-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring-to-shellcode.py
More file actions
42 lines (40 loc) · 1.06 KB
/
string-to-shellcode.py
File metadata and controls
42 lines (40 loc) · 1.06 KB
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
import sys
def main():
if len(sys.argv) != 2:
print("Usage: %s <string>\n" % (sys.argv[0]))
sys.exit(1)
val = sys.argv[1];
n = int(len(val)/4)+1
c = n-1
if (len(val)-c*4)==3:
print("xor eax, eax")
print("mov al, 0x", end='')
print(hex(ord(val[c*4+2]))[2:])
print("shl eax, 0x10")
print("add ax, 0x", end='')
print(hex(ord(val[c*4+1]))[2:], end='')
print(hex(ord(val[c*4]))[2:])
if (len(val)-c*4)==2:
print("xor eax, eax")
print("mov ax, 0x", end='')
print(hex(ord(val[c*4+1]))[2:], end='')
print(hex(ord(val[c*4]))[2:])
if (len(val)-c*4)==1:
print("xor eax, eax")
print("mov al, 0x", end='')
print(hex(ord(val[c*4]))[2:])
if (len(val)-c*4)==0:
print("xor eax, eax")
print("push eax")
c = c -1
while c >= 0:
print("push 0x", end='')
print(hex(ord(val[c*4+3]))[2:], end='')
print(hex(ord(val[c*4+2]))[2:], end='')
print(hex(ord(val[c*4+1]))[2:], end='')
print(hex(ord(val[c*4]))[2:])
c = c -1
print("push esp")
sys.exit(0)
if __name__ == "__main__":
main()