#!/usr/bin/env bash # Verify rollback on invalid config, log API, WAF and unit enablement. set -uo pipefail ENTRY="${1:?usage: verify-hardening.sh }" BASE="http://127.0.0.1:8888/$ENTRY" PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt) curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' \ -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/tmp/login.out CSRF=$(python3 -c "import json;print(json.load(open('/tmp/login.out'))['data']['csrf'])") echo "=== 1. 非法 nginx 片段应被拒绝并回滚 ===" curl -s -o /tmp/bad.out -w 'HTTP %{http_code}\n' -b /tmp/ck.txt \ -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' -H "X-CSRF-Token: $CSRF" \ -X PUT -d '{"name":"demo","kind":"static","domains":["demo.test"],"port":80,"options":{"waf":true,"security_headers":true,"custom_nginx":"this_is_not_a_valid_directive;"}}' \ "$BASE/api/v1/sites/1" python3 - <<'PY' import json d = json.load(open('/tmp/bad.out')) print('resp:', d.get('code'), d.get('msg', '')[:120]) PY if [ -f /www/server/panel/vhost/nginx/extension/demo/90-custom.conf ]; then echo "回滚失败: 90-custom.conf 仍然存在"; exit 1 else echo "回滚成功: 90-custom.conf 未落盘" fi nginx -t 2>&1 | tail -1 curl -s -o /dev/null -w '站点仍可访问: %{http_code}\n' -H 'Host: demo.test' http://127.0.0.1/ echo "=== 2. 日志接口 ===" curl -s -b /tmp/ck.txt "$BASE/api/v1/sites/3/logs?type=app&lines=3" | head -c 300 echo curl -s -b /tmp/ck.txt "$BASE/api/v1/sites/1/logs?type=access&lines=2" | head -c 300 echo echo "=== 3. 开机自启 ===" for u in miaopanel miaopanel-site-nodedemo.service nginx php8.2-fpm; do printf '%-40s %s\n' "$u" "$(systemctl is-enabled "$u" 2>/dev/null || echo -)" done echo "=== 4. WAF 在 Node 站点生效 ===" curl -s -o /dev/null -w 'node.demo sqlmap UA -> %{http_code}\n' -A 'nikto/2.5' -H 'Host: node.demo' http://127.0.0.1/ curl -s -o /dev/null -w 'node.demo 正常 UA -> %{http_code}\n' -A 'Mozilla/5.0' -H 'Host: node.demo' http://127.0.0.1/ echo "=== 5. 审计日志 ===" curl -s -b /tmp/ck.txt "$BASE/api/v1/system/audit?limit=5" | python3 -m json.tool 2>/dev/null | head -30