攻击者通常使用协议隧道和端口滥用作为规避技术来绕过安全控制。协议隧道涉及在知名端口上运行非标准协议,例如使用端口80运行SSH而非HTTP,以规避仅检查端口号的防火墙规则。同样,攻击者可能通过在非标准端口上运行合法协议来进行端口跳跃,以避免被专注于标准端口监控的安全工具检测。这些技术能够通过允许的端口使用看似合法流量的自定义协议进行数据泄露,或通过滥用受信任的端口和协议建立隐蔽的命令和控制通道。
通过强制执行严格的端口/协议对齐,我们可以确保端口80只能承载HTTP流量,端口443只能承载TLS/HTTPS流量,端口22只能承载SSH流量。这种双向执行创建了强大的安全态势,既能防止在标准端口上滥用协议,也能防止在非标准端口上使用协议。
接下来,让我们添加规则以强制在标准端口上正确使用协议:
返回 StatefulRuleGroup 并再次选择 Edit。
添加以下规则以强制正确使用协议:
# 端口80只能用于HTTP流量
drop tcp $HOME_NET any -> any 80 (msg:"Egress Port TCP/80 but not HTTP"; app-layer-protocol:!http; flow:to_server; sid:10000002;)
# 出站HTTP流量必须使用端口80
drop http $HOME_NET any -> any !80 (msg:"Egress HTTP but not port TCP/80"; flow:to_server; sid:10000003;)
# 端口443只能用于TLS流量
drop tcp $HOME_NET any -> any 443 (msg:"Egress Port TCP/443 but not TLS"; app-layer-protocol:!tls; flow:to_server; sid:10000004;)
# 出站TLS流量必须使用端口443
drop tls $HOME_NET any -> any !443 (msg:"Egress TLS but not port TCP/443"; flow:to_server; sid:10000005;)
# 端口22只能用于SSH流量
drop tcp $HOME_NET any -> any 22 (msg:"Egress Port TCP/22 but not SSH"; app-layer-protocol:!ssh; flow:to_server; sid:10000006;)
# 出站SSH流量必须使用端口22
drop ssh $HOME_NET any -> any !22 (msg:"Egress SSH but not port TCP/22"; flow:to_server; sid:10000007;)

有关这些防火墙规则的说明:
# 端口80只能用于HTTP流量
drop tcp $HOME_NET any -> any 80 (msg:"Egress Port TCP/80 but not HTTP"; app-layer-protocol:!http; flow:to_server; sid:10000002;)
app-layer-protocol:!http 关键字专门识别不符合HTTP协议模式的流量。这可以防止攻击者将端口80用于非HTTP流量,例如使用自定义协议的命令和控制通道或数据泄露。# 出站HTTP流量必须使用端口80
drop http $HOME_NET any -> any !80 (msg:"Egress HTTP but not port TCP/80"; flow:to_server; sid:10000003;)
!80 匹配除80以外的任何端口。这可以防止应用程序使用非标准端口进行HTTP流量,这是一种常见的规避技术,用于绕过仅关注标准端口的安全监控。# 端口443只能用于TLS流量
drop tcp $HOME_NET any -> any 443 (msg:"Egress Port TCP/443 but not TLS"; app-layer-protocol:!tls; flow:to_server; sid:10000004;)
# 出站TLS流量必须使用端口443
drop tls $HOME_NET any -> any !443 (msg:"Egress TLS but not port TCP/443"; flow:to_server; sid:10000005;)
# 端口22只能用于SSH流量
drop tcp $HOME_NET any -> any 22 (msg:"Egress Port TCP/22 but not SSH"; app-layer-protocol:!ssh; flow:to_server; sid:10000006;)
# 出站SSH流量必须使用端口22
drop ssh $HOME_NET any -> any !22 (msg:"Egress SSH but not port TCP/22"; flow:to_server; sid:10000007;)
