Skip to content

Commit

Permalink
mxrouter: Add primitive blacklist
Browse files Browse the repository at this point in the history
With the current Emotet outbreak, I want at least temporarily
to maintain and apply a blacklist of the IP addresses of
its C&C servers.

https://www.dfn-cert.de/aktuell/emotet-aktuell.html

Add a rudimentary blacklist feature. IPs from
/etc/local/mxrouter/ip-blacklist are loaded into the ipset ip-blacklist
on router start or reload. This ipset can be used by netfilter rules to
block traffic to/from that ip.
  • Loading branch information
donald committed Sep 29, 2019
1 parent 42f232a commit 9c725e5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mxrouter/mxrouterctl
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ sub disable_ipv4_rp_filter {
$disable_ipv4_rp_filter{$if}=1;
}

sub reload_ip_blacklist {
sys('ipset','flush','ip-blacklist');
if (-e '/etc/local/mxrouter/ip-blacklist') {
open my $in,'<','/etc/local/mxrouter/ip-blacklist' or die "/etc/local/mxrouter/ip-blacklist: $!\n";
while (<$in>) {
s/#.*//;
/^\s*(\d+\.\d+\.\d+\.\d+)\s*$/ or next;
system('ipset','add','ip-blacklist',$1);
}
}
}

sub start {

-d "/var/run/mxrouter/$NETNS" or sys ('mkdir','-p',"/var/run/mxrouter/$NETNS");
Expand Down Expand Up @@ -519,6 +531,8 @@ sub start {
start_process_if($process_radvd);

unless ($opt_noop) {
sys('ipset','create','-exist','ip-blacklist','hash:ip','counters');
reload_ip_blacklist();
open my $pipe,'|-','iptables-restore' or die "$!\n";
print $pipe rules_in_restore_format();
close $pipe or die "$!\n";
Expand Down

0 comments on commit 9c725e5

Please sign in to comment.