blob: 60dc183e384a2688f565d14303cd68e104214341 (
plain)
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
|
#!/usr/bin/python3
from pwn import *
elf = context.binary = ELF("house_of_orange")
libc = elf.libc
gs = '''
set breakpoint pending on
break _IO_flush_all_lockp
enable breakpoints once 1
continue
'''
def start():
if args.GDB:
return gdb.debug(elf.path, gdbscript=gs)
else:
return process(elf.path)
# Select the "malloc (small)" option.
def small_malloc():
io.send("1")
io.recvuntil("> ")
# Select the "malloc (large)" option.
def large_malloc():
io.sendthen("> ", "2")
# Select the "edit (1st small chunk)" option; send data.
def edit(data):
io.send("3")
io.sendafter("data: ", data)
io.recvuntil("> ")
io = start()
# This binary leaks the address of puts(), use it to resolve the libc load address.
io.recvuntil("puts() @ ")
libc.address = int(io.recvline(), 16) - libc.sym.puts
# This binary leaks the heap start address.
io.recvuntil("heap @ ")
heap = int(io.recvline(), 16)
io.recvuntil("> ")
io.timeout = 0.1
# =============================================================================
# =-=-=- EXAMPLE -=-=-=
# Request a small chunk.
small_malloc()
# Edit the 1st small chunk.
edit(b"Y"*24)
# Request a large chunk.
large_malloc()
# =============================================================================
io.interactive()
|