Puteți folosi două reguli iptables: Prima pentru a înregistra evenimentul; Și al doilea să arunce pachetul.
Metoda 1, per port:
sudo iptables -A INPUT -p tcp --dport 25 -j LOG --log-prefix „EMAIL:” --log-level info
sudo iptables -A INPUT -p tcp --dport 25 -j DROP
sudo iptables -A INPUT -p udp --dport 33434 -j LOG --log-prefix "PORT33434:" --log-level info
sudo iptables -A INPUT -p udp --dport 33434 -j DROP
Metoda 2, multiport:
sudo iptables -A INPUT -p udp -m multiport --dport 33434:33448 -j LOG --log-prefix "MULTIUDP:" --log-level info
sudo iptables -A INPUT -p udp -m multiport --dport 33434:33448 -j DROP
sudo iptables -A INPUT -p tcp -m multiport --dport 23,2323 -j LOG --log-prefix „MULTITCP:” --log-level info
sudo iptables -A INPUT -p tcp -m multiport --dport 23,2323 -j DROP
Intrările de jurnal vor fi în /var/log/syslog
. Exemplu din sistemul meu pentru aceste reguli (unde folosesc un script și este un filtru de port sursă):
$IPTABLES -A INTRARE -i $EXTIF -p tcp -m multiport --sport 80,443 -j LOG --log-prefix „BAD80:” --log-level info
$IPTABLES -A INPUT -i $EXTIF -p tcp -m multiport --sport 80.443 -j DROP
doug@s15:~$ grep BAD80 /var/log/syslog | cap
1 august 00:02:17 kernel s15: [456814.408209] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =23.2.106.84 DST=173.180.45.4 LEN=44 TOS=0x08 PREC=0x20 TTL=52 ID=0 DF PROTO=TCP SPT=80 DPT=51602 WINDOW=64240 RES=0x00 ACK= SYN 0
1 august 00:08:37 kernel s15: [457195.250598] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=26786 WINDOW=0 RES=0x00 RST URGP=0
1 august 00:08:40 kernel s15: [457198.217675] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=18153 WINDOW=0 RES=0x00 RST URGP=0
1 august 00:09:02 kernel s15: [457220.036071] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =23.2.106.84 DST=173.180.45.4 LEN=44 TOS=0x08 PREC=0x20 TTL=52 ID=0 DF PROTO=TCP SPT=80 DPT=59130 WINDOW=64240 RES=0x00 ACK= SYN SYN
1 august 00:09:08 kernel s15: [457226.325411] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=24461 WINDOW=0 RES=0x00 RST URGP=0
1 august 00:15:34 kernel s15: [457612.178539] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=31895 WINDOW=0 RES=0x00 RST URGP=0
1 august 00:16:54 kernel s15: [457691.594480] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =23.2.106.84 DST=173.180.45.4 LEN=44 TOS=0x08 PREC=0x20 TTL=52 ID=0 DF PROTO=TCP SPT=80 DPT=52192 WINDOW=64240 RES=0x00 ACK= SYN SYN
1 august 00:22:29 kernel s15: [458026.722346] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=20888 WINDOW=0 RES=0x00 RST URGP=0
1 august 00:23:12 kernel s15: [458069.616810] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =23.2.106.84 DST=173.180.45.4 LEN=44 TOS=0x08 PREC=0x20 TTL=52 ID=0 DF PROTO=TCP SPT=80 DPT=52324 WINDOW=64240 RES=0x00 ACK= SYN 0
1 august 00:23:35 kernel s15: [458093.252954] BAD80:IN=enp1s0 OUT= MAC=68:05:ca:01:c5:e6:6c:be:e9:a7:f1:07:08:00 SRC =130.211.9.161 DST=173.180.45.4 LEN=40 TOS=0x00 PREC=0x80 TTL=62 ID=0 DF PROTO=TCP SPT=443 DPT=20218 WINDOW=0 RES=0x00 RST URGP=0
Vedea acest răspuns vechi pentru ajutor la înțelegerea intrărilor din jurnal.