Let's chart our escapes based on what a container is under the hood.
namespaces - what a container can SEE
cgroups - what a container can HAVE
capabilities - what a container can DO
overlayfs - the weird filesystem that stacks on
top of itself
AppArmor or SELinux are part of the host's kernel called Mandatory
Access Control. They make sure each process can only touch things
it's allowed to.
Namespaces (see)
How single resources, like a network card, are shared across many
processes without those processes seeing each other.
Hostname (uts)
System time (time)
Inter-process comms (ipc)
Control groups! (cgroup)
Mount points (mount)
Network (network)
Process IDs (process)
User IDs (user)
Minimizing what a container can see
Reduces attack surface
Reduces amount of information exposed for living off the
land
Control groups (have)
It's a weird filesystem.
Defines and sets boundaries on what a process can have.
Protect it. Messing with it can be part of a denial of
service attack.
Capabilities (do) - let's get dangerous!
Used to be root/admin/everything or nothing at all
Now there's about 40 unique permissions
CAP_NET_BIND_SERVICE
CAP_AUDIT_READ
CAP_SYS_PTRACE
CAP_SYS_ADMIN is effectively everything
Be careful out there!
This gives us a better escape and more of a foothold once we're
out.
Mandatory Access Controls
One more line of defense - SELinux or AppArmor
Part of the host - each process (container) can only touch/do
things based on
User
Role
File locations, processes, etc - CONTEXT
SELinux is more RedHat
AppArmor is more Debian
😩 The reason I bring this up is that it's common to disable
these! It's usually the first suggestion and it's easier to leave it off than troubleshoot and write a new policy.
What's an escape?
Types of escapes
Kernel vulnerabilities ("dirty pipe" or CVE-2022-0847)
Runtime vulnerabilities (2024's "leaky vessels" CVEs for runc and
BuildKit)
Insecure configuration at runtime
We're focusing on that third one.
Most common (in my experience)
Least "alarmed on" and most likely to get dismissed (in my experience)
... also most reliable in a workshop ...
Where this fits in an attack
Enumeration
Who am I? - Let's get oriented and figure out what
we have in our container.
Our shared kernel - Containers are processes that
share a kernel. What can we see?
Vulnerable apps in the wild - You're typically not
SSH'd into the container host, so ... how does this still work in the
wild?
Finding secrets in image layers - Finding secrets
in a container image's layers can be done at runtime if you have
access to download it and a shell or access to the host's socket or
access to the registry.