Skip to content

Commit

Permalink
Merge pull request #38 from Honeybrain/feature/countryBlocking
Browse files Browse the repository at this point in the history
✨ Update fail2ban for geoIP support
  • Loading branch information
valentinbreiz authored Jan 3, 2024
2 parents d78f83d + c97a717 commit 3ceb70e
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2 deletions.
59 changes: 59 additions & 0 deletions config/fail2ban/action.d/geohostsdeny.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[Definition]

# Option: actionstart
# Notes.: command executed once at the start of Fail2Ban.
# Values: CMD
#
actionstart =

# Option: actionstop
# Notes.: command executed once at the end of Fail2Ban
# Values: CMD
#
actionstop =

# Option: actioncheck
# Notes.: command executed once before each actionban command
# Values: CMD
#
actioncheck =

# Option: actionban
# Notes.: command executed when banning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Excludes PH|Philippines from banning.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionban = IP=<ip> &&
geoiplookup $IP | egrep "<country_list>" ||
(printf %%b "<daemon_list>: $IP\n" >> <file>)

# Option: actionunban
# Notes.: command executed when unbanning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionunban = IP=<ip> && sed -i.old /ALL:\ $IP/d <file>

[Init]

# Option: country_list
# Notes.: List of banned countries separated by pipe "|"
# Values: STR Default:
#
country_list = PH

# Option: file
# Notes.: hosts.deny file path.
# Values: STR Default: /etc/hosts.deny
#
file = /etc/hosts.deny

# Option: daemon_list
# Notes: The list of services that this action will deny. See the man page
# for hosts.deny/hosts_access. Default is all services.
# Values: STR Default: ALL
daemon_list = ALL

3 changes: 3 additions & 0 deletions config/fail2ban/jail.d/jail.local
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ findtime = 600
# How many attempts can be made before a ban is imposed
maxretry = 3

# Define the banaction globally if you want all jails to use the geohostsdeny action
banaction = geohostsdeny

[iptables-honeypot]
enabled = true
port = all
Expand Down
1 change: 1 addition & 0 deletions docker/compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ services:
- "../../logs/suricata/fast.log:/app/honeypot/fast.log"
- "../../config/suricata/suricata.rules:/app/honeypot/suricata.rules"
- "../../config/fail2ban/filter.d/nginx-honeypot.conf:/app/honeypot/nginx-honeypot.conf"
- "../../config/fail2ban/action.d/geohostsdeny.conf:/app/honeypot/geohostsdeny.conf"
- "../../config/nginx/block.conf:/app/honeypot/block.conf"
- "/var/run/docker.sock:/var/run/docker.sock"
healthcheck:
Expand Down
3 changes: 2 additions & 1 deletion docker/dockerfile/fail2ban/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ FROM crazymax/fail2ban:latest

USER root

RUN apk add --no-cache docker-cli
RUN apk add --no-cache docker-cli
RUN apk add --no-cache geoip
8 changes: 8 additions & 0 deletions protos/blacklist.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package blacklist;

service Blacklist {
rpc PutBlackList (PutBlackListRequest) returns (PutBlackListReply) {}
rpc BlockCountry (BlockCountryRequest) returns (BlockCountryReply) {}
rpc GetBlackList (GetBlackListRequest) returns (stream GetBlackListReply) {}
rpc PutWhiteList (PutWhiteListRequest) returns (PutWhiteListReply) {}
}
Expand All @@ -15,6 +16,13 @@ message PutBlackListRequest {
message PutBlackListReply {
}

message BlockCountryRequest {
string countryCode = 1;
}

message BlockCountryReply {
}

message GetBlackListRequest {}

message GetBlackListReply {
Expand Down
Empty file modified scripts/auto_update_vps.sh
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion scripts/check_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ if ! python3 -c "import jinja2" &> /dev/null; then
echo "❌ Error: jinja2 is not installed for python3. Please install 'jinja2' pip3 package."
exit 1
fi
echo "✅ jinja2 is installed."
echo "✅ jinja2 is installed."

0 comments on commit 3ceb70e

Please sign in to comment.