After getting a shell through an exploited container, how can you tell whether you landed inside the container or on the host?
Inspect PID 1 via /proc/1/status — in a container the initial process is the containerised app (e.g. the web server), on the host it is the init system (systemd).
Every Linux process appears under /proc/<pid>/, and /proc/1/status names the process with PID 1 — the first process in that PID namespace. Reading it tells you where you are:
cat /proc/1/status # look at the Name: field
- Inside a container: PID 1 is whatever the container started as its main process — the web server,
sh, etc. The container has its own PID namespace starting at 1. - On the host: PID 1 is the host's init system, normally
systemd(orinit).
In the lab's Shellshock exercise the reverse shell runs as the www-data user and PID 1 is the container's web process — confirming the attacker is (for now) confined to the container, not yet on the host. It is a quick orientation check that tells an attacker whether they still need to escape, and tells a defender how far an intrusion has reached.
Go deeper:
man7.org: user_namespaces(7) — how PID and user namespaces give a container its own PID 1.