【Python】exe2shellcode,shellcode2exe

用python写这类程序真简洁,要是用C++又不知道得多写多少行代码了。

exe2shellcode

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

def payload(files):
    shellcode = ""
    ctr = 1
    maxlen = 15 #to create rows
    try:
        for b in open(files, "rb").read():
            shellcode +=b.encode("hex")
            if ctr == maxlen:
                ctr = 0
            ctr += 1
        print "Code length: " + str(len(shellcode))
        return shellcode
    except:
        print "转换失败,请检查!"

f = open('messagebox.txt','w')
files = "messagebox.exe" 
a = payload(files)
f.write(a)
f.close()

shellcode2exe

#! /usr/bin/env python
# -*- coding: utf-8 -*-

# 计算messagebox大小
c = open('messagebox.txt','r')
r = c.read()
print len(r)

# 将cmd.exe中的opcode再转换为HEX数据
s = open('messagebox.txt','rb')
b = s.read()
bb = b[-len(r):]
cb = bb.decode("hex")
f = open('mess.exe','wb')
f.write(cb)

参考

分解型后门构想初探
https://mp.weixin.qq.com/s/KLR2s9PkHqy97eZjYTeM2w

posted @ 2017-12-04 16:55  17bdw  阅读(1198)  评论(0编辑  收藏  举报