This repository has been archived by the owner on Sep 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
reputation-rbl.sh
executable file
·152 lines (120 loc) · 3.88 KB
/
reputation-rbl.sh
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
#
# Copyright (C) 2016, OVH SAS
#
# This file is part of ip-reputation-monitoring.
#
# ip-reputation-monitoring is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# RBL URL
STOP_FORUM_SPAM=http://www.stopforumspam.com/downloads/listed_ip_1_all.zip
SNDS="https://postmaster.live.com/snds/data.aspx?key=${SNDS_KEY}&days=2"
CLEANTALK=https://cleantalk.org/blacklists/AS${AS_NUMBER}
BLOCKLIST=http://lists.blocklist.de/lists/dnsbl/all.list
# User agent to get RBL with
USER_AGENT='Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0 Iceweasel/38.2.0'
# Directories computation
CURRENT_DIR=`dirname \`readlink -f $0\``
REPUTATION_DIR="${CURRENT_DIR}/reputation"
OUTPUT_DIR="${CURRENT_DIR}/temp"
REPUTATION_SCRIPT="${REPUTATION_DIR}/main.py"
# Download RBL and store them in ${OUTPUT_DIR}
function download {
>&2 echo "### Downloading files"
date 1>&2
cd ${OUTPUT_DIR}
### SFS ###
wget ${STOP_FORUM_SPAM} -U "${USER_AGENT}" --output-document=sfs.zip > /dev/null
unzip sfs.zip
rm -f sfs.zip
mv listed*txt sfs
### CLEAN TALK ###
if [ ! -z "${AS_NUMBER}" ]
then
wget ${CLEANTALK} -U "${USER_AGENT}" --output-document=cleantalk.html > /dev/null
cat ${OUTPUT_DIR}/cleantalk.html | ${REPUTATION_DIR}/tools/cleantalk/ct_formatter.py > cleantalk
rm -f ${OUTPUT_DIR}/cleantalk.html
else
>&2 echo "No AS_NUMBER varenv defined. Please define it to be able to fetch CleanTalk report."
fi
### BLOCK LIST DE (retry until it succeed...) ###
wget ${BLOCKLIST} -U "${USER_AGENT}" --output-document=blocklist > /dev/null
while [ $? -ne 0 ]
do
wget ${BLOCKLIST} -U "${USER_AGENT}" --output-document=blocklist > /dev/null
done
### SNDS (retry until it succeed...) only if you have a SNDS key ###
if [ ! -z "${SNDS_KEY}" ]
then
wget "${SNDS}" -U "${USER_AGENT}" --output-document=snds > /dev/null
while [ $? -ne 0 ]
do
wget "${SNDS}" -U "${USER_AGENT}" --output-document=snds > /dev/null
done
else
>&2 echo "Please define your personal SNDS key in SNDS_KEY varenv to fetch live.com abuse report"
fi
cd -
}
# Parse downloaded data
function parse {
if [ ! -z "${SNDS_KEY}" ]
then
>&2 echo "### Parsing SNDS"
date 1>&2
${REPUTATION_SCRIPT} --parse --snds "${OUTPUT_DIR}/snds"
fi
if [ ! -z "${AS_NUMBER}" ]
then
>&2 echo "###### Parsing CT"
date 1>&2
${REPUTATION_SCRIPT} --parse --cleantalk "${OUTPUT_DIR}/cleantalk"
fi
>&2 echo "###### Parsing BL"
date 1>&2
${REPUTATION_SCRIPT} --parse --blocklist "${OUTPUT_DIR}/blocklist"
>&2 echo "###### Parsing SFS"
date 1>&2
${REPUTATION_SCRIPT} --parse --stopforumspam "${OUTPUT_DIR}/sfs"
}
# Archive old entries
function purge {
>&2 echo "### Purging Mongo"
date 1>&2
${REPUTATION_SCRIPT} --purge
}
# Compute top 10 of ip with the worst reputation
function compute {
>&2 echo "### Sending Top10"
date 1>&2
${REPUTATION_SCRIPT} --scores
}
# Setting up temp dir
function setup {
if [ ! -e "${OUTPUT_DIR}" ]
then
mkdir ${OUTPUT_DIR}
fi
}
function main {
>&2 echo "# Starting fetcher"
date 1>&2
setup
download
parse
purge
compute
>&2 echo "# End fetcher"
date 1>&2
}
main