Pythonexe2shellcode,shellcode2exe
Posted 17bdw随手笔记
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Pythonexe2shellcode,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)
参考
以上是关于Pythonexe2shellcode,shellcode2exe的主要内容,如果未能解决你的问题,请参考以下文章