forked from DepthFirstDisclosures/Nginx-Rift
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnix-setup.sh
More file actions
executable file
·120 lines (107 loc) · 4.86 KB
/
Copy pathnix-setup.sh
File metadata and controls
executable file
·120 lines (107 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
# nix-setup.sh — Nix + Podman alternative to the docker compose workflow.
#
# Replaces:
# ./setup.sh -> ./nix-setup.sh build
# docker compose -f env/docker-compose.yml up -> ./nix-setup.sh start
#
# Requires: nix (flakes enabled), podman
set -euo pipefail
IMAGE="nginx-rift:vulnerable"
CONTAINER="nginx-rift-poc"
PORT=19321
# ── build ──────────────────────────────────────────────────────────────────
# Compiles nginx from commit 98fc3bb78 via Nix and loads the OCI image into
# Podman. Equivalent to `docker compose build` in the original workflow.
build() {
echo "[*] Generating flake.lock (first run only)..."
[[ -f flake.lock ]] || nix flake update
echo "[*] Building vulnerable nginx (98fc3bb78) from source via Nix..."
echo " (this compiles nginx — takes a few minutes on first run)"
nix build .#dockerImage --out-link result-docker
echo "[*] Loading OCI image into Podman..."
podman load < result-docker
echo "[+] Image ready: ${IMAGE}"
}
# ── start ──────────────────────────────────────────────────────────────────
# Starts the container with ASLR disabled.
# Equivalent to `docker compose -f env/docker-compose.yml up`.
start() {
echo "[*] Starting vulnerable nginx container (ASLR disabled)..."
podman rm -f "${CONTAINER}" 2>/dev/null || true
podman run -d \
--name "${CONTAINER}" \
-p "${PORT}:19321" \
--cap-add SYS_PTRACE \
--security-opt seccomp=unconfined \
"${IMAGE}"
echo "[*] Waiting for nginx..."
for i in $(seq 1 15); do
if python3 -c "
import socket, sys
try:
s = socket.create_connection(('127.0.0.1', ${PORT}), timeout=1)
s.sendall(b'GET / HTTP/1.1\r\nHost:l\r\nConnection:close\r\n\r\n')
s.recv(10); s.close(); sys.exit(0)
except: sys.exit(1)
" 2>/dev/null; then
echo "[+] nginx is up on 127.0.0.1:${PORT}"
return
fi
sleep 0.5
done
echo "[!] nginx did not respond in time"
podman logs "${CONTAINER}" 2>&1 | tail -20
exit 1
}
# ── stop ───────────────────────────────────────────────────────────────────
stop() {
echo "[*] Stopping container..."
podman stop "${CONTAINER}" 2>/dev/null || true
podman rm "${CONTAINER}" 2>/dev/null || true
echo "[+] Done"
}
# ── logs ───────────────────────────────────────────────────────────────────
logs() { podman logs -f "${CONTAINER}"; }
# ── exec ───────────────────────────────────────────────────────────────────
# Equivalent to `docker compose exec nginx <cmd>`.
exec_cmd() { podman exec "${CONTAINER}" "$@"; }
# ── poc ────────────────────────────────────────────────────────────────────
poc() {
echo "[*] Running Nginx-Rift PoC..."
python3 poc.py "$@"
}
# ── dispatch ───────────────────────────────────────────────────────────────
case "${1:-help}" in
build) build ;;
start) start ;;
stop) stop ;;
logs) logs ;;
exec) shift; exec_cmd "$@" ;;
poc) shift; poc "$@" ;;
all)
build
start
echo ""
echo " # Terminal 1 — server is running. In another terminal:"
echo " ./nix-setup.sh poc --cmd 'id > /tmp/pwned'"
echo ""
echo " # Verify:"
echo " ./nix-setup.sh exec cat /tmp/pwned"
;;
*)
cat <<EOF
Usage: $0 <command> [args]
build Compile nginx ${COMMIT:-98fc3bb78} via Nix and load into Podman
start Start vulnerable nginx (port ${PORT}, ASLR disabled)
stop Stop and remove the container
logs Tail container logs
exec <cmd> Run command inside the running container
poc [args] Run poc.py (pass extra args directly, e.g. --cmd 'id > /tmp/pwned')
all build + start, then print usage hint
Original docker compose workflow:
./setup.sh -> ./nix-setup.sh build
docker compose -f env/docker-compose.yml up -> ./nix-setup.sh start
EOF
;;
esac