-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodsecpars
More file actions
67 lines (54 loc) · 1.03 KB
/
modsecpars
File metadata and controls
67 lines (54 loc) · 1.03 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
#!/bin/bash
# Small Mod Security Log parser
# by Irek 'Monsoft' Pelech
IP=$1
FILE=$2
# get incident IDs
function get_iid () {
local ATTACKER_IP=$1
local LOG_FILE=$2
IID=($(grep -B1 "$ATTACKER_IP" $LOG_FILE|grep '\-A\-\-'|sed 's/--//g'))
}
function get_incidents () {
local LOG_FILE=$1
local X=0
for i in ${IID[@]}
do
X=$(echo ${i/A/H})
echo "$(grep -A 1 "$X" $LOG_FILE|egrep -Eo -m1 'id "[0-9]{6}"|msg \"([^]]+)\"'|tr '\n' ' ')"
done |sort| uniq -c
}
function show_ips () {
local LOG_FILE=$1
IIP=($(grep -A1 '\-A\-\-' "$LOG_FILE"|grep -v '\-A\-\-'|sed '/^--/d'|awk '{print $4}'))
for i in ${IIP[@]}
do
echo $i
done|sort -n| uniq
}
function help () {
cat <<EOF
modsecpars v. 1.0.0 (c) 2017 by Irek Pelech"
Usage: modsecpars [IP|log_file] [log_file]
EOF
}
### MAIN
# Print help
if [ $# -eq 0 ]
then
help
exit 0
fi
# Show intruders IPs
if [ $# -eq 1 ]
then
for i in $(show_ips $IP)
do
echo "Attacker IP: $i"
get_iid $i $IP
get_incidents $IP
done
exit 0
fi
get_iid $IP $FILE
get_incidents $FILE