Skip to content

Commit 13e1d6a

Browse files
committed
[WebUI] Add support for blacklist script
1 parent 1b22df5 commit 13e1d6a

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed

bin/v-add-firewall-ipset

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ inet_ver="inet"
125125
[ "$ip_version" == "v6" ] && inet_ver="inet6"
126126

127127
$IPSET_BIN create "$ip_name" -exist hash:net family $inet_ver
128-
$IPSET_BIN create "${ip_name}-tmp" -exist hash:net family $inet_ver
128+
$IPSET_BIN -quiet destroy "${ip_name}-tmp"
129+
$IPSET_BIN create "${ip_name}-tmp" -exist hash:net family $inet_ver maxelem 1048576
129130
$IPSET_BIN flush "${ip_name}-tmp"
130131

131132
sed -rn -e '/^#|^$/d' -e "s/^(.*)/add ${ip_name}-tmp \\1/p" "${IPSET_PATH}/${IPSET_FILE}.iplist" | $IPSET_BIN -quiet restore
132133
check_result $? "Populating ipset table"
133134

134135
$IPSET_BIN swap "${ip_name}-tmp" "${ip_name}"
135-
$IPSET_BIN --quiet destroy "${ip_name}-tmp"
136+
$IPSET_BIN -quiet destroy "${ip_name}-tmp"
136137

137138

138139
# Generating timestamp

bin/v-delete-firewall-ipset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ fi
5050
# Action #
5151
#----------------------------------------------------------#
5252

53-
if $IPSET_BIN --quiet list "${ip_name}-tmp"; then
53+
if $IPSET_BIN --quiet list "${ip_name}-tmp" >/dev/null; then
5454
$IPSET_BIN --quiet destroy "${ip_name}-tmp"
5555
fi
5656

57-
if $IPSET_BIN --quiet list "${ip_name}"; then
57+
if $IPSET_BIN --quiet list "${ip_name}" >/dev/null; then
5858
$IPSET_BIN --quiet destroy "${ip_name}"
5959
check_result $? "ipset ${ip_name} still used by iptables. Cannot remove"
6060
fi
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Script and blacklist urls partially taken from:
4+
# https://github.com/trick77/ipset-blacklist/blob/master/ipset-blacklist.conf
5+
#
6+
7+
BLACKLISTS=(
8+
"https://www.projecthoneypot.org/list_of_ips.php?t=d&rss=1" # Project Honey Pot Directory of Dictionary Attacker IPs
9+
"https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=1.1.1.1" # TOR Exit Nodes
10+
"https://www.maxmind.com/en/high-risk-ip-sample-list" # MaxMind GeoIP Anonymous Proxies
11+
"http://danger.rulez.sk/projects/bruteforceblocker/blist.php" # BruteForceBlocker IP List
12+
"https://www.spamhaus.org/drop/drop.lasso" # Spamhaus Don't Route Or Peer List (DROP)
13+
"https://cinsscore.com/list/ci-badguys.txt" # C.I. Army Malicious IP List
14+
"https://lists.blocklist.de/lists/all.txt" # blocklist.de attackers
15+
"https://blocklist.greensnow.co/greensnow.txt" # GreenSnow
16+
"https://raw.githubusercontent.com/firehol/blocklist-ipsets/master/firehol_level1.netset" # Firehol Level 1
17+
"https://raw.githubusercontent.com/firehol/blocklist-ipsets/master/stopforumspam_7d.ipset" # Stopforumspam via Firehol
18+
)
19+
20+
21+
IP_BLACKLIST_TMP=$(mktemp)
22+
for i in "${BLACKLISTS[@]}"; do
23+
IP_TMP=$(mktemp)
24+
(( HTTP_RC=$(curl -L --connect-timeout 10 --max-time 10 -o "$IP_TMP" -s -w "%{http_code}" "$i") ))
25+
if (( HTTP_RC == 200 || HTTP_RC == 302 || HTTP_RC == 0 )); then # "0" because file:/// returns 000
26+
command grep -Po '^(?:\d{1,3}\.){3}\d{1,3}(?:/\d{1,2})?' "$IP_TMP" | sed -r 's/^0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+)$/\1.\2.\3.\4/' >> "$IP_BLACKLIST_TMP"
27+
elif (( HTTP_RC == 503 )); then
28+
echo >&2 -e "\\nUnavailable (${HTTP_RC}): $i"
29+
else
30+
echo >&2 -e "\\nWarning: curl returned HTTP response code $HTTP_RC for URL $i"
31+
fi
32+
rm -f "$IP_TMP"
33+
done
34+
35+
sed -r -e '/^(0\.0\.0\.0|10\.|127\.|172\.1[6-9]\.|172\.2[0-9]\.|172\.3[0-1]\.|192\.168\.|22[4-9]\.|23[0-9]\.)/d' "$IP_BLACKLIST_TMP"|sort -n|sort -mu
36+
rm -f "$IP_BLACKLIST_TMP"

web/templates/admin/add_firewall_ipset.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,37 @@
140140
*/
141141
];
142142

143+
var blacklist_iplists = [
144+
{name: "[ipv4] Blacklist Script", source:"script:/usr/local/hestia/install/deb/firewall/ipset/blacklist.sh"},
145+
/*
146+
{name: "[ipv6] Blacklist Script", source:"script:/usr/local/hestia/install/deb/firewall/ipset/blacklist.ipv6.sh"},
147+
*/
148+
];
149+
143150
country_iplists.sort(function (a, b) {
144151
return a.name > b.name;
145152
});
146153

154+
blacklist_iplists.sort(function (a, b) {
155+
return a.name > b.name;
156+
});
157+
147158
$(function() {
148159
var targetelement = document.getElementById('datasource_list');
149160

161+
// Blacklist
162+
var newEl = document.createElement("option");
163+
newEl.text="BLACKLIST";
164+
newEl.disabled=true;
165+
targetelement.appendChild(newEl);
166+
167+
blacklist_iplists.forEach(iplist => {
168+
var newEl = document.createElement("option");
169+
newEl.text=iplist.name;
170+
newEl.value=iplist.source;
171+
targetelement.appendChild(newEl);
172+
});
173+
150174
// IPVERSE
151175
var newEl = document.createElement("option");
152176
newEl.text="IPVERSE";

0 commit comments

Comments
 (0)