Python exe2shellcode,shellcode2exe

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://www.cnblogs.com/hjbf/p/10670959.html

你可能感兴趣的:(Python exe2shellcode,shellcode2exe)