羊城杯2024 pwn4的解法(kernel<5.6)

前言

今天无聊乱刷的时候发现有师傅说羊城杯的pwn4(hardsandbox)用openat2只能打通本地,远程无法打通,于是点击看了一下文章,发现了一个对沙箱的逃逸的知识点。

正文

为什么openat2无法打通远程

Qanux师傅说是远程的 kernel(linux内核) 版本是 5.4,而 openat2 系统调用是在 kernel 5.6 才引入的,所以这种方法作废。

怎么办?

我们不难发现,此次沙箱的开法和平常不太一样:

 

平常我们看到的都是:return KILL,这一次不太一样,是return TRACE,我们来看一下The Linux Kernel Archives对这一条指令的描述(链接:Seccomp BPF (SECure COMPuting with filters) — The Linux Kernel documentation):

Return values

A seccomp filter may return any of the following values. If multiple filters exist, the return value for the evaluation of a given system call will always use the highest precedent value. (For example, SECCOMP_RET_KILL_PROCESS will always take precedence.)

In precedence order, they are:

SECCOMP_RET_KILL_PROCESS:

Results in the entire process exiting immediately without executing the system call. The exit status of the task (status & 0x7f) will be SIGSYS, not SIGKILL.

SECCOMP_RET_KILL_THREAD:

Results in the task exiting immediately without executing the system call. The exit status of the task (status & 0x7f) will be SIGSYS, not SIGKILL.

SECCOMP_RET_TRAP:

Results in the kernel sending a SIGSYS signal to the triggering task without executing the system call. siginfo->si_call_addr will show the address of the system call instruction, and siginfo->si_syscall and siginfo->si_arch will indicate which syscall was attempted. The program counter will be as though the syscall happened (i.e. it will not point to the syscall instruction). The return value register will contain an arch- dependent value -- if resuming execution, set it to something sensible. (The architecture dependency is because replacing it with -ENOSYS could overwrite some useful information.)

The SECCOMP_RET_DATA portion of the return value will be passed as si_errno.

SIGSYS triggered by seccomp will have a si_code of SYS_SECCOMP.

SECCOMP_RET_ERRNO:

Results in the lower 16-bits of the return value being passed to userland as the errno without executing the system call.

SECCOMP_RET_USER_NOTIF:

Results in a struct seccomp_notif message sent on the userspace notification fd, if it is attached, or -ENOSYS if it is not. See below on discussion of how to handle user notifications.

SECCOMP_RET_TRACE:

When returned, this value will cause the kernel to attempt to notify a ptrace()-based tracer prior to executing the system call. If there is no tracer present, -ENOSYS is returned to userland and the system call is not executed.

A tracer will be notified if it requests PTRACE_O_TRACESECCOMP using ptrace(PTRACE_SETOPTIONS). The tracer will be notified of a PTRACE_EVENT_SECCOMP and the SECCOMP_RET_DATA portion of the BPF program return value will be available to the tracer via PTRACE_GETEVENTMSG.

The tracer can skip the system call by changing the syscall number to -1. Alternatively, the tracer can change the system call requested by changing the system call to a valid syscall number. If the tracer asks to skip the system call, then the system call will appear to return the value that the tracer puts in the return value register.

The seccomp check will not be run again after the tracer is notified. (This means that seccomp-based sandboxes MUST NOT allow use of ptrace, even of other sandboxed processes, without extreme care; ptracers can use this mechanism to escape.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值