-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshellcode2js.py
More file actions
43 lines (35 loc) · 939 Bytes
/
Copy pathshellcode2js.py
File metadata and controls
43 lines (35 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
#
# Converter from a C style shellcode or binary file containing the shellcode to escaped Javascript shellcode
#
# http://eternal-todo.com
# Jose Miguel Esparza
#
import sys,os
usage = "Usage: " + sys.argv[0] + ''' shellcode|file
Arguments:
shellcode: C style shellcode.
file: binary file containing the shellcode.
'''
jsshellcode = ""
tmp = ""
cont = 0
if len(sys.argv) != 2:
sys.exit(usage)
if os.path.exists(sys.argv[1]):
shellcode = open(sys.argv[1],'r').read()
else:
shellcode = sys.argv[1]
for i in range(2,len(shellcode),4):
chars = shellcode[i]+shellcode[i+1]
tmp += chr(int(chars,16))
shellcode = tmp
for i in range(0,len(shellcode)-1,2):
if i%16 == 0:
if cont == 0:
jsshellcode += '"'
cont += 1
else:
jsshellcode += '"+\n"'
jsshellcode += "%%u%.2x%.2x" % (ord(shellcode[i+1]),ord(shellcode[i]))
print jsshellcode+'"'