Suricata & Iptables cheatsheet
Iptables
链
在 iptables 中,规则列表被称为链,按顺序处理。其中,有三个主要链是普遍存在的,还有像 NAT 这样的其他链可能会根据系统的能力而得到支持。
Input 链:用于管理传入连接的行为。
Forward 链:用于处理不是发送到本地系统的传入连接。这对于充当路由器的设备是典型的,其中接收到的数据应转发到另一个目的地。当系统涉及路由、NAT 或类似活动时,此链主要相关。
Output 链:专用于调节传出连接。
这些链确保网络流量的有序处理,允许指定详细规则来管理数据进入、通过和离开系统的流动。
# Delete all rules
iptables -F
# List all rules
iptables -L
iptables -S
# Block IP addresses & ports
iptables -I INPUT -s ip1,ip2,ip3 -j DROP
iptables -I INPUT -p tcp --dport 443 -j DROP
iptables -I INPUT -s ip1,ip2 -p tcp --dport 443 -j DROP
# String based drop
## Strings are case sensitive (pretty easy to bypass if you want to check an SQLi for example)
iptables -I INPUT -p tcp --dport <port_listening> -m string --algo bm --string '<payload>' -j DROP
iptables -I OUTPUT -p tcp --sport <port_listening> -m string --algo bm --string 'CTF{' -j DROP
## You can also check for the hex, base64 and double base64 of the expected CTF flag chars
# Drop every input port except some
iptables -P INPUT DROP # Default to drop
iptables -I INPUT -p tcp --dport 8000 -j ACCEPT
iptables -I INPUT -p tcp --dport 443 -j ACCEPT
# Persist Iptables
## Debian/Ubuntu:
apt-get install iptables-persistent
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
iptables-restore < /etc/iptables/rules.v4
##RHEL/CentOS:
iptables-save > /etc/sysconfig/iptables
ip6tables-save > /etc/sysconfig/ip6tables
iptables-restore < /etc/sysconfig/iptablesSuricata
安装与配置
规则定义
来自文档: 一个规则/签名由以下部分组成:
动作,确定规则匹配时会发生什么。
头部,定义规则的协议、IP地址、端口和方向。
规则选项,定义规则的具体内容。
有效操作包括
alert - 生成警报
pass - 停止对数据包的进一步检查
drop - 丢弃数据包并生成警报
reject - 向匹配数据包的发送方发送RST/ICMP不可达错误。
rejectsrc - 与 reject 相同
rejectdst - 向匹配数据包的接收方发送RST/ICMP错误数据包。
rejectboth - 向对话的双方发送RST/ICMP错误数据包。
协议
tcp(用于tcp流量)
udp
icmp
ip(ip代表‘all’或‘any’)
layer7协议: http, ftp, tls, smb, dns, ssh...(更多内容请参阅文档)
源地址和目标地址
支持IP范围、否定和地址列表:
! 1.1.1.1
除了1.1.1.1之外的所有IP地址
![1.1.1.1, 1.1.1.2]
除了1.1.1.1和1.1.1.2之外的所有IP地址
$HOME_NET
您在yaml中设置的HOME_NET
[$EXTERNAL_NET, !$HOME_NET]
EXTERNAL_NET而不是HOME_NET
[10.0.0.0/24, !10.0.0.5]
10.0.0.0/24,但不包括10.0.0.5
源端口和目标端口
支持端口范围、否定和端口列表
any
任何地址
[80, 81, 82]
端口80、81和82
[80: 82]
从80到82的范围
[1024: ]
从1024到最高端口号
!80
除了80之外的所有端口
[80:100,!99]
从80到100的范围,但排除99
[1:80,![2,4]]
从1到80的范围,但排除端口2和4
方向
可以指示应用通信规则的方向:
关键词
在Suricata中有数百个选项可用于搜索您正在寻找的特定数据包,如果发现有趣的内容,将在此处提及。查看文档获取更多信息!
最后更新于