【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)