miaopanel
1#!/usr/bin/env bash
2# Confirm 429 is counted as throttling, not as malicious traffic.
3set -uo pipefail
4ENTRY="${1:-ipdduiyy}"
5BASE="http://127.0.0.1:8888/$ENTRY"
6PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt)
7ORIGIN="http://127.0.0.1:8888"
8
9curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H "Origin: $ORIGIN" \
10 -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/dev/null
11
12before=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/waf/overview")
13echo "before: $(echo "$before" | python3 -c "import json,sys;d=json.load(sys.stdin)['data'];print('req',d['requests'],'blocked',d['blocked'],'throttled',d['throttled'])")"
14
15seq 1 400 | xargs -P 40 -I{} curl -s -o /dev/null -H 'Host: demo.test' "http://127.0.0.1/t{}"
16sleep 7
17
18after=$(curl -s -b /tmp/ck.txt "$BASE/api/v1/waf/overview")
19echo "after: $(echo "$after" | python3 -c "import json,sys;d=json.load(sys.stdin)['data'];print('req',d['requests'],'blocked',d['blocked'],'throttled',d['throttled'])")"
20
21echo "events:"
22curl -s -b /tmp/ck.txt "$BASE/api/v1/waf/events?limit=5" | python3 -c "
23import json,sys
24for e in json.load(sys.stdin)['data'][:5]:
25 print(' ', e['status'], e['rule'], e['uri'][:30])"