前言
今天无聊乱刷的时候发现有师傅说羊城杯的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_PROCESSwill 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 beSIGSYS, notSIGKILL.
SECCOMP_RET_KILL_THREAD:Results in the task exiting immediately without executing the system call. The exit status of the task (
status & 0x7f) will beSIGSYS, notSIGKILL.
SECCOMP_RET_TRAP:Results in the kernel sending a
SIGSYSsignal to the triggering task without executing the system call.siginfo->si_call_addrwill show the address of the system call instruction, andsiginfo->si_syscallandsiginfo->si_archwill 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-ENOSYScould overwrite some useful information.)The
SECCOMP_RET_DATAportion of the return value will be passed assi_errno.
SIGSYStriggered by seccomp will have a si_code ofSYS_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_notifmessage sent on the userspace notification fd, if it is attached, or-ENOSYSif 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,-ENOSYSis returned to userland and the system call is not executed.A tracer will be notified if it requests
PTRACE_O_TRACESECCOMPusingptrace(PTRACE_SETOPTIONS). The tracer will be notified of aPTRACE_EVENT_SECCOMPand theSECCOMP_RET_DATAportion of the BPF program return value will be available to the tracer viaPTRACE_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.

&spm=1001.2101.3001.5002&articleId=141761305&d=1&t=3&u=8dc5d19bff0e48019ee43ff6f5506579)
2711

被折叠的 条评论
为什么被折叠?



