binary to shellcode
ssooking Lv5

从二进制文件中转储shellcode的Tips:

  • hexdump command
  • python scripts

hexdump

1
hexdump -v -e '"\\""x" 1/1 "%02x" ""' filename

python

bin2shellcode.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @ Author: ssooking
# @ Blog : https://ssooking.github.io
# @ Github: https://github.com/ssooking

import sys

def bin2shellcode(binfile):
binary = open(binfile,'rb')
for byte in binary.read():
sys.stdout.write("\\x"+byte.encode("hex"))
print ""

if __name__ == "__main__":
if len(sys.argv) < 2:
print "\nUsage: python bin2shellcode.py filename\n"
sys.exit(0)
bin2shellcode(sys.argv[1])

bin2shellcode2.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
if __name__ == "__main__":
if len(sys.argv) < 2:
print "usage: %s file.bin\n" % (sys.argv[0],)
sys.exit(0)

shellcode = "\""
ctr = 1
maxlen = 15

for b in open(sys.argv[1], "rb").read():
shellcode += "\\x" + b.encode("hex")
if ctr == maxlen:
shellcode += "\" +\n\""
ctr = 0
ctr += 1
shellcode += "\""
print shellcode

Reference

  • Post title:binary to shellcode
  • Post author:ssooking
  • Create time:2020-01-26 14:34:00
  • Post link:https://ssooking.github.io/2020/01/binary-to-shellcode/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.