kochj23/Bastion

GitHub: kochj23/Bastion

面向 macOS 的 AI 驱动渗透测试平台,集成网络扫描、漏洞利用编排、MITRE ATT&CK 映射和攻陷后取证功能。

Stars: 2 | Forks: 0

# Bastion ![构建](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/f85b64e173103656.svg) ![测试](https://img.shields.io/badge/tests-140%20passed-brightgreen) ![平台](https://img.shields.io/badge/platform-macOS%2014.0%2B-blue) ![Swift](https://img.shields.io/badge/Swift-5.9-orange) [![许可证:MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE) ![状态](https://img.shields.io/badge/status-Production-success) **面向 macOS 的 AI 驱动网络渗透测试。** Bastion 将原生 Swift 网络扫描与多后端 AI 编排相结合,用于发现设备、识别漏洞、链接漏洞利用、绘制横向移动路径并生成专业安全报告——所有功能均来自一个在 Apple Silicon 上原生运行的 SwiftUI 应用程序。 由 Jordan Koch([@kochj23](https://github.com/kochj23))编写。 ## 架构 ``` graph TB subgraph App["Bastion.app"] subgraph UI["SwiftUI Views"] Dashboard DeviceList["Device List"] AttackLog["Attack Log"] AIInsights["AI Insights"] Vulns["Vulnerabilities"] end subgraph AI["AI Backend Manager (10 backends)"] Ollama["Ollama :11434"] MLX["MLX Apple Silicon"] TinyLLM["TinyLLM :8000"] OpenWebUI["OpenWebUI :8080"] Cloud["OpenAI / Google / Azure / AWS / IBM"] end subgraph Scanner["Network Scanner (Darwin BSD / NWConnection)"] CIDR["CIDR Parser"] --> PortScan["Port Scanner"] PortScan --> ServiceFP["Service Fingerprinter"] end subgraph Security["Security Engine"] CVEDb["CVE Database NIST NVD"] Orchestrator["AI Attack Orchestrator"] ExploitGen["AI Exploit Generator"] Chainer["Vulnerability Chainer"] LateralMap["Lateral Movement Mapper"] MITRE["MITRE ATT&CK Mapper"] PostComp["Post-Compromise 10-phase"] Anomaly["Anomaly Detector CoreML"] Monitor["Continuous Monitor"] Remediation["Remediation Scripts"] PDFReport["PDF Report Generator"] end subgraph Exploits["Exploit Modules"] SSH & SMB & DNS_M["DNS"] & LDAP & Web & Creds["Default Creds"] end Guard["Ethical AI Guardian"] Widget["WidgetKit Extension"] end UI --> Scanner AI --> Orchestrator AI --> ExploitGen Scanner --> Security Security --> Exploits Security --> Guard Security --> Widget ```
ASCII 架构图 ``` +-------------------------------------------------------------------+ | Bastion.app | | | | +---------------------+ +-------------------------------+ | | | SwiftUI Views | | AI Backend Manager | | | | | | | | | | Dashboard | | Ollama (localhost:11434) | | | | Device List | | MLX (Apple Silicon) | | | | Attack Log | | TinyLLM (localhost:8000) | | | | AI Insights | | TinyChat(localhost:8000) | | | | Vulnerabilities | | OpenWebUI(localhost:8080) | | | | Settings | | OpenAI / Google / Azure / | | | +----------+-----------+ | AWS Bedrock / IBM Watson | | | | +-------+-----------------------+ | | v | | | +----------+-----------+ | | | | Network Scanner |<-----------+ | | | (Darwin BSD / NW) | | | +----------+-----------+ | | | | | v | | +----------+----------------------------------------------------+ | | | Security Engine | | | | | | | | +------------------+ +-------------------+ +--------------+ | | | | | CVE Database | | Service | | Exploit | | | | | | (NIST NVD) | | Fingerprinter | | Modules | | | | | +------------------+ +-------------------+ | SSH, SMB, | | | | | | DNS, LDAP, | | | | | +------------------+ +-------------------+ | Web, Creds | | | | | | AI Attack | | AI Exploit | +--------------+ | | | | | Orchestrator | | Generator | | | | | +------------------+ +-------------------+ | | | | | | | | +------------------+ +-------------------+ +--------------+ | | | | | Vulnerability | | Lateral Movement | | MITRE ATT&CK | | | | | | Chainer | | Mapper | | Mapper | | | | | +------------------+ +-------------------+ +--------------+ | | | | | | | | +------------------+ +-------------------+ +--------------+ | | | | | Post-Compromise | | Timeline | | Anomaly | | | | | | Module (10-phase)| | Reconstructor | | Detector | | | | | +------------------+ +-------------------+ +--------------+ | | | | | | | | +------------------+ +-------------------+ +--------------+ | | | | | Remediation | | Continuous | | PDF Report | | | | | | Script Generator | | Monitor | | Generator | | | | | +------------------+ +-------------------+ +--------------+ | | | +----------------------------------------------------------------+ | | | | +-------------------------------+ +---------------------------+ | | | Ethical AI Guardian | | WidgetKit Extension | | | | Content monitoring, TOS, | | Security score, vuln | | | | prohibited-use detection | | counts, last scan time | | | +-------------------------------+ +---------------------------+ | +-------------------------------------------------------------------+ ```
## 功能 ### 网络侦察 - **纯 Swift 网络扫描器**,基于 Darwin BSD 套接字和 Network 框架构建——不依赖 nmap 或其他外部工具。 - 基于 CIDR 的主机发现(`/24` 和 `/16` 子网),支持并发 TCP 连接探测。 - 跨 23 个常见端口的端口扫描(FTP、SSH、Telnet、HTTP、HTTPS、SMB、RDP、数据库端口等)。 - 反向 DNS 主机名解析。 - 通过原始 TCP 连接进行服务指纹识别和横幅抓取。 - 基于暴露服务组合的操作系统检测启发式算法。 - 快速扫描模式,用于快速的前 10 端口探测。 ### AI 驱动的攻击编排 - **AI 攻击编排器**通过分析每个发现设备的完整威胁景观、按照可利用性对目标进行排名、预测成功概率并识别多步骤攻击链来构建智能攻击计划。 - **AI 漏洞利用生成器**读取 CVE 描述,并为特定目标和漏洞生成可工作的概念验证漏洞利用代码(Python、Bash、Ruby)。 - **漏洞链接器**识别多步骤利用路径:信息泄露到权限提升、SQL 注入到 RCE、路径遍历到凭证窃取、XSS 到管理员接管,以及漏洞利用到持久化链。 - **横向移动映射器**发现信任关系(SSH 密钥重用、共享凭证、扁平网络分段)并构建单跳和多跳透视路径。 - **后渗透规划器**在设备被攻陷后建议权限提升、持久化、横向移动和数据泄露步骤。 - AI 自我改进循环:漏洞利用生成器从成功和失败的尝试中学习,每 10 次运行分析模式以提高未来成功率。 ### 攻陷后评估 一个 10 阶段的取证评估模块,通过 SSH 连接到目标并进行深度检查: | 阶段 | 模块 | 检测内容 | |-------|---------------------------|---------------------------------------------------| | 1 | Rootkit 检测器 | 内核和用户空间 rootkit | | 2 | 可疑用户检测器 | UID-0 账户、空密码、异常 shell | | 3 | 后门检测器 | 未授权监听端口和服务 | | 4 | 隐藏进程检测器 | 从 `ps` / `/proc` 隐藏的进程 | | 5 | 二进制完整性检查器 | 被篡改的系统二进制文件(伪装的 `ls`、`ps` 等)| | 6 | 持久化检测器 | Cron 作业、init 脚本、authorized_keys | | 7 | 内核模块分析器 | 可疑或未签名的内核模块 | | 8 | 日志篡改检测器 | 清除的日志、时间戳间隙、截断的文件 | | 9 | 网络嗅探器检测器 | 混杂接口和数据包捕获工具 | | 10 | AI 分析 | 所有发现的自然语言取证摘要 | ### CVE 数据库 - 下载并缓存来自 NIST NVD 的严重/高危 CVE。 - 将发现的服务映射到已知漏洞。 - 为每个发现提供 CVSS 分数和严重等级。 ### MITRE ATT&CK 映射 - 所有漏洞和攻击结果都映射到 MITRE ATT&CK 技术和战术(T1046、T1021、T1078、T1059、T1068、T1110、T1190、T1210 等)。 - 可导出的 ATT&CK Navigator JSON 用于热力图可视化。 - 涵盖从侦察到影响的所有 14 个 ATT&CK 战术。 ### 持续监控和异常检测 - 可配置间隔的预定扫描,带基线对比。 - 基于 CreateML/CoreML 的异常检测器,学习正常设备行为配置文件并标记偏差(新端口、新设备、变更的服务)。 - macOS 安全警报通知。 - 完整扫描历史,带时间线跟踪。 ### 取证时间线重建 - 从攻陷后证据重建攻击者活动序列。 - 阶段:侦察、初始访问、权限提升、持久化、横向移动和目标达成。 - AI 生成的攻击叙事,用于事件响应报告。 ### 修复 - **修复脚本生成器**为每台设备生成硬化 bash 脚本,覆盖 SSH、Web 服务器、SMB 和 DNS 配置。 - 针对特定漏洞配置文件的 AI 增强建议。 - 用于授权红队演练的可导出漏洞利用链脚本。 ### 报告 - **企业 PDF 报告**,使用 PDFKit 生成:标题页、执行摘要、网络概览、每台设备的漏洞详情和 AI 分析。 - MITRE ATT&CK Navigator JSON 导出。 - 所有扫描日志可在 UI 中查看和导出。 ### macOS WidgetKit 小组件 - 三种尺寸(小、中、大)的仪表板小组件,显示整体安全评分、按严重等级分类的漏洞概览、风险设备、上次扫描时间和网络信息。 - 每次扫描后通过 App Group 共享的 UserDefaults(`group.com.jkoch.bastion`)自动同步。 - 每 15 分钟更新一次。 ### 道德 AI 保护措施 - 全面的内容监控,包含 100 多种禁止使用模式。 - 自动阻止非法、有害和滥用内容。 - 危机资源转介(988 自杀预防、危机短信热线、家庭暴力热线)。 - 哈希使用日志用于审计(非纯文本)。 - 法律合规(CSAM 报告义务)。 - 服务条款执行——请参阅 [ETHICAL_AI_TERMS_OF_SERVICE.md]( AI Backend 中配置任何云后端 ``` ## 使用方法 1. 启动 Bastion。首次运行时接受法律免责声明。 2. 输入目标 CIDR(例如 `192.168.1.0/24`)并点击**扫描网络**。 3. 在**设备列表**选项卡中查看发现的设备。 4. 打开 **AI 洞察**查看 AI 生成的攻击计划,包含排名目标和漏洞利用链。 5. 在**设备详情**中检查各个设备的开放端口、服务、漏洞和 CVE 匹配项。 6. 使用**攻击**菜单运行 AI 推荐的攻击或触发全面攻击。 7. 攻陷后,运行**攻陷后评估**进行 10 阶段取证检查。 8. 从仪表板导出 PDF 报告或 MITRE ATT&CK Navigator JSON。 ### 键盘快捷键 | 快捷键 | 操作 | |-----------------------------|--------------------------| | Cmd+N | 新扫描 | | Cmd+S | 停止扫描 | | Cmd+Q | 快速扫描 | | Cmd+R | 运行 AI 攻击计划 | | Cmd+Option+Shift+X | 全面攻击模式 | | Cmd+. | 紧急停止 | | Cmd+Option+B | AI 后端设置 | | Cmd+1 到 Cmd+5 | 切换视图选项卡 | ## 技术细节 - **语言:** Swift 5.9、SwiftUI - **最低操作系统:** macOS 13.0(Ventura) - **架构:** Apple Silicon 原生(arm64),支持通用二进制 - **沙盒:** 已禁用(`com.apple.security.app-sandbox = false`)——网络扫描、SSH 连接和原始套接字访问需要完整系统权限。 - **App Group:** `group.com.jkoch.bastion`(与 WidgetKit 扩展共享数据) - **网络层:** 通过 `Network` 框架(`NWConnection`)的 Darwin BSD 套接字;无外部工具依赖。 - **AI 集成:** 所有本地和云后端使用 OpenAI 兼容的 HTTP API;MLX 使用 Python `Process` 子进程。 - **CVE 数据:** 缓存在 `~/Library/Application Support/Bastion/CVE/`。 - **PDF 生成:** 原生 `PDFKit` + `CGContext` 渲染。 - **异常检测:** `CreateML` / `CoreML` 用于设备端行为分析。 - **并发:** 整个项目使用 Swift 结构化并发(`async`/`await`、`TaskGroup`)。 ## 项目结构 ``` Bastion/ BastionApp.swift App entry point, legal warning, main UI AI/ AIBackendManager.swift Multi-backend AI manager (10 backends) AIAttackOrchestrator.swift Network-wide attack planning AIExploitGenerator.swift CVE-to-exploit code generation AICapabilities/ UnifiedAICapabilities.swift Unified capability detection ImageGenerationUnified.swift Image generation backends VoiceUnified.swift Voice/speech backends AnalysisUnified.swift Analysis backends SecurityUnified.swift Security-specific AI Models/ Device.swift Device, Port, Service, Vulnerability models CVE.swift CVE data model AttackResult.swift Attack outcome tracking CompromiseReport.swift Post-compromise assessment report Security/ NetworkScanner.swift Pure-Swift CIDR scanner CVEDatabase.swift NIST NVD downloader and cache ServiceFingerprinter.swift Banner grabbing and version detection ComprehensiveDeviceTester.swift Full device security audit VulnerabilityChainer.swift Multi-step exploit chain builder LateralMovementMapper.swift Network pivot path discovery MITREATTACKMapper.swift ATT&CK technique/tactic mapping ContinuousMonitor.swift Scheduled scan and alert engine AnomalyDetector.swift ML-based behavior anomaly detection TimelineReconstructor.swift Forensic attack timeline builder RemediationScriptGenerator.swift Hardening script output ExploitModules/ SSHModule.swift SSH-specific testing SMBModule.swift SMB/CIFS testing DNSModule.swift DNS testing LDAPModule.swift LDAP testing WebModule.swift HTTP/HTTPS testing DefaultCredsModule.swift Default credential testing PostCompromise/ PostCompromiseModule.swift 10-phase assessment orchestrator RootkitDetector.swift Rootkit scanning BackdoorDetector.swift Backdoor scanning HiddenProcessDetector.swift Hidden process detection SuspiciousUserDetector.swift User account analysis PersistenceDetector.swift Persistence mechanism scanning KernelModuleAnalyzer.swift Kernel module inspection LogTamperingDetector.swift Log integrity checking NetworkSnifferDetector.swift Promiscuous mode detection BinaryIntegrityChecker.swift System binary hash verification BinaryHashDatabase.swift Known-good hash database Utilities/ SSHConnection.swift SSH client for post-compromise PDFGenerator.swift Enterprise PDF report output WidgetDataSync.swift Widget data sync via App Group SafetyValidator.swift Input validation ModernDesign.swift Glassmorphic UI styling Views/ DashboardView.swift Main dashboard with scan controls DeviceListView.swift Discovered device list DeviceDetailView.swift Per-device detail inspector AttackLogView.swift Attack execution log AIInsightsView.swift AI recommendations and plans VulnerabilitiesView.swift Vulnerability browser SettingsView.swift Backend and scan configuration Bastion Widget/ BastionWidget.swift WidgetKit entry point SharedDataManager.swift Shared App Group data reader WidgetData.swift Widget data models ``` ## Bastion 与其他工具的比较 | 功能 | Bastion | Metasploit | Burp Suite | |-----------------------------------|----------------------|----------------------|--------------------| | AI 驱动的漏洞利用选择 | 是(10 个后端) | 否 | 否 | | AI 漏洞利用代码生成 | 是 | 否 | 否 | | 漏洞链分析 | 是 | 否 | 否 | | 横向移动映射 | 是 | 有限 | 否 | | MITRE ATT&CK 映射 | 是 | 有限 | 否 | | 攻陷后取证 | 是(10 阶段) | 后渗透模块 | 否 | | 原生 macOS 应用 | 是(SwiftUI) | 否(CLI/Java) | 否(Java)| | 本地 AI(无需云端)| 是 | 不适用 | 不适用 | | Apple Silicon 原生 | 是 | 否 | 否 | | WidgetKit 仪表板 | 是 | 否 | 否 | | PDF 报告生成 | 是 | 是 | 是 | | 免费和开源 | 是(MIT) | 社区版 | 否 | ## 下载 下载最新版本: [GitHub Releases 上的 Bastion](https://github.com/kochj23/Bastion/releases/latest) ## 测试套件 Bastion 包含全面的 XCTest 套件,涵盖模型、安全逻辑、MITRE ATT&CK 映射、漏洞链接和安全执行。 **140 个测试,0 个失败,分布在 10 个测试类中:** | 测试类 | 测试数 | 覆盖领域 | |---|---|---| | `DeviceModelTests` | 22 | 设备、开放端口、服务信息、风险等级、安全评分 | | `CVEModelTests` | 17 | CVE 严重等级映射、Codable 往返、VulnerabilitySeverity | | `AttackResultTests` | 12 | AttackResult、AttackStatus、AttackType、ScanResults | | `SafetyValidatorTests` | 14 | RFC 1918 执行、公共 IP 阻止、速率限制 | | `CompromiseReportTests` | 22 | 攻陷后发现、评估逻辑、所有发现类型 | | `MITREATTACKMapperTests` | 16 | ATT&CK 技术/战术映射、Navigator JSON 导出 | | `VulnerabilityChainerTests` | 8 | 链概率计算、链类型 | | `LateralMovementTests` | 8 | 信任关系、移动路径、多跳过滤 | | `AIBackendTests` | 16 | 后端枚举、错误类型、AttackPlan、PostExploitationPlan | | `NetworkErrorTests` | 5 | NetworkError、CVEDatabaseError、CVEMetadata | ### 运行测试 ``` xcodebuild test -project Bastion.xcodeproj -scheme Bastion \ -configuration Debug -destination 'platform=macOS' \ -only-testing BastionTests ``` ## 许可证 MIT 许可证——请参阅 [LICENSE](./LICENSE)。 需要道德使用——请参阅 [ETHICAL_AI_TERMS_OF_SERVICE.md](./ETHICAL_AI_TERMS_OF_SERVICE.md)。 版权所有 © 2026 Jordan Koch。保留所有权利。 ## Jordan Koch 的更多应用 | 应用 | 描述 | |-----|-------------| | [NMAPScanner](https://github.com/kochj23/NMAPScanner) | 带 AI 威胁检测的网络安全扫描器 | | [MLXCode](https://github.com/kochj23/MLXCode) | Apple Silicon 本地 AI 编程助手 | | [URL-Analysis](https://github.com/kochj23/URL-Analysis) | 网络流量分析和 URL 监控 | | [TopGUI](https://github.com/kochj23/TopGUI) | 带实时指标的 macOS 系统监控器 | | [rtsp-rotator](https://github.com/kochj23/rtsp-rotator) | RTSP 摄像机流旋转和监控 | [查看所有项目](https://github.com/kochj23?tab=repositories)
标签:AI安全, AI编排, AI风险缓解, AI驱动安全, Apple Silicon安全, Chat Copilot, CISA项目, Cloudflare, CVE, DAST, DNS 反向解析, HTTP工具, IP 地址批量处理, LLM评估, macOS渗透测试, MITRE ATT&CK, MLX, Ollama, PE 加载器, Qt框架, SwiftUI, Swift开发, XXE攻击, 云存储安全, 代码生成, 企业安全, 反取证, 安全评估, 恶意软件分析, 插件系统, 搜索语句(dork), 数字签名, 无线安全, 服务识别, 横向移动, 渗透测试工具, 编程规范, 网络安全, 网络安全审计, 网络扫描, 网络指纹识别, 网络资产管理, 自动化渗透测试, 隐私保护