Windows下使用powershell修改防火墙

发布时间 2023-06-27 15:35:49作者: Garenliu

Windows下使用powershell修改防火墙

前两天,领导给了我一个漏扫报告,让我看着弄,其中上图这一条是花了一点时间的,做一个记录。

以下是原文

6、允许Traceroute探测
整改建议:在防火墙出站规则中禁用echo-reply(type 0)、time-exceeded(type 11)、destination-unreachable(type 3)类型的ICMP包

当时看到的这个时候,想着很简单,看我firewall-cmd大法,分分钟拿下,后来发现是Windows系统下,然后有了以下语句,注意,使用管理员打开powershell,powershell版本是 5.1.14393.206,其余版本没有测试。

New-NetFirewallRule -DisplayName "Disable Outbound ICMP0" -Direction "Outbound" -Protocol "ICMPv4" -ICMPType 0 -Action "Block"
New-NetFirewallRule -DisplayName "Disable Outbound ICMP11" -Direction "Outbound" -Protocol "ICMPv4" -ICMPType 11 -Action "Block"
New-NetFirewallRule -DisplayName "Disable Outbound ICMP3" -Direction "Outbound" -Protocol "ICMPv4" -ICMPType 3 -Action "Block"

参考链接

https://learn.microsoft.com/en-us/powershell/module/netsecurity/new-netfirewallrule?view=winserver2012r2-ps&redirectedfrom=MSDN