Windows Defender具有高级安全管理的防火墙Windows PowerShell 您所在的位置:网站首页 sem_open未定义的引用 Windows Defender具有高级安全管理的防火墙Windows PowerShell

Windows Defender具有高级安全管理的防火墙Windows PowerShell

2023-06-04 15:10| 来源: 网络整理| 查看: 265

Windows Defender具有高级安全管理的防火墙Windows PowerShell 项目 05/25/2023 适用于: ✅ Windows 11, ✅ Windows 10, ✅ Windows Server 2022, ✅ Windows Server 2019, ✅ Windows Server 2016

Windows Defender防火墙与高级安全管理Windows PowerShell指南提供了用于自动Windows Defender防火墙管理的基本脚本。 它专为 IT 专业人员、系统管理员、IT 经理以及使用和需要在 Windows 中自动执行Windows Defender防火墙管理的其他人员而设计。

可以使用Windows PowerShell来管理防火墙和 IPsec 部署。 这种面向对象的脚本环境将使你比在 netsh 中更容易管理策略和监视网络条件。 Windows PowerShell允许通过每个 cmdlet 中的语法和参数自行发现网络设置。 本指南演示了如何在 netsh 中执行常见任务,以及如何使用 Windows PowerShell 来完成这些任务。

在 Windows 的未来版本中,Microsoft 可能会删除Windows Defender防火墙的 netsh 功能。 如果当前使用 netsh 配置和管理Windows Defender防火墙,Microsoft 建议转换为 Windows PowerShell。

Windows PowerShell和 netsh 命令引用位于以下位置。

适用于Windows Defender防火墙的 Netsh 命令 范围

本指南不教你Windows Defender防火墙的基础知识,可以在Windows Defender防火墙中找到。 它不教授Windows PowerShell的基础知识,它假定你熟悉Windows PowerShell语言和Windows PowerShell的基本概念。 有关Windows PowerShell概念和用法的详细信息,请参阅本指南的“其他资源”部分中的参考主题。

受众和用户要求

本指南面向 IT 专业人员、系统管理员和 IT 经理,假定你熟悉Windows Defender防火墙、Windows PowerShell语言和Windows PowerShell的基本概念。

本主题内容 部分 描述 设置配置文件全局默认值 启用和控制防火墙行为 部署基本防火墙规则 如何创建、修改和删除防火墙规则 远程管理 使用 远程管理 -CimSession 部署基本 IPsec 规则设置 IPsec 规则和关联的参数 使用 IPsec 部署安全防火墙规则 域和服务器隔离 其他资源 有关Windows PowerShell的详细信息 设置配置文件全局默认值

全局默认值基于每个配置文件设置设备行为。 Windows Defender防火墙支持域、专用和公共配置文件。

启用具有高级安全性的Windows Defender防火墙

Windows Defender防火墙会丢弃与允许的未经请求的流量不相对应的流量,或者为响应设备请求而发送的流量。 如果发现未强制实施所创建的规则,可能需要启用Windows Defender防火墙。 下面介绍如何在本地域设备上启用Windows Defender防火墙:

Netsh

netsh advfirewall set allprofiles state on

Windows PowerShell

Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True 使用高级安全行为控制Windows Defender防火墙

可以通过命令行接口定义全局默认设置。 这些修改也可通过具有高级安全性的Windows Defender防火墙控制台获得。

以下 scriptlet 设置默认的入站和出站操作,指定受保护的网络连接,并允许在阻止程序接收入站连接时向用户显示通知。 它允许对多播或广播网络流量进行单播响应,并指定用于故障排除的日志记录设置。

Netsh

netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound netsh advfirewall set allprofiles settings inboundusernotification enable netsh advfirewall set allprofiles settings unicastresponsetomulticast enable netsh advfirewall set allprofiles logging filename %SystemRoot%\System32\LogFiles\Firewall\pfirewall.log

Windows PowerShell

Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow –NotifyOnListen True -AllowUnicastResponseToMulticast True –LogFileName %SystemRoot%\System32\LogFiles\Firewall\pfirewall.log 禁用具有高级安全性的Windows Defender防火墙

Microsoft 建议不要禁用Windows Defender防火墙,因为你会失去该服务提供的其他好处,例如能够使用 Internet 协议安全 (IPsec) 连接安全规则、网络保护免受使用网络指纹、Windows 服务强化和启动时间筛选器的攻击。

