curl --silent --location --request GET 'https://raw.githubusercontent.com/saghul/lxd-alpine-builder/master/build-alpine' --remote-name
Building Alpine
From the Attacker ⚔️
bash ./build-alpine
Running the Exploit
From the Target 🎯
bash script.bash
Once inside the container, just go to /mnt/root to see all resources from the host machine
Docker
If the current user belongs to the docker group, we can spawn new docker containers and compromise the entire machine using volumes by mounting the system root / on the container’s /mnt directory
This is because, by default, both ROOT user and the Docker group have write permissions over the Docker Daemon’s Socket
Therefore, a member of the Docker group can use the docker command ( Docker Client ) to send requests to the Docker Daemon’s API REST without receiving an access denied error
Alternatively, Docker may have SUID set or the current user is in the sudoers file
In any case, we can create a Docker Container with a bind mount so that the host’s file system is accesible from the container
Members of this group have full access to any existing device within /dev, which means that file system permissions are ignored, so we can read the entire file system from the raw disk
To do so, we use debugfs
Interactive
debugfs <DISK> # debugfs /dev/sda1
Non-Interactive
debugfs -R 'cat <RESOURCE>' <DISK>
e.g.
debugfs -R 'cat /root/.ssh/id_rsa' /dev/sda5
ADM
Users belonging to the adm group commonly have read access to sensitive system logs under /var/log
Membership in adm is therefore an information disclosure capability rather than a direct privesc primitive
The directive above simply enable TTY Auditing for the john system user
Therefore, we can verify if audit logs are readable by the current user to subsequently look for sensitive information entered during a given TTY session
Checking whether Audit Logs are readable
find /var/log/audit -type f -readable -ls 2> /dev/null
A record such as new-enabled=1 or new-log_passwd=1 indicates that TTY auditing was enabled and configured to log input while terminal echo was disabled
Terminal echo is usually disabled on password prompts
Parsing TTY Events correctly
Once we have identified that TTY audit has been configured for an specific user to log every issued command by the latter, simply proceed as follows to parse all relevant information
ausearch
ausearch -m TTY -i --escape shell_quote
aureport
aureport --tty
Note that RAW audit data may contain bytes captured from TTY in hex format, so we can proceed as follows to decode it