阅读量:41
在Linux系统中,配置入侵检测通常涉及使用iptables、firewalld或更高级的工具如Snort或Suricata。以下是使用这些工具进行入侵检测的基本步骤:
使用iptables进行基本的入侵检测
-
更新iptables规则:
sudo iptables -F sudo iptables -X -
设置默认策略:
sudo iptables -P INPUT DROP sudo iptables -P FORWARD DROP sudo iptables -P OUTPUT ACCEPT -
允许必要的流量:
sudo iptables -A INPUT -i lo -j ACCEPT sudo iptables -A OUTPUT -o lo -j ACCEPT sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT sudo iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # SSH sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT # HTTP sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT # HTTPS -
添加入侵检测规则:
sudo iptables -A INPUT -p tcp --dport 21 -j LOG --log-prefix "FTP attempt: " sudo iptables -A INPUT -p tcp --dport 23 -j LOG --log-prefix "Telnet attempt: " sudo iptables -A INPUT -p udp --dport 137:139 -j LOG --log-prefix "NetBIOS attempt: " sudo iptables -A INPUT -p tcp --dport 139 -j DROP sudo iptables -A INPUT -p tcp --dport 445 -j DROP -
保存iptables规则:
sudo iptables-save > /etc/iptables/rules.v4
使用firewalld进行基本的入侵检测
-
安装firewalld:
sudo yum install firewalld sudo systemctl start firewalld sudo systemctl enable firewalld -
设置默认区域:
sudo firewall-cmd --set-default-zone=public -
允许必要的流量:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --permanent --zone=public --add-service=ssh sudo firewall-cmd --reload -
添加入侵检测规则:
sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 21 -j LOG --log-prefix "FTP attempt: " sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 23 -j LOG --log-prefix "Telnet attempt: " sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p udp --dport 137:139 -j LOG --log-prefix "NetBIOS attempt: " sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 139 -j DROP sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p tcp --dport 445 -j DROP sudo firewall-cmd --reload
使用Snort进行高级入侵检测
-
安装Snort:
sudo yum install snort -
配置Snort: 编辑
/etc/snort/snort.conf文件,配置规则和其他选项。 -
启动Snort:
sudo systemctl start snort sudo systemctl enable snort -
查看Snort日志:
sudo tail -f /var/log/snort/alert
使用Suricata进行高级入侵检测
-
安装Suricata:
sudo yum install suricata -
配置Suricata: 编辑
/etc/suricata/suricata.yaml文件,配置规则和其他选项。 -
启动Suricata:
sudo systemctl start suricata sudo systemctl enable suricata -
查看Suricata日志:
sudo tail -f /var/log/suricata/fast.log
通过以上步骤,你可以在Linux系统中配置基本的入侵检测。根据具体需求,你可以选择合适的工具并进行更详细的配置。