+ #oct. 04 19:10:30 aurae.aoihime.eu kernel: net-fw DROP IN=enp3s0 OUT= MAC=50:46:5d:a1:a1:85:0c:86:10:f5:c6:4b:08:00 SRC=61.227.52.153 DST=144.76.27.210 LEN=52 TOS=0x00 PREC=0x00 TTL=116 ID=29123 DF PROTO=TCP SPT=64349 DPT=445 WINDOW=8192 RES=0x00 SYN URGP=0
+ #net-fw DROP IN=enp3s0 OUT= MAC=50:46:5d:a1:a1:85:0c:86:10:f5:c6:4b:08:00 SRC=110.34.70.110 DST=144.76.27.210 LEN=40 TOS=0x00 PREC=0x00 TTL=50 ID=17488 PROTO=TCP SPT=58225 DPT=34567 WINDOW=53283 RES=0x00 SYN URGP=0
+ if (/net-fw DROP .* SRC=([^\s]+) .* PROTO=([^\s]+) .* DPT=([^\s]+)/) {
+ #Save ip
+ my $ip = $1;
+ #Save proto
+ my $proto = lc($2);
+ #Save dpt
+ my $dpt = $3;
+ #Check if v4 ip and not in whitelist
+ #if (is_ipv4($ip) && not scalar map { my $network = NetAddr::IP->new($_); my $netip = NetAddr::IP->new($ip); unless ($network->contains($netip)) { (); } } @{$iplist{ipv4}}) {
+ if (is_ipv4($ip) && not scalar map { my $network = new_ipv4($_); my $netip = new_ipv4($ip); unless ($network->contains($netip)) { (); } } @{$iplist{ipv4}}) {
+ if (!defined $ip4s{$ip}) {
+ %{$ip4s{$ip}} = ('tcp' => {}, 'udp' => {});
+ }
+ #Add ip in v4 blacklist
+ $ip4s{$ip}{$proto}{$dpt}=1;
+ } elsif (is_ipv6($ip) && not scalar map { my $network = NetAddr::IP->new($_); my $netip = NetAddr::IP->new($ip); unless ($network->contains($netip)) { (); } } @{$iplist{ipv6}}) {
+ if (!defined $ip6s{$ip}) {
+ %{$ip6s{$ip}} = ('tcp' => {}, 'udp' => {});
+ }
+ #Add ip in v6 blacklist
+ $ip6s{$ip}{$proto}{$dpt}=1;
+ }
+ #oct. 04 19:17:10 aurae.aoihime.eu kernel: audit: type=1100 audit(1570209430.543:17321294): pid=5890 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=195.154.112.70 addr=195.154.112.70 terminal=ssh res=failed'
+ #audit: type=1100 audit(1570291573.615:8660): pid=3225 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:authentication grantors=? acct="root" exe="/usr/sbin/sshd" hostname=222.186.180.9 addr=222.186.180.9 terminal=ssh res=failed'
+ } elsif (/op=PAM:authentication grantors=\? acct="(.+)" exe="\/usr\/(?:libexec\/dovecot\/auth|sbin\/sshd)" hostname=.+ addr=(.+) terminal=(dovecot|ssh) res=failed/ && grep($_ ne $1, @userlist)) {
+ #Save ip
+ my $ip = $2;
+ #Init blacklist
+ my %blacklist = ('tcp' => [], 'udp' => []);
+ #Set ssh proto and port tuple
+ if ($3 eq 'ssh') {
+ #Set blacklist for 22 dest port on tcp
+ #$blacklist{'tcp'}[$#{$blacklist{'tcp'}}+1] = 22;
+ %blacklist = ('tcp' => [ 22 ]);
+ #Set dovecot proto and port tuples
+ } elsif ($3 eq 'dovecot') {
+ #Set blacklist for 25, 143, 587, 993 dest ports on tcp and udp
+ %blacklist = ('tcp' => [ 25, 143, 587, 993 ], 'udp' => [ 25, 143, 587, 993 ]);
+ #Set other proto and port tuples
+ } else {