System Security

Sandboxing

Computer security sandboxing refers to a technique used to isolate potentially malicious code or untrusted programs, ensuring they run in a confined environment where they cannot cause harm to the broader system. By creating a 'sandbox' or restricted space for these programs to operate in, any malicious actions are confined to this isolated area, preventing potential damage to the host system or access to sensitive data. This module explores sandboxing techniques as well as how hackers can escape a misconfigured sandbox.

18 challenges

Sandboxing: Introduction

Tips, Tricks, and Further Reading

Some tips and tricks for the challenge problems!

  • Be very careful to understand the timeline of what the challenge does. A file opened BEFORE chroot() is very different from a file opened AFTER chroot(). The sequence of actions makes a big difference.
  • There aren't any restrictions on shellcode (other than syscalls), so we highly recommend making sure your shellcode exits cleanly. That will make it easier to debug.
  • You can determine the value of constants such as AT_FDCWD by writing a quick C program that includes the relevant header files and does printf("%d\n", AT_FDCWD);.
  • chroot() will fail if you're not running as root. strace causes the SUID bit to be ignored, so you must use sudo strace to properly trace these challenges. Of course, this will only be possible in practice mode.
  • There is a known issue with strace that, in certain configurations, it will improperly resolve the syscall number of 32-bit syscalls in amd64. Using a newer Linux VM sometimes helps. If you're using int 0x80 to trigger system calls, the 32-bit ones ARE being used; strace is just lying to you.
  • On the subject of 32-bit syscalls: you do not have to assemble your shellcode in 32-bit mode (i.e., you don't need -m32). It is perfectly valid to just up and int 0x80 in the middle of an otherwise-64-bit shellcode.
  • Read this thoroughly, especially Section 3.6.1.

Filesystem Sandboxing

Sandboxing: chroot

CHALLENGE 01

chroot-escape-basic

— solves

Escape a basic chroot sandbox!

CHALLENGE 02

chroot-shellcode

— solves

Escape a basic chroot sandbox by utilizing shellcode.

CHALLENGE 03

chroot-proper

— solves

Escape a chroot sandbox with shellcode.

System Call Sandboxing

Sandboxing: seccomp

Sandboxing: Escaping seccomp

CHALLENGE 04

seccomp-basic

— solves

Escape a chroot sandbox using shellcode, but this time only using the following syscalls: ["openat", "read", "write", "sendfile"]

CHALLENGE 05

seccomp-linkat

— solves

Escape a chroot sandbox using shellcode, but this time only using the following syscalls: ["linkat", "open", "read", "write", "sendfile"]

CHALLENGE 06

seccomp-fchdir

— solves

Escape a chroot sandbox using shellcode, but this time only using the following syscalls: ["fchdir", "open", "read", "write", "sendfile"]

CHALLENGE 07

seccomp-rechroot

— solves

Escape a chroot sandbox using shellcode, but this time only using the following syscalls: ["chdir", "chroot", "mkdir", "open", "read", "write", "sendfile"]

CHALLENGE 08

seccomp-only

— solves

Escape a chroot sandbox using shellcode, but this time only using the following syscalls: ["openat", "read", "write", "sendfile"]

CHALLENGE 09

seccomp-arch32

— solves

Escape a chroot sandbox using shellcode, but this time only using the following syscalls: ["close", "stat", "fstat", "lstat"]

CHALLENGE 10

seccomp-minimal

— solves

Escape a chroot sandbox using shellcode, but this time only using the following syscalls: ["read", "exit"]. Note that "write" is disabled! You will need a creative way of extracting the flag data from your process!

CHALLENGE 11

seccomp-timebased

— solves

Escape a chroot sandbox using shellcode, but this time only using the following syscalls: ["read", "nanosleep"]. Note that "write" is disabled! You will need a creative way of extracting the flag data from your process!

CHALLENGE 12

seccomp-readonly

— solves

Escape a chroot sandbox using shellcode, but this time only using the following syscalls: ["read"]. Note that "write" is disabled! You will need a creative way of extracting the flag data from your process!

CHALLENGE 13

process-isolation

— solves

Escape a different kind of sandbox in which a jailed child process is only communicable to from a parent process.

Sandboxing via Namespaces

Sandboxing: Namespacing Live Session 1

Sandboxing: Namespacing Live Session 2

CHALLENGE 14

mount-namespace

— solves

Learn the implications of a different way of sandboxing, using modern namespacing techniques! But what if the sandbox is really sloppy?

CHALLENGE 15

mount-cleanup

— solves

Learn the implications of a different way of sandboxing, using modern namespacing techniques! But what are the implications of sharing filesystems between the sandbox and host?

CHALLENGE 16

mount-readonly

— solves

Learn the implications of a different way of sandboxing, using modern namespacing techniques! But what shenanigans can you get up to with special kernel-backed filesystems?

CHALLENGE 17

mount-shellcode

— solves

Learn the implications of a different way of sandboxing, using modern namespacing techniques! But what happens if you can smuggle in a resource from the outside?

CHALLENGE 18

mount-bindmount

— solves

Learn the implications of a different way of sandboxing, using modern namespacing techniques! What could be the harm of mounting in a harmless directory?