Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.

Commit 8d61005

Browse files
committed
Matching rules per PL send payload script
1 parent 703bb1e commit 8d61005

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

util/send-payload-pls.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
#
3+
# Script to post a payload against a local webserver at each paranoia level
4+
#
5+
# Note: Webserver has to be prepared to take desired PL as Request Header "PL"
6+
#
7+
#Path to CRS rule set and local files
8+
CRS="/usr/share/modsecurity-crs/rules/"
9+
accesslog="/apache/logs/access.log"
10+
errorlog="/apache/logs/error.log"
11+
12+
#URL of web server
13+
URL="localhost:40080"
14+
15+
#Rules per Paranoia level
16+
#Paranoia level 1 rules, rule 012 is the phase 2 rule delimiter of the start of PL1
17+
#Paranoia level 1 rules, rule 013 is the phase 1 rule delimiter of the finish of PL1
18+
PL1=$(awk "/012,phase:2/,/013,phase:1/" $CRS/*.conf |egrep -v "(012|013),phase" |egrep -o "id:[0-9]+" |sed -r 's,id:([0-9]+),\1\\,' |tr -t '\n' '\|' |sed -r 's,\\\|$,,')
19+
20+
#Paranoia level 2 rules, rule 014 is the phase 2 rule delimiter of the start of PL2
21+
#Paranoia level 2 rules, rule 015 is the phase 1 rule delimiter of the finish of PL2
22+
PL2=$(awk "/014,phase:2/,/015,phase:1/" $CRS/*.conf |egrep -v "(014|015),phase" |egrep -o "id:[0-9]+" |sed -r 's,id:([0-9]+),\1\\,' |tr -t '\n' '\|' |sed -r 's,\\\|$,,')
23+
24+
#Paranoia level 3 rules, rule 016 is the phase 2 rule delimiter of the start of PL3
25+
#Paranoia level 3 rules, rule 017 is the phase 1 rule delimiter of the finish of PL3
26+
PL3=$(awk "/016,phase:2/,/017,phase:1/" $CRS/*.conf |egrep -v "(016|017),phase" |egrep -o "id:[0-9]+" |sed -r 's,id:([0-9]+),\1\\,' |tr -t '\n' '\|' |sed -r 's,\\\|$,,')
27+
28+
#Paranoia level 4 rules, rule 018 is the phase 2 rule delimiter of the start of PL4
29+
#Paranoia level 4 rules, "Paranoia Levels Finished" delimiter of the finish of PL4
30+
PL4=$(awk "/018,phase:2/,/Paranoia Levels Finished/" $CRS/*.conf |egrep -v "018,phase" |egrep -o "id:[0-9]+" |sed -r 's,id:([0-9]+),\1\\,' |tr -t '\n' '\|' |sed -r 's,\\\|$,,')
31+
32+
if [ ! -z "$1" ]; then
33+
PAYLOAD="$1"
34+
else
35+
echo "Please submit payload as parameter. This is fatal. Aborting."
36+
exit 1
37+
fi
38+
39+
echo "Sending the following payload at multiple paranoia levels: $PAYLOAD"
40+
echo
41+
42+
for PL in 1 2 3 4; do
43+
echo "--- Paranoia Level $PL ---"
44+
echo
45+
if [ -f "$PAYLOAD" ]; then
46+
curl $URL --data-binary "@$PAYLOAD" -H "PL: $PL" -o /dev/null -s
47+
else
48+
curl $URL -d "$PAYLOAD" -H "PL: $PL" -o /dev/null -s
49+
fi
50+
grep $(tail -1 $accesslog | cut -d\" -f11 | cut -b2-26) $errorlog | sed -e "s/.*\[id \"//" -e "s/\(......\).*\[msg \"/\1 /" -e "s/\"\].*//" -e "s/(Total .*/(Total ...) .../" -e "s/Incoming and Outgoing Score: [0-9]* [0-9]*/Incoming and Outgoing Score: .../" | sed -e "s/$PL1/& PL1/" -e "s/$PL2/& PL2/" -e "s/$PL4/& PL4/" | sort -k2
51+
echo
52+
echo -n "Total Incoming Score: "
53+
tail -1 $accesslog | cut -d\" -f11 | cut -d\ -f14 | tr "-" "0"
54+
echo
55+
done

0 commit comments

Comments
 (0)