禁用具有高级安全性的Windows Defender防火墙也可能导致问题,包括:

“开始”菜单可停止工作 新式应用程序可能无法安装或更新 通过手机激活 Windows 失败 依赖于Windows Defender防火墙的应用程序或 OS 不兼容

Microsoft 建议仅在安装第三方防火墙时禁用Windows Defender防火墙,并在禁用或删除第三方软件时将Windows Defender防火墙重置回默认值。

如果需要禁用Windows Defender防火墙,请不要通过在服务管理单元中停止Windows Defender防火墙服务 (来禁用它,显示名称Windows Defender防火墙,服务名称为 MpsSvc) 。 Microsoft 不支持停止Windows Defender防火墙服务。

非 Microsoft 防火墙软件只能以编程方式禁用需要禁用Windows Defender防火墙的部分以确保兼容性。 不应出于此目的自行禁用防火墙。

禁用Windows Defender防火墙的正确方法是禁用Windows Defender防火墙配置文件,使服务保持运行状态。

使用以下过程关闭防火墙,或禁用组策略设置计算机配置|管理模板 |网络|网络连接 |Windows Defender防火墙 |域 Prolfile |Windows Defender防火墙:保护所有网络连接。 有关详细信息,请参阅Windows Defender具有高级安全性的防火墙部署指南。

以下示例对所有配置文件禁用Windows Defender防火墙。

Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False 部署基本防火墙规则

本部分提供用于创建、修改和删除防火墙规则的 scriptlet 示例。

创建防火墙规则

在 Windows PowerShell 中添加防火墙规则看起来非常类似于 Netsh 中的防火墙规则,但参数和值的指定方式不同。

下面是如何允许 Telnet 应用程序在网络上侦听的示例。 此防火墙规则使用 关键字 (keyword) 而不是 IP 地址将范围限定为本地子网。 就像在 Netsh 中一样,规则是在本地设备上创建的,并且会立即生效。

Netsh

netsh advfirewall firewall add rule name="Allow Inbound Telnet" dir=in program= %SystemRoot%\System32\tlntsvr.exe remoteip=localsubnet action=allow

Windows PowerShell

New-NetFirewallRule -DisplayName “Allow Inbound Telnet” -Direction Inbound -Program %SystemRoot%\System32\tlntsvr.exe -RemoteAddress LocalSubnet -Action Allow

以下 scriptlet 演示如何添加一个基本的防火墙规则,该规则阻止从特定应用程序和本地端口到 Active Directory 中的 组策略 对象 (GPO) 的出站流量。 在 Windows PowerShell 中,策略存储被指定为 New-NetFirewall cmdlet 中的参数。 在 Netsh 中,必须首先指定 Netsh 会话中的命令应修改的 GPO。 输入的命令针对 GPO 的内容运行,执行将一直有效,直到 Netsh 会话结束或执行另一个 set store 命令为止。

此处,domain.contoso.com 是Active Directory 域服务 (AD DS) 的名称,gpo_name是要修改的 GPO 的名称。 如果 GPO 名称中有任何空格,则需要引号。

Netsh

netsh advfirewall set store gpo=domain.contoso.com\gpo_name netsh advfirewall firewall add rule name="Block Outbound Telnet" dir=out program=%SystemRoot%\System32\telnet.exe protocol=tcp localport=23 action=block

Windows PowerShell

New-NetFirewallRule -DisplayName “Block Outbound Telnet” -Direction Outbound -Program %SystemRoot%\System32\tlntsvr.exe –Protocol TCP –LocalPort 23 -Action Block –PolicyStore domain.contoso.com\gpo_name GPO 缓存

为了减轻繁忙的域控制器的负担,Windows PowerShell允许将 GPO 加载到本地会话,在该会话中进行所有更改,然后一次性保存。

以下命令通过向 GPO) 添加 Telnet 规则来执行与上一示例 (相同的操作,但我们通过在 PowerShell 中应用 GPO 缓存来执行此操作。 Netsh 不支持通过将 GPO 加载到本地会话并使用 -GPOSession 参数来更改 GPO

Windows PowerShell

$gpo = Open-NetGPO –PolicyStore domain.contoso.com\gpo_name New-NetFirewallRule -DisplayName “Block Outbound Telnet” -Direction Outbound -Program %SystemRoot%\System32\telnet.exe –Protocol TCP –LocalPort 23 -Action Block –GPOSession $gpo Save-NetGPO –GPOSession $gpo

此命令不会对单个更改进行批处理,它会同时加载并保存整个 GPO。 因此,如果其他管理员或在其他Windows PowerShell窗口中进行了任何其他更改,保存 GPO 将覆盖这些更改。

修改现有防火墙规则

创建规则时,Netsh 和 Windows PowerShell 允许更改规则属性和影响,但规则在 Windows PowerShell 中保留其唯一标识符 (,此标识符使用 -Name 参数) 指定。

例如,可以有一个规则 “允许 Web 80 ”为入站未经请求的流量启用 TCP 端口 80。 可以更改规则,以匹配 Web 服务器的其他远程 IP 地址,通过指定规则的用户可读的本地化名称来允许其流量。

Netsh

netsh advfirewall firewall set rule name="Allow Web 80" new remoteip=192.168.0.2

Windows PowerShell

Set-NetFirewallRule –DisplayName “Allow Web 80” -RemoteAddress 192.168.0.2

Netsh 要求你提供要更改的规则的名称,我们没有其他方法获取防火墙规则。 在Windows PowerShell中,可以使用规则的已知属性查询规则。

运行 Get-NetFirewallRule时,你可能会注意到地址和端口等常见条件未出现。 这些条件在名为 Filters 的单独对象中表示。 如前所述,可以在 New-NetFirewallRule 和 Set-NetFirewallRule 中设置所有条件。 如果要基于这些字段 (端口、地址、安全性、接口、服务) 查询防火墙规则,则需要自行获取筛选器对象。

可以更改 允许 Web 80 规则 (的远程终结点,就像之前使用筛选器对象) 一样。 使用 Windows PowerShell,使用端口筛选器按端口进行查询,然后假设存在影响本地端口的其他规则,则使用进一步的查询进行生成,直到检索到所需的规则。

在以下示例中,假设查询返回单个防火墙规则,然后利用Windows PowerShell的管道输入功能通过管道将规则传递给 Set-NetFirewallRule cmdlet。

Windows PowerShell

Get-NetFirewallPortFilter | ?{$_.LocalPort -eq 80} | Get-NetFirewallRule | ?{ $_.Direction –eq “Inbound” -and $_.Action –eq “Allow”} | Set-NetFirewallRule -RemoteAddress 192.168.0.2

还可以使用通配符查询规则。 以下示例返回与特定程序关联的防火墙规则数组。 可以在后续 Set-NetFirewallRule cmdlet 中修改数组的元素。

Windows PowerShell

Get-NetFirewallApplicationFilter -Program "*svchost*" | Get-NetFirewallRule

在 Set 命令中指定关联的组名称时,可以同时修改组中的多个规则。 可以将防火墙规则添加到指定的管理组,以便管理共享相同影响的多个规则。

在以下示例中,我们将入站和出站 Telnet 防火墙规则添加到 组 Telnet Management。 在 Windows PowerShell 中,首次创建规则时指定组成员身份,因此我们重新创建前面的示例规则。 在 Netsh 中无法向自定义规则组添加规则。

Windows PowerShell

New-NetFirewallRule -DisplayName “Allow Inbound Telnet” -Direction Inbound -Program %SystemRoot%\System32\tlntsvr.exe -RemoteAddress LocalSubnet -Action Allow –Group “Telnet Management” New-NetFirewallRule -DisplayName “Block Outbound Telnet” -Direction Outbound -Program %SystemRoot%\System32\tlntsvr.exe -RemoteAddress LocalSubnet -Action Allow –Group “Telnet Management”

如果在规则创建时未指定该组,则可以在Windows PowerShell中使用点表示法将该规则添加到规则组。 不能使用 Set-NetFirewallRule 指定组,因为 命令允许按规则组进行查询。

Windows PowerShell

$rule = Get-NetFirewallRule -DisplayName “Allow Inbound Telnet” $rule.Group = “Telnet Management” $rule | Set-NetFirewallRule

在 命令的帮助下 Set ,如果指定了规则组名称,则不会修改组成员身份,而是组的所有规则都会收到由给定参数指示的相同修改。

以下 scriptlet 在包含影响防火墙规则的远程管理的预定义组中启用所有规则。

Netsh

netsh advfirewall firewall set rule group="Windows Defender Firewall remote management" new enable=yes

Windows PowerShell

Set-NetFirewallRule -DisplayGroup “Windows Defender Firewall Remote Management” –Enabled True

还有一个单独的 Enable-NetFirewallRule cmdlet 用于按组或规则的其他属性启用规则。

Windows PowerShell

Enable-NetFirewallRule -DisplayGroup “Windows Defender Firewall Remote Management” -Verbose 删除防火墙规则

可以禁用规则对象,使其不再处于活动状态。 在 Windows PowerShell,Disable-NetFirewallRule cmdlet 会将规则保留在系统上,但将其置于禁用状态,以便不再应用规则并影响流量。 Enable-NetFirewallRule 可以重新启用已禁用的防火墙规则。 此 cmdlet 不同于 Remove-NetFirewallRule,后者从设备中永久删除规则定义。

以下 cmdlet 从本地策略存储中删除指定的现有防火墙规则。

Netsh

netsh advfirewall firewall delete rule name=“Allow Web 80”

Windows PowerShell

Remove-NetFirewallRule –DisplayName “Allow Web 80”

与其他 cmdlet 一样,还可以查询要删除的规则。 在这里,将从设备中删除所有阻止防火墙规则。

Windows PowerShell

Remove-NetFirewallRule –Action Block

使用 Get 命令查询规则并将其保存在变量中,观察要受影响的规则,然后通过管道将其传递给 Remove 命令,这可能更加安全,就像我们对 Set 命令所做的那样。 以下示例演示如何查看所有阻止防火墙规则,然后删除前四个规则。

Windows PowerShell

$x = Get-NetFirewallRule –Action Block $x $x[0-3] | Remove-NetFirewallRule 远程管理

默认情况下启用使用 WinRM 的远程管理。 支持 CimSession 参数的 cmdlet 使用 WinRM,默认情况下可以远程管理。

以下示例返回名为 RemoteDevice 的设备上的持久存储的所有防火墙规则。

Windows PowerShell

Get-NetFirewallRule –CimSession RemoteDevice

可以使用 –CimSession 参数在远程设备上执行任何修改或查看规则。 此处我们从远程设备中删除特定的防火墙规则。

Windows PowerShell

$RemoteSession = New-CimSession –ComputerName RemoteDevice Remove-NetFirewallRule –DisplayName “AllowWeb80” –CimSession $RemoteSession -Confirm 部署基本 IPsec 规则设置

Internet 协议安全 (IPsec) 策略由确定 IPsec 行为的规则组成。 IPsec 支持网络级对等身份验证、数据源身份验证、数据完整性、数据机密性 (加密) 和重播保护。

Windows PowerShell可以创建功能强大的复杂 IPsec 策略,例如 Netsh 和具有高级安全性的Windows Defender防火墙控制台。 但是,由于Windows PowerShell基于对象而不是基于字符串令牌,因此Windows PowerShell中的配置提供了更大的控制和灵活性。

在 Netsh 中,身份验证和加密集被指定为特定格式的逗号分隔令牌列表。 在Windows PowerShell中,你首先创建所需的身份验证或加密建议对象,并按首选顺序将它们捆绑到列表中,而不是使用默认设置。 然后,创建一个或多个引用这些集的 IPsec 规则。 此模型的优点是,以编程方式访问规则中的信息要容易得多。 有关阐明示例,请参阅以下部分。

创建 IPsec 规则

以下 cmdlet 在 组策略 对象中创建基本 IPsec 传输模式规则。 IPsec 规则易于创建;只需要显示名称,其余属性使用默认值。 入站流量使用默认快速模式和main模式设置进行身份验证并检查完整性。 可以在控制台的“自定义 IPsec 默认值”下找到这些默认设置。

Netsh

netsh advfirewall set store gpo=domain.contoso.com\gpo_name netsh advfirewall consec add rule name="Require Inbound Authentication" endpoint1=any endpoint2=any action=requireinrequestout

Windows PowerShell

New-NetIPsecRule -DisplayName “Require Inbound Authentication” -PolicyStore domain.contoso.com\gpo_name 向 IPsec 规则添加自定义身份验证方法

如果要在 IPsec 规则对象中创建一组同时包含 AH 和 ESP 的自定义快速模式建议,可以单独创建关联的对象并链接其关联。 有关身份验证方法的详细信息,请参阅 选择 IPsec 协议 。

然后,可以在创建 IPsec 规则时使用新创建的自定义快速模式策略。 加密集对象链接到 IPsec 规则对象。

在此示例中,我们通过指定自定义快速模式加密集来构建以前创建的 IPsec 规则。 最终的 IPsec 规则要求出站流量通过指定的加密方法进行身份验证。

Netsh

netsh advfirewall set store gpo=domain.contoso.com\gpo_name netsh advfirewall consec add rule name="Require Outbound Authentication" endpoint1=any endpoint2=any action=requireinrequestout qmsecmethods=ah:sha1+esp:sha1-3des

Windows PowerShell

$AHandESPQM = New-NetIPsecQuickModeCryptoProposal -Encapsulation AH,ESP –AHHash SHA1 -ESPHash SHA1 -Encryption DES3 $QMCryptoSet = New-NetIPsecQuickModeCryptoSet –DisplayName “ah:sha1+esp:sha1-des3” -Proposal $AHandESPQM –PolicyStore domain.contoso.com\gpo_name New-NetIPsecRule -DisplayName “Require Inbound Authentication” -InboundSecurity Require -OutboundSecurity Request -QuickModeCryptoSet $QMCryptoSet.Name –PolicyStore domain.contoso.com\gpo_name IKEv2 IPsec 传输规则

企业网络可能需要保护与其他机构的通信。 但是,你发现该机构运行非 Windows 操作系统,并需要使用 Internet 密钥交换版本 2 (IKEv2) 标准。

通过在 IPsec 规则中将 IKEv2 指定为关键模块,可以在 Windows Server 2012 中应用 IKEv2 功能。 此功能规范只能使用计算机证书身份验证完成,不能与阶段 2 身份验证一起使用。

Windows PowerShell

New-NetIPsecRule -DisplayName “Require Inbound Authentication” -InboundSecurity Require -OutboundSecurity Request –Phase1AuthSet MyCertAuthSet -KeyModule IKEv2 –RemoteAddress $nonWindowsGateway

有关 IKEv2 的详细信息(包括方案),请参阅 使用 IKEv2 保护端到端 IPsec 连接。

将 IPsec 规则从一个策略复制到另一个策略

可以复制具有相同规则属性的防火墙和 IPsec 规则,以简化在不同策略存储中重新创建它们的任务。

若要将以前创建的规则从一个策略存储复制到另一个策略存储区,还必须单独复制关联的对象。 无需复制关联的防火墙筛选器。 可以按与其他 cmdlet 相同的方式查询要复制的规则。

复制单个规则是无法通过 Netsh 接口完成的任务。 下面介绍如何使用 Windows PowerShell 完成此操作。

Windows PowerShell

$Rule = Get-NetIPsecRule –DisplayName “Require Inbound Authentication” $Rule | Copy-NetIPsecRule –NewPolicyStore domain.costoso.com\new_gpo_name $Rule | Copy-NetPhase1AuthSet –NewPolicyStore domain.costoso.com\new_gpo_name 处理Windows PowerShell错误

若要处理Windows PowerShell脚本中的错误,可以使用 –ErrorAction 参数。 此参数对于 Remove cmdlet 特别有用。 如果想要删除特定规则,你会注意到,如果找不到该规则,则它失败。 删除规则时,如果规则尚不存在,可以忽略该错误。 在这种情况下,可以执行以下操作,以禁止在删除操作期间出现任何“未找到规则”错误。

Windows PowerShell

Remove-NetFirewallRule –DisplayName “Contoso Messenger 98” –ErrorAction SilentlyContinue

使用通配符也可以禁止显示错误,但它们可能会匹配你不打算删除的规则。 这些通配符可能是一个有用的快捷方式,但仅当知道不会意外删除任何额外的规则时,才应使用。 因此,以下 cmdlet 还会删除该规则,从而禁止出现任何“未找到”错误。

Windows PowerShell

Remove-NetFirewallRule –DisplayName “Contoso Messenger 98*”

使用通配符时,如果要对匹配的规则集进行双重检查,可以使用 –WhatIf 参数。

Windows PowerShell

Remove-NetFirewallRule –DisplayName “Contoso Messenger 98*” –WhatIf

如果只想删除某些匹配的规则,可以使用 –Confirm 参数获取逐条规则确认提示。

Windows PowerShell

Remove-NetFirewallRule –DisplayName “Contoso Messenger 98*” –Confirm

还可以仅执行整个操作,在执行操作时显示每个规则的名称。

Windows PowerShell

Remove-NetFirewallRule –DisplayName “Contoso Messenger 98*” –Verbose 监视器

以下Windows PowerShell命令在部署阶段的更新周期中非常有用。

若要允许查看特定存储区中的所有 IPsec 规则,可以使用以下命令。 在 Netsh 中,此命令不显示 profile=domain,public 或 profile=domain,private 的规则。 它仅显示具有规则中包含的单个条目域的规则。 以下命令示例将显示所有配置文件中的 IPsec 规则。

Netsh

netsh advfirewall consec show rule name=all

Windows PowerShell

Show-NetIPsecRule –PolicyStore ActiveStore

可以监视main模式安全关联,了解哪些对等方当前已连接到设备,以及哪个保护套件用于形成安全关联。

使用以下 cmdlet 查看现有的main模式规则及其安全关联:

Netsh

netsh advfirewall monitor show mmsa all

Windows PowerShell

Get-NetIPsecMainModeSA 查找规则的源 GPO

若要查看特定规则或规则组的属性,请查询该规则。 当查询返回指定为 NotConfigured 的字段时,可以确定规则源自哪个策略存储。

对于来自 GPO (–PolicyStoreSourceType 参数在 Show 命令) 指定为 GroupPolicy,如果传递了 –TracePolicyStore,则会在 PolicyStoreSource 字段中找到并返回 GPO 的名称。

Windows PowerShell

Get-NetIPsecRule –DisplayName “Require Inbound Authentication” –TracePolicyStore

请务必注意,公开的源不包含域名。

部署基本域隔离策略

IPsec 可用于将域成员与非域成员隔离。 域隔离使用 IPsec 身份验证要求已加入域的设备积极建立通信设备的标识,以提高组织的安全性。 IPsec 的一个或多个功能可用于使用 IPsec 规则对象保护流量。

若要在网络上实现域隔离,域中的设备会收到 IPsec 规则,以阻止不受 IPsec 保护的未经请求的入站网络流量。 在这里,我们将创建一个 IPsec 规则,该规则要求域成员进行身份验证。 通过此身份验证,可以将已加入域的设备与未加入域的设备隔离开来。 在以下示例中,入站流量需要 Kerberos 身份验证,并请求对出站流量进行身份验证。

Netsh

netsh advfirewall set store gpo=domain.contoso.com\domain_isolation netsh advfirewall consec add rule name=“Basic Domain Isolation Policy” profile=domain endpoint1=”any” endpoint2=”any” action=requireinrequestout auth1=”computerkerb”

Windows PowerShell

$kerbprop = New-NetIPsecAuthProposal –Machine –Kerberos $Phase1AuthSet = New-NetIPsecPhase1AuthSet -DisplayName "Kerberos Auth Phase1" -Proposal $kerbprop –PolicyStore domain.contoso.com\domain_isolation New-NetIPsecRule –DisplayName “Basic Domain Isolation Policy” –Profile Domain –Phase1AuthSet $Phase1AuthSet.Name –InboundSecurity Require –OutboundSecurity Request –PolicyStore domain.contoso.com\domain_isolation 配置 IPsec 隧道模式

以下命令创建一个 IPsec 隧道,该隧道通过本地设备上的接口 (192.168.0.0/16) 路由来自专用网络的流量 (1.1.1 (1.1.1) ) 通过公共接口 (2.2.2.2) 连接到另一个专用网络, (192.157.0.0/16) 连接到另一个设备的公共网络。 使用 ESP/SHA1 检查通过隧道的所有流量的完整性,并使用 ESP/DES3 对其进行加密。

Netsh

netsh advfirewall consec add rule name="Tunnel from 192.168.0.0/16 to 192.157.0.0/16" mode=tunnel endpoint1=192.168.0.0/16 endpoint2=192.157.0.0/16 localtunnelendpoint=1.1.1.1 remotetunnelendpoint=2.2.2.2 action=requireinrequireout qmsecmethods=esp:sha1-3des

Windows PowerShell

$QMProposal = New-NetIPsecQuickModeCryptoProposal -Encapsulation ESP -ESPHash SHA1 -Encryption DES3 $QMCryptoSet = New-NetIPsecQuickModeCryptoSet –DisplayName “esp:sha1-des3” -Proposal $QMProposal New-NetIPSecRule -DisplayName “Tunnel from HQ to Dallas Branch” -Mode Tunnel -LocalAddress 192.168.0.0/16 -RemoteAddress 192.157.0.0/16 -LocalTunnelEndpoint 1.1.1.1 -RemoteTunnelEndpoint 2.2.2.2 -InboundSecurity Require -OutboundSecurity Require -QuickModeCryptoSet $QMCryptoSet.Name 使用 IPsec 部署安全防火墙规则

在仅允许安全流量通过Windows Defender防火墙的情况下,需要结合使用手动配置的防火墙和 IPsec 规则。 防火墙规则确定允许的数据包的安全级别,基础 IPsec 规则保护流量。 这些方案可以在 Windows PowerShell 和 Netsh 中完成,在部署方面有许多相似之处。

如果安全) , (允许创建安全防火墙规则

配置防火墙规则以允许连接(如果连接是安全的)需要对相应的流量进行身份验证和完整性保护,然后选择性地由 IPsec 加密。

以下示例创建要求对流量进行身份验证的防火墙规则。 仅当使用单独的 IPsec 规则对来自远程设备的连接进行身份验证时,命令才允许入站 Telnet 网络流量。

Netsh

netsh advfirewall firewall add rule name="Allow Authenticated Telnet" dir=in program=%SystemRoot%\System32\tlntsvr.exe security=authenticate action=allow

Windows PowerShell

New-NetFirewallRule -DisplayName “Allow Authenticated Telnet” -Direction Inbound -Program %SystemRoot%\System32\tlntsvr.exe -Authentication Required -Action Allow

以下命令创建一个 IPsec 规则,该规则要求第一个 (计算机) 身份验证,然后尝试第二个可选的 (用户) 身份验证。 创建此规则可保护流量,并允许流量通过信使程序的防火墙规则要求。

Netsh

netsh advfirewall consec add rule name="Authenticate Both Computer and User" endpoint1=any endpoint2=any action=requireinrequireout auth1=computerkerb,computerntlm auth2=userkerb,userntlm,anonymous

Windows PowerShell

$mkerbauthprop = New-NetIPsecAuthProposal -Machine –Kerberos $mntlmauthprop = New-NetIPsecAuthProposal -Machine -NTLM $P1Auth = New-NetIPsecPhase1AuthSet -DisplayName “Machine Auth” –Proposal $mkerbauthprop,$mntlmauthprop $ukerbauthprop = New-NetIPsecAuthProposal -User -Kerberos $unentlmauthprop = New-NetIPsecAuthProposal -User -NTLM $anonyauthprop = New-NetIPsecAuthProposal -Anonymous $P2Auth = New-NetIPsecPhase2AuthSet -DisplayName “User Auth” -Proposal $ukerbauthprop,$unentlmauthprop,$anonyauthprop New-NetIPSecRule -DisplayName “Authenticate Both Computer and User” -InboundSecurity Require -OutboundSecurity Require -Phase1AuthSet $P1Auth.Name –Phase2AuthSet $P2Auth.Name 通过要求加密和组成员身份来隔离服务器

若要提高组织中设备的安全性,可以部署限制域成员的域隔离。 它们要求在相互通信时进行身份验证,并拒绝未经身份验证的入站连接。 若要提高具有敏感数据的服务器的安全性,必须通过仅允许访问企业域中的一部分设备来保护此数据。

IPsec 可以通过隔离服务器来提供此额外的保护层。 在服务器隔离中,敏感数据访问仅限于具有合法业务需求的用户和设备,并且数据会额外加密以防止窃听。

创建需要组成员身份和加密的防火墙规则

为了部署服务器隔离,我们分层了一个防火墙规则,该规则将流量限制到强制身份验证的 IPsec 规则上的授权用户或设备。

以下防火墙规则允许来自名为“已授权访问服务器”的自定义组成员的用户帐户的 Telnet 流量。 此外,还可以通过指定限制参数,根据设备、用户或两者来限制此访问。

通过将用户或组的安全标识符扩展 (SID) 来创建安全描述符定义语言 (SDDL) 字符串。 有关查找组的 SID 的详细信息,请参阅: 查找组帐户的 SID。

通过限制对组的访问,管理部门可以通过Windows Defender防火墙和/或 IPsec 策略来扩展强身份验证支持。

以下示例演示如何创建表示安全组的 SDDL 字符串。

Windows PowerShell

$user = new-object System.Security.Principal.NTAccount (“corp.contoso.com\Administrators”) $SIDofSecureUserGroup = $user.Translate([System.Security.Principal.SecurityIdentifier]).Value $secureUserGroup = "D:(A;;CC;;;$SIDofSecureUserGroup)"

通过使用前面的 scriptlet,还可以获取安全计算机组的 SDDL 字符串,如下所示:

Windows PowerShell

$secureMachineGroup = "D:(A;;CC;;;$SIDofSecureMachineGroup)"

有关如何创建安全组或如何确定 SDDL 字符串的详细信息,请参阅 使用 SID。

Telnet 是一个不提供加密的应用程序。 此应用程序可以通过网络发送数据,例如名称和密码。 恶意用户可能会截获此数据。 如果管理员希望允许使用 Telnet,但要保护流量,则可以创建需要 IPsec 加密的防火墙规则。 此防火墙规则是必需的,以便管理员能够确保使用此应用程序时,此端口发送或接收的所有流量都已加密。 如果 IPsec 未能授权连接,则不允许来自此应用程序的流量。

在此示例中,通过创建以下防火墙规则,仅允许来自指定安全用户组的经过身份验证和加密的入站 Telnet 流量。

Netsh

netsh advfirewall set store gpo=domain.contoso.com\Server_Isolation netsh advfirewall firewall add rule name=“Allow Encrypted Inbound Telnet to Group Members Only” program=%SystemRoot%\System32\tlntsvr.exe protocol=TCP dir=in action=allow localport=23 security=authenc rmtusrgrp ="D:(A;;CC;;; S-1-5-21-2329867823-2610410949-1491576313-1735)"

Windows PowerShell

New-NetFirewallRule -DisplayName "Allow Encrypted Inbound Telnet to Group Members Only" -Program %SystemRoot%\System32\tlntsvr.exe -Protocol TCP -Direction Inbound -Action Allow -LocalPort 23 -Authentication Required -Encryption Required –RemoteUser $secureUserGroup –PolicyStore domain.contoso.com\Server_Isolation 终结点安全强制实施

上一个示例演示了特定应用程序的端到端安全性。 如果许多应用程序需要终结点安全性,则每个应用程序都有防火墙规则可能很麻烦且难以管理。 授权可以重写每个规则的基础,并在 IPsec 层完成。

在此示例中,我们将全局 IPsec 设置设置为仅允许传输模式流量来自具有以下 cmdlet 的授权用户组。 请参阅前面的示例以使用安全组。

Windows PowerShell

Set-NetFirewallSetting -RemoteMachineTransportAuthorizationList $secureMachineGroup 创建防火墙规则,允许受 IPsec 保护的网络流量 (经过身份验证的旁路)

经过身份验证的旁路允许来自指定受信任设备或用户的流量替代防火墙阻止规则。 当管理员想要使用扫描服务器来监视和更新设备而无需使用端口级异常时,此替代非常有用。 有关详细信息,请参阅 如何启用经过身份验证的防火墙绕过。

在此示例中,假定存在阻止防火墙规则。 此示例允许来自任何 IP 地址的任何端口上的任何网络流量覆盖阻止规则(如果流量被验证为源自指定设备或用户安全组的成员的设备或用户帐户)。

Netsh

netsh advfirewall set store gpo=domain.contoso.com\domain_isolation netsh advfirewall firewall add rule name="Inbound Secure Bypass Rule" dir=in security=authenticate action="bypass" rmtcomputergrp="D:(A;;CC;;;S-1-5-21-2329867823-2610410949-1491576313-1114)" rmtusrgrp="D:(A;;CC;;; S-1-5-21-2329867823-2610410949-1491576313-1735)"

Windows PowerShell

New-NetFirewallRule –DisplayName “Inbound Secure Bypass Rule" –Direction Inbound –Authentication Required –OverrideBlockRules $true -RemoteMachine $secureMachineGroup –RemoteUser $secureUserGroup –PolicyStore domain.contoso.com\domain_isolation 其他资源

有关Windows PowerShell概念的详细信息,请参阅以下主题。

Windows PowerShell 入门指南

Windows PowerShell用户指南

关于帮助主题的Windows PowerShell

about_Functions

about_Functions_Advanced

about_Execution_Policies

about_Foreach

about_Objects

about_Properties

about_While

about_Scripts

about_Signing

about_Throw

about_PSSessions

about_Modules

about_Command_Precedence

 

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有