PSAD也称为端口扫描攻击检测器,是在Linux系统上运行并分析iptables日志消息以检测端口扫描和其他可疑流量的轻量级系统守护程序的集合。PSAD用于将入侵检测系统更改为入侵防御系统。PSAD使用Snort规则检测入侵事件。它是专门设计用于Linux iptables / firewalld的,以检测可疑流量,例如端口扫描,后门和botnet命令。
在本教程中,我们将学习如何在Ubuntu Linux上安装和配置PSAD。
特征
- 支持iptables生成的IPv4和IPv6日志。
- 从Snort检测TCP SYN,FIN,NULL,XMAS扫描和许多签名规则。
- 具有TCP / UDP / ICMP扫描特征,反向dns和whois信息的电子邮件通知。
- icmp类型和代码头字段验证。
- 根据扫描级别自动通过iptables和tcpwrappers阻止可疑IP地址。
- 免费,并根据GNU通用公共许可证发行。
系统要求
- 新部署的Ubuntu 16.04服务器,安装了iptables。
- 在服务器上设置的静态IP地址192.168.15.189。
准备要部署的系统
在开始之前,您的系统应该是最新的,并且所有已安装的软件都在运行最新版本。
首先,登录到root用户并使用以下命令更新系统:
apt-get update -y
apt-get upgrade -y
更新系统后,重新启动系统。
安装Psad
默认情况下,Psad在Ubuntu存储库中可用。您可以通过运行以下命令来安装它:
apt-get install psad
Psad需要许多依赖关系,这些依赖关系是从Ubuntu存储库自动安装的。
为Psad配置iptables
在配置Psad之前,您将需要配置iptable日志以检测系统上的任何恶意活动。
您可以使用以下命令在iptables的输入和转发链上启用数据包日志记录:
iptables -A INPUT -j LOG
iptables -A FORWARD -j LOG
启用日志后,运行以下命令以列出iptables的当前配置:
iptables -L
您应该看到以下输出:
Chain INPUT (policy ACCEPT)
target prot opt source destination
LOG all -- anywhere anywhere LOG level warning
Chain FORWARD (policy ACCEPT)
target prot opt source destination
LOG all -- anywhere anywhere LOG level warning
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
配置Psad
默认情况下,Psad将其配置文件存储在/etc/psad目录下。
让我们开始编辑主要的psad配置/etc/psad/psad.conf,如下所示:
nano /etc/psad/psad.conf
更改文件,如下所示:
##Set the email address which you would like to notify when a report is generated.
EMAIL_ADDRESSES hitjethva@gmail.com;
##Your system hostname
HOSTNAME Node1;
##Specify the home and external networks.
HOME_NET 192.168.15.0/24;;
EXTERNAL_NET any;
##Danger levels. These represent the total number of packets required for a scan to reach each danger level.
DANGER_LEVEL1 5; ### Number of packets.
DANGER_LEVEL2 15;
DANGER_LEVEL3 150;
DANGER_LEVEL4 1500;
DANGER_LEVEL5 10000;
##By default, psad search for logs in /var/log/messages so change it to /var/log/syslog.
IPT_SYSLOG_FILE /var/log/syslog;
We will use PSAD as IDS/IPS, so enable it.
ENABLE_AUTO_IDS Y;
##Specify port which you should tell psad to ignore attempts on these ports.
IGNORE_PORTS NONE;
完成后保存并关闭文件。然后更新签名,以便它可以正确识别已知的攻击类型。
psad --sig-update
您应该看到以下输出:
Length: 45267 (44K)
Saving to: 'signatures'
signatures 100%[======================================================================>] 44.21K 58.4KB/s in 0.8s
2017-06-10 10:06:51 (58.4 KB/s) - 'signatures' saved [45267/45267]
[+] New signature file /etc/psad/signatures has been put in place. You can restart psad (or use 'psad -H') to import the new sigs.
启动Psad
完成所有配置后,请重新启动psad服务以实施配置更改。
systemctl restart psad
现在,使用以下命令检查psad检测到的事件的当前状态:
psad -S
您应该看到在以下输出中未找到任何内容:
[-] psad: pid file /var/run/psad/psadwatchd.pid does not exist for psadwatchd on Node1
[+] psad (pid: 14777) %CPU: 0.0 %MEM: 2.1
Running since: Sat Jun 10 10:10:21 2017
Command line arguments: [none specified]
Alert email address(es): root@localhost
[+] Version: psad v2.2.3
[+] Top 50 signature matches:
[NONE]
[+] Top 25 attackers:
[NONE]
[+] Top 20 scanned ports:
udp 33577 2 packets
[+] iptables log prefix counters:
[NONE]
Total protocol packet counters:
udp: 2 pkts
[+] IP Status Detail:
[NONE]
Total scan sources: 0
Total scan destinations: 0
[+] These results are available in: /var/log/psad/status.out
测试节奏
Psad现在已启动并正在运行。现在该测试Psad了。
在远程计算机上,使用Nmap工具扫描服务器的端口。
如果未安装Nmap,请运行以下命令以安装Nmap:
apt-get install nmap
接下来,运行以下命令来扫描服务器的端口:
nmap -PN -sS 192.168.15.189
您应该看到以下输出:
Starting Nmap 6.40 ( http://nmap.org ) at 2017-06-10 10:15 IST
Nmap scan report for Node1 (192.168.15.189)
Host is up (0.0076s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
MAC Address: 08:00:27:7C:5B:40 (Cadmus Computer Systems)
Nmap done: 1 IP address (1 host up) scanned in 1.89 seconds
在服务器计算机上,使用以下命令检查Psad的状态:
psad -S
PSAD守护程序阻止了攻击者192.168.15.196的IP地址,如下所示:
[+] Top 25 attackers:
192.168.15.196 DL: 3, Packets: 1087, Sig count: 41
192.168.15.1 DL: 2, Packets: 24, Sig count: 0
0.0.0.0 DL: 1, Packets: 8, Sig count: 0
[+] Top 20 scanned ports:
tcp 50000 2 packets
tcp 1782 2 packets
tcp 17 2 packets
tcp 543 2 packets
tcp 55600 2 packets
tcp 6106 2 packets
tcp 19101 2 packets
tcp 4567 2 packets
tcp 1137 2 packets
.
.
.
[+] iptables log prefix counters:
[NONE]
iptables auto-blocked IPs:
192.168.15.1 (3119 seconds remaining)
192.168.15.196 (3341 seconds remaining)
Total protocol packet counters:
tcp: 1085 pkts
udp: 26 pkts
[+] IP Status Detail:
SRC: 192.168.15.196, DL: 3, Dsts: 1, Pkts: 1085, Total protocols: 1, Unique sigs: 33, Email alerts: 1, Local IP
DST: 192.168.15.189, Local IP
Scanned ports: TCP 1-65389, Pkts: 1085, Chain: INPUT, Intf: eth0
您还可以使用以下命令查看IPtables规则阻止的攻击者IP地址:
iptables -L
输出:
[+] Listing chains from IPT_AUTO_CHAIN keywords...
Chain PSAD_BLOCK_INPUT (1 references)
pkts bytes target prot opt in out source destination
27 3283 DROP all -- * * 192.168.15.196 0.0.0.0/0
0 0 DROP all -- * * 192.168.15.1 0.0.0.0/0
Chain PSAD_BLOCK_OUTPUT (1 references)
pkts bytes target prot opt in out source destination
9 540 DROP all -- * * 0.0.0.0/0 192.168.15.196
46 2426 DROP all -- * * 0.0.0.0/0 192.168.15.1
Chain PSAD_BLOCK_FORWARD (1 references)
pkts bytes target prot opt in out source destination
0 0 DROP all -- * * 0.0.0.0/0 192.168.15.196
0 0 DROP all -- * * 192.168.15.196 0.0.0.0/0
0 0 DROP all -- * * 0.0.0.0/0 192.168.15.1
0 0 DROP all -- * * 192.168.15.1 0.0.0.0/0
如果要允许Psad阻止所有IP地址,请运行以下命令:
psad -F
如果要允许被Psad阻止的特定IP地址,请运行以下命令:
psad --fw-rm-block-ip 192.168.15.196
您还可以通过以下命令了解有关psad命令示例和选项的更多信息:
man psad
结论
在上面的文章中,我们已经学会了如何安装和使用PSAD工具阻止Linux系统上的端口扫描攻击。我希望你现在可以轻松地安装和配置PSAD来阻止恶意IP地址。
参考资料