XPOC逆向

package main
 
import (
	"bytes"
	"compress/gzip"
	"crypto/aes"
	"crypto/cipher"
	"encoding/hex"
	"fmt"
	"io"
	"os"
	"path/filepath"
)
 
var aeskeystr = "75715A1D7927214737C249EDFF019CC5E336A85050A2661FA73800DD9A682C1A"
var noncestr = "57177B09C87090010D0AFAD4"
 
func main() {
	key, _ := hex.DecodeString(aeskeystr)
	nonce, _ := hex.DecodeString(noncestr)
 
	filelist, err := filepath.Glob("*.bin")
	if err != nil {
		fmt.Println("解码失败")
	}
 
	if len(filelist) == 0 {
		fmt.Println("未在当前目录下获取到XPOC的poc文件!")
		return
	}
 
	// 遍历每个文件并进行解密
	for _, filename := range filelist {
		fmt.Println("正在解密的文件为:" + filename)
		pocdata, _ := os.ReadFile(filename)
		n := len(pocdata) - 0x100
		if n <= 0 {
			continue
		}
		data := pocdata[:n]
		poc, err := decrpytPoc(key, nonce, data)
		if err != nil {
			continue
		}
		m := len(filename) - 4
		newfile := filename[:m]
		outputPath := filepath.Join("pocs", newfile)
		parentDir := filepath.Dir(outputPath)
		if _, err := os.Stat(parentDir); os.IsNotExist(err) {
			if err := os.MkdirAll(parentDir, os.ModePerm); err != nil {
				continue
			}
		}
		os.WriteFile(outputPath, poc, os.ModePerm)
	}
	fmt.Println("解密完成,请到pocs目录下查看所有已解密的poc文件")
}
 
func deCompress(data []byte) []byte {
	reader, _ := gzip.NewReader(bytes.NewReader(data))
	defer reader.Close()
	result, _ := io.ReadAll(reader)
	return result
}
 
func decrpytPoc(key, nonce, data []byte) ([]byte, error) {
 
	block, err := aes.NewCipher(key)
	if err != nil {
		return []byte(""), err
	}
 
	aesGCM, err := cipher.NewGCM(block)
	if err != nil {
		return []byte(""), err
	}
	
	plaintext, err := aesGCM.Open(nil, nonce, data, nil)
	if err != nil {
		return []byte(""), err
	}
 
	poc := deCompress(plaintext)
	return poc, nil
}