Small sandbox inspired by Chromium's good ol' suid sandbox & friends
Note: build as a challenge (archived here) for the thc18 CTF.
Use the provided Makefile
:
git clone https://github.com/plcp/sandkox
cd sandkox
Make
How to bootstrap the sandbox is left as an exercise to an attentive reader.
Here are a small listing of symbols exposed by smallkox.so
:
-
sandkox
creates a new PID namespace, then jail the process and drops its privileges.See
jail_strap
+jail_final
anddrop_priv
+lock_priv
-
drop_priv
is a superset ofdrop_root
that preservesCAP_SET_PCAP
See
lock_caps
-
drop_root
drops root privileges, checks if effectively dropped then sets the process as not dumpable.See
drop_ptrace
-
drop_uid
drops privileged user to eitherrgid
,SUDO_GID
or an unuseduid
. -
drop_gid
drops privileged group to eitherrgid
,SUDO_GID
or an unusedgid
, also cleans supplementary groups. -
drop_ptrace
sets the process as not dumpable – forbids unprivilegedptrace(2)
calls to attach the process. -
lock_priv
is defined aslock_news
,lock_bits
andlock_caps
called in sequence. -
lock_caps
drop all capabilities – may requireCAP_SET_PCAP
. -
lock_bits
disables thread's "keep capabilities" flag,SECBIT_NOROOT
andSECBIT_NO_SETUID_FIXUP
, then locks them.See
capabilities(7)
+/The securebits
-
lock_news
sets thread'sno_new_privs
bit to disabled – inherited, see linuxDocumentation/prctl/no_new_privs.txt
. -
jail_strap
prepares a jail intosafedir
– works best with/proc/self/fdinfo
– and returnsfd
forjail_final
.See
jail_final
-
jail_final
effectively jail active process – it must be unprivileged to be effective.See
drop_root
Note: as jail_strap
chroot the calling process from a helper child – via
clone(2)
+ CLONE_FS
– into safedir
, setting safedir
to
/proc/self/fdinfo
prevents the unprivileged¹ parent to access the
filesystem – including .
and /
– as the proc(5)
pseudofiles attached
to the privileged child are protected – see ptrace(2)
+ /pseudofiles
.
¹after calling jail_strap
, a well-behaved calling process calls
drop_priv
and jail_final
in sequence, effectively jailing itself after
dropping its privileges.