This repository contains a collection of scripts and configuration files to play with Linux Containers.
A modern Linux distribution. Tested on Fedora VERSION="40 (Server Edition)".
- A namespace is a way to isolate a process from the rest of the system.
- Let's see the default namespaces in a Linux system:
lsnsorlsns -t pidto see the namespaces of a process. Default value is 4026531836. - Check where the PID is running:
ls /proc/$$/ns -al - Run the golang program
scripts/1_get_my_pid/main.goto get the PID of the process. - Let's get the PID
pidof main - Check the namespaces of the process
pidof main | xargs -n1 lsns -p
Let's watch the pid namespaces
watch lsns -t pidLet's create a new PID namespace:
unshare -fp --mount-proc zshCheck the namespaces of the process
lsns -p $$Run the golang program
go run scripts/1_get_my_pid/main.go &to get the PID of the process.From another terminal check the namespaces of the process
cat /proc/$(pidof main)/status | grep NSpidCheck the PID of the process
pidof mainCheck all the namespaces
lsns -t pidLet's enter to the PID namespace
nsenter -t $(lsns -t pid | tail -n1 | awk {'print $4'}) -p -r zshLet's check the list of the processes
ps aux( Seen ??"!)Let's kill the process
kill -9 $(pidof main)
- Execute the script
scripts/network/2_create_network_namespace - Execute the script
ip netns exec blue zsh - Execute the script
ip netns exec red zsh
Execute the command
ip link add veth-red type veth peer name veth-blueExecute the command to one terminal
unshare -f -p -n -u --mount-proc /bin/zshSet hostname
hostname blueGet the net PID of the process
lsns -t netand get the PID-BLUEip link set veth-blue netns PID-BLUE
ip addr add 192.168.15.2/30 dev veth-blue
ip link set veth-blue up
PS1='$(uname -n)~: '
Execute the command to second terminal
unshare -f -p -n -u --mount-proc /bin/zshSet hostname
hostname redFrom the root: Get the net PID of the process
lsns -t netand get the PID-REDip link set veth-red netns PID-RED
ip link set veth-red up
ip addr add 192.168.15.1/30 dev veth-red
from the red
nc -lv 5552from the blue
telnet 192.168.15.1 5552check
lsns -t netExecute the command to one terminal
nsenter -n -t PID-BLUE zshExecute the script
/ebpf_ns_firewall/makeCheck
cat /sys/kernel/debug/tracing/trace_pipeThe firewall is blocking the connection
5552from the blue to the redTry nc with another port
nc -lv 5553andtelnetagain
go run scripts/leak/3_create_leak.go- mkdir /sys/fs/cgroup/limitapps
- echo "100M" >/sys/fs/cgroup/limitapps/memory.max && echo "100M" >/sys/fs/cgroup/limitapps/memory.swap.high && echo "100M" >/sys/fs/cgroup/limitapps/memory.swap.max
- echo $(pidof 3_create_leak) >/sys/fs/cgroup/limitapps/cgroup.procs
- dmesg | tail -n1
- Let's create a new UTS namespace:
unshare -fn zsh - Check the namespaces of the process
lsns -p $$ - Let's change the hostname
hostname mycontainer - Let's check the hostname
hostname - Let's exit the UTS namespace
exit
- Let's create a new mount namespace:
unshare -fm zsh - Check the namespaces of the process
lsns -p $$ - Let's check the mount points
mount - Let's create a new mount point
mkdir /tmp/mountpoint - Let's mount the proc filesystem
mount -t proc proc /tmp/mountpoint - Let's check the mount points
mount - Let's unmount the proc filesystem
umount /tmp/mountpoint