介绍

由于工作机无法登陆微信,遂先记录在这,回家后整理。

想了解下免杀,python打包的话文件太大,所以想通过go来实现。

python实现的免杀效果VT不是完全体的状态下是7/66,未测试完全体能过多少,虽然思路非常简单,但是也不想频繁提交样本。

当然免杀思路也都是来自互联网,里面加了点自己的思路进去。

代码

  • main.go

主函数入口,原本思路是将shellcode放置于另一个包内从而引入进来,但是测试的时候失败了,所以先暂时使用man主函数存放shellcode,并将shellcode赋值给加解密函数。

package main

import "goby01/encode"

func main() {

	shellcode := []byte{

		0x61, 0x62, 0x63, 0x64,

	}

	encode.Enc(shellcode)

	// Encode is ok!

	encode.Dec(shellcode)

	// Decode is ok!

}
  • encode.go

加解密包文件,思路是将shellcode进行加密,或者是将shellcode加密后存放于加载器中,这样可能就不会存在shellcode被杀的情况,然后再在加载器中调用解密函数将shellcode进行解密,从而调入内存进行执行,但是目前还是有很大问题,只是大致看懂了加密的过程,要将加密后的字符串解密为原始的字符串还没有成功,还未学会。

记录下该方式下的加解密过程,方法也来源于网络,只是想实现下自己的思路。

package encode

import (

	"crypto/aes"

	"crypto/cipher"

	"encoding/hex"

	"fmt"

	"os"

)

// 加密密钥吧

var commonIV = []byte{0x61, 0x01, 0x02, 0x03, 0x04, 0x65, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0a}

func ToCry() {

	shellcode := []byte{

		0x61, 0x62, 0x63, 0x64,

	}

	// plaintext 		原始的数据

	// ciphertext		加密的数据

	//plaintext := []byte("This is encode test ")

	plaintext := []byte(shellcode) //从main主函数中传入的shellcode

	key_text := "astaxie12798akljzmknm.ahkjkljl;k"

	if len(os.Args) > 2 {

		key_text = os.Args[2]

	}

	// 创建加密函数

	c, err := aes.NewCipher([]byte(key_text))

	if err != nil {

		fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key_text), err)

		os.Exit(-1)

	}

	// 加密过程

	cfb := cipher.NewCFBEncrypter(c, commonIV)

	ciphertext := make([]byte, len(plaintext))

	cfb.XORKeyStream(ciphertext, plaintext)

	fmt.Printf("%s => %x\n", plaintext, ciphertext)

	// 解密过程

	cfbdec := cipher.NewCFBDecrypter(c, commonIV)

	plaintextCopy := make([]byte, len(plaintext))

	cfbdec.XORKeyStream(plaintextCopy, ciphertext)

	fmt.Printf("%x => %s\n", ciphertext, plaintextCopy)

}

//想单独将加密过程和解密过程分离出来,从而实现想法的,但是只有加密正常,解密不正常。

func Enc(shellcode []byte) string {

	println("abcd to hex: ", hex.EncodeToString(shellcode))

	plaintext := []byte(shellcode) //传入的shellcode

	if len(os.Args) > 1 {

		plaintext = []byte(os.Args[1])

	}

	key_text := "astaxie12798akljzmknm.ahkjkljl;k"

	//fmt.Println(len(key_text))

	c, err := aes.NewCipher([]byte(key_text))

	if err != nil {

		fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key_text), err)

		os.Exit(-1)

	}

	cfb := cipher.NewCFBEncrypter(c, commonIV)

	ciphertext := make([]byte, len(plaintext))

	cfb.XORKeyStream(ciphertext, plaintext)

	fmt.Printf("%s => %x\n", plaintext, ciphertext)

	cfbdec := cipher.NewCFBDecrypter(c, commonIV)

	plaintextCopy := make([]byte, len(plaintext))

	cfbdec.XORKeyStream(plaintextCopy, ciphertext)

	encode := hex.EncodeToString(ciphertext)

	return encode	//返回加密后的结果以16进制显示

}

//解密就不正常了,还在研究。(菜)

func Dec(shellcode []byte) string {

	// plaintext 		source code

	// ciphertext		encode code

	plaintext := []byte(shellcode)

	if len(os.Args) > 1 {

		plaintext = []byte(os.Args[1])

	}

	key_text := "astaxie12798akljzmknm.ahkjkljl;k"

	if len(os.Args) > 2 {

		key_text = os.Args[2]

	}

	//fmt.Println(len(key_text))

	c, err := aes.NewCipher([]byte(key_text))

	if err != nil {

		fmt.Printf("Error: NewCipher(%d bytes) = %s", len(key_text), err)

		os.Exit(-1)

	}

	cfb := cipher.NewCFBEncrypter(c, commonIV)

	ciphertext := make([]byte, len(plaintext))

	cfb.XORKeyStream(ciphertext, plaintext)

	//fmt.Printf("%s => %x\n", plaintext, ciphertext)

	cfbdec := cipher.NewCFBDecrypter(c, commonIV)

	plaintextCopy := make([]byte, len(plaintext))

	cfbdec.XORKeyStream(plaintextCopy, ciphertext)

	fmt.Printf("%x => %s\n", ciphertext, plaintextCopy)

	decode := hex.EncodeToString(ciphertext)

	return decode

}

结束

面向谷歌的go加密解密学习;