Firewall updates

This commit is contained in:
Przemyslaw Klys
2021-02-11 12:15:27 +01:00
parent d0a678353f
commit efbd2b12de
5 changed files with 345 additions and 103 deletions
+14 -103
View File
@@ -15,33 +15,10 @@
Count = 0
Settings = $null
}
[Array] $CreateGPO['Settings'] = foreach ($Rule in $GPO.DataSet) {
[Array] $CreateGPO['Settings'] = foreach ($Policy in $GPO.DataSet) {
[PSCustomObject] @{
Version = $Rule.Version
Type = if ($Rule.Dir -eq 'In') { 'Inbound' } elseif ($Rule.Dir -eq 'Out') { 'Outbound' } else { $Rule.Dir }
Name = $Rule.Name
Action = $Rule.Action
Enabled = if ($Rule.Active -eq 'true') { $true } else { $false }
Profile = $Rule.Profile
Svc = $Rule.Svc
LocalAddressIPv4 = $Rule.LA4
LocalAddressIPv6 = $Rule.LA6
RemoteAddressIPV4 = $Rule.RA4
RemoteAddressIPV6 = $Rule.RA6
LocalPort = $Rule.LPort
RemotePort = $Rule.RPort
Description = $Rule.Desc
EmbedCtxt = $Rule.EmbedCtxt
Edge = $Rule.Edge
IFType = $Rule.IFType
Security = $Rule.Security
App = $Rule.App
Protocol = $Rule.Protocol
RMAuth = $Rule.RMAuth
RUAuth = $Rule.RUAuth
ICMP4 = $Rule.ICMP4
LocalName = $Rule.LocalName
Name = $Policy.LocalName
Version = $Policy.PolicyVersion.Value
}
}
$CreateGPO['Count'] = $CreateGPO['Settings'].Count
@@ -50,84 +27,18 @@
$CreateGPO['Links'] = $GPO.Links
[PSCustomObject] $CreateGPO
} else {
foreach ($Rule in $GPO.DataSet) {
foreach ($Policy in $GPO.DataSet) {
[PSCustomObject]@{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
Version = $Rule.Version
Type = if ($Rule.Dir -eq 'In') { 'Inbound' } elseif ($Rule.Dir -eq 'Out') { 'Outbound' } else { $Rule.Dir }
Name = $Rule.Name
Action = $Rule.Action
Enabled = if ($Rule.Active -eq 'true') { $true } else { $false }
Profile = $Rule.Profile
Svc = $Rule.Svc
LocalAddressIPv4 = $Rule.LA4
LocalAddressIPv6 = $Rule.LA6
RemoteAddressIPV4 = $Rule.RA4
RemoteAddressIPV6 = $Rule.RA6
LocalPort = $Rule.LPort
RemotePort = $Rule.RPort
Description = $Rule.Desc
EmbedCtxt = $Rule.EmbedCtxt
Edge = $Rule.Edge
IFType = $Rule.IFType
Security = $Rule.Security
App = $Rule.App
Protocol = $Rule.Protocol
RMAuth = $Rule.RMAuth
RUAuth = $Rule.RUAuth
ICMP4 = $Rule.ICMP4
LocalName = $Rule.LocalName
Linked = $GPO.Linked
LinksCount = $GPO.LinksCount
Links = $GPO.Links
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
Name = $Policy.LocalName
Version = $Policy.PolicyVersion.Value
Linked = $GPO.Linked
LinksCount = $GPO.LinksCount
Links = $GPO.Links
}
}
}
}
<#
Version : 2.30
Action : Allow
Name : @%SystemRoot%\system32\firewallapi.dll,-37303
Dir : In
App : %SystemRoot%\system32\svchost.exe
Svc : dnscache
Profile : Public
RA4 : LocalSubnet
RA6 : LocalSubnet
LPort : 5353
Protocol : 17
Desc : @%SystemRoot%\system32\firewallapi.dll,-37304
Active : true
EmbedCtxt : @%SystemRoot%\system32\firewallapi.dll,-37302
Version : 2.30
Action : Allow
Name : TEST APP
Dir : In
App : C:\Test\exe.exe
Active : true
Version : 2.30
Action : Block
Name : Blo
Dir : Out
App : dfdff
Active : true
Version : 2.30
Action : Block
Name : @FirewallAPI.dll,-36012
Dir : Out
App : %SystemRoot%\system32\svchost.exe
Svc : Qwave
Profile : {Private, Public}
RPort : 2177
Protocol : 17
Desc : @FirewallAPI.dll,-36013
Active : true
EmbedCtxt : @FirewallAPI.dll,-36001
#>
}
@@ -0,0 +1,56 @@
function ConvertTo-XMLWindowsFirewallConnectionSecurityAuthentiation {
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[switch] $SingleObject
)
if ($SingleObject) {
$CreateGPO = [ordered]@{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
#GpoCategory = $GPOEntry.GpoCategory
#GpoSettings = $GPOEntry.GpoSettings
Count = 0
Settings = $null
}
[Array] $CreateGPO['Settings'] = foreach ($Connection in $GPO.DataSet) {
[PSCustomObject] @{
Name = $Connection.LocalName
Version = $Connection.Version
ConnectionGUID = $Connection.GUID
Method = $Connection.AuthenticationSuites.Method #: MachineCert
CAName = $Connection.AuthenticationSuites.CAName #: DC = xyz, DC = evotec, DC = ad, CN = ad-ADCS-CA
CertAccountMapping = if ($Connection.AuthenticationSuites.CertAccountMapping -eq 'true') { $true } elseif ($Connection.AuthenticationSuites.CertAccountMapping -eq 'false') { $false } else { $Connection.AuthenticationSuites.CertAccountMapping }
ExcludeCAName = if ($Connection.AuthenticationSuites.ExcludeCAName -eq 'true') { $true } elseif ($Connection.AuthenticationSuites.ExcludeCAName -eq 'false') { $false } else { $Connection.AuthenticationSuites.ExcludeCAName }
HealthCert = if ($Connection.AuthenticationSuites.HealthCert -eq 'true') { $true } elseif ($Connection.AuthenticationSuites.HealthCert -eq 'false') { $false } else { $Connection.AuthenticationSuites.HealthCert }
}
}
$CreateGPO['Count'] = $CreateGPO['Settings'].Count
$CreateGPO['Linked'] = $GPO.Linked
$CreateGPO['LinksCount'] = $GPO.LinksCount
$CreateGPO['Links'] = $GPO.Links
[PSCustomObject] $CreateGPO
} else {
foreach ($Connection in $GPO.DataSet) {
[PSCustomObject]@{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
Name = $Connection.LocalName
Version = $Connection.Version
ConnectionGUID = $Connection.GUID
Method = $Connection.AuthenticationSuites.Method #: MachineCert
CAName = $Connection.AuthenticationSuites.CAName #: DC = xyz, DC = evotec, DC = ad, CN = ad-ADCS-CA
CertAccountMapping = if ($Connection.AuthenticationSuites.CertAccountMapping -eq 'true') { $true } elseif ($Connection.AuthenticationSuites.CertAccountMapping -eq 'false') { $false } else { $Connection.AuthenticationSuites.CertAccountMapping }
ExcludeCAName = if ($Connection.AuthenticationSuites.ExcludeCAName -eq 'true') { $true } elseif ($Connection.AuthenticationSuites.ExcludeCAName -eq 'false') { $false } else { $Connection.AuthenticationSuites.ExcludeCAName }
HealthCert = if ($Connection.AuthenticationSuites.HealthCert -eq 'true') { $true } elseif ($Connection.AuthenticationSuites.HealthCert -eq 'false') { $false } else { $Connection.AuthenticationSuites.HealthCert }
Linked = $GPO.Linked
LinksCount = $GPO.LinksCount
Links = $GPO.Links
}
}
}
}
@@ -0,0 +1,66 @@
function ConvertTo-XMLWindowsFirewallProfile {
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[switch] $SingleObject
)
if ($SingleObject) {
$CreateGPO = [ordered]@{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
#GpoCategory = $GPOEntry.GpoCategory
#GpoSettings = $GPOEntry.GpoSettings
Count = 0
Settings = $null
}
[Array] $CreateGPO['Settings'] = foreach ($Profile in $GPO.DataSet) {
[PSCustomObject] @{
Profile = $Profile.LocalName
EnableFirewall = if ($Profile.EnableFirewall.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
AllowLocalIPsecPolicyMerge = if ($Profile.AllowLocalIPsecPolicyMerge.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
AllowLocalPolicyMerge = if ($Profile.AllowLocalPolicyMerge.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DefaultInboundAction = if ($Profile.DefaultInboundAction.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DefaultOutboundAction = if ($Profile.DefaultOutboundAction.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DisableNotifications = if ($Profile.DisableNotifications.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DisableUnicastResponsesToMulticastBroadcast = if ($Profile.DisableUnicastResponsesToMulticastBroadcast.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DoNotAllowExceptions = if ($Profile.DoNotAllowExceptions.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
LogFilePath = if ($Profile.LogFilePath.Value) { $Profile.LogFilePath.Value } else { 'Not configured' }
LogDroppedPackets = if ($Profile.LogDroppedPackets.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
LogFileSize = if ($Profile.LogFileSize.Value) { $Profile.LogFileSize.Value } else { 'Not configured' }
LogSuccessfulConnections = if ($Profile.LogSuccessfulConnections.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
}
}
$CreateGPO['Count'] = $CreateGPO['Settings'].Count
$CreateGPO['Linked'] = $GPO.Linked
$CreateGPO['LinksCount'] = $GPO.LinksCount
$CreateGPO['Links'] = $GPO.Links
[PSCustomObject] $CreateGPO
} else {
foreach ($Profile in $GPO.DataSet) {
[PSCustomObject]@{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
Profile = $Profile.LocalName
EnableFirewall = if ($Profile.EnableFirewall.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
AllowLocalIPsecPolicyMerge = if ($Profile.AllowLocalIPsecPolicyMerge.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
AllowLocalPolicyMerge = if ($Profile.AllowLocalPolicyMerge.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DefaultInboundAction = if ($Profile.DefaultInboundAction.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DefaultOutboundAction = if ($Profile.DefaultOutboundAction.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DisableNotifications = if ($Profile.DisableNotifications.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DisableUnicastResponsesToMulticastBroadcast = if ($Profile.DisableUnicastResponsesToMulticastBroadcast.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
DoNotAllowExceptions = if ($Profile.DoNotAllowExceptions.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
LogFilePath = if ($Profile.LogFilePath.Value) { $Profile.LogFilePath.Value } else { 'Not configured' }
LogDroppedPackets = if ($Profile.LogDroppedPackets.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
LogFileSize = if ($Profile.LogFileSize.Value) { $Profile.LogFileSize.Value } else { 'Not configured' }
LogSuccessfulConnections = if ($Profile.LogSuccessfulConnections.Value -eq 'true') { 'Yes' } elseif ($Profile.EnableFirewall.Value -eq 'false') { 'No' } else { 'Not configured' }
Linked = $GPO.Linked
LinksCount = $GPO.LinksCount
Links = $GPO.Links
}
}
}
}
@@ -0,0 +1,133 @@
function ConvertTo-XMLWindowsFirewallRules {
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[switch] $SingleObject
)
if ($SingleObject) {
$CreateGPO = [ordered]@{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
#GpoCategory = $GPOEntry.GpoCategory
#GpoSettings = $GPOEntry.GpoSettings
Count = 0
Settings = $null
}
[Array] $CreateGPO['Settings'] = foreach ($Rule in $GPO.DataSet) {
[PSCustomObject] @{
Version = $Rule.Version
Type = if ($Rule.Dir -eq 'In') { 'Inbound' } elseif ($Rule.Dir -eq 'Out') { 'Outbound' } else { $Rule.Dir }
Name = $Rule.Name
Action = $Rule.Action
Enabled = if ($Rule.Active -eq 'true') { $true } else { $false }
Profile = $Rule.Profile
Svc = $Rule.Svc
LocalAddressIPv4 = $Rule.LA4
LocalAddressIPv6 = $Rule.LA6
RemoteAddressIPV4 = $Rule.RA4
RemoteAddressIPV6 = $Rule.RA6
LocalPort = $Rule.LPort
RemotePort = $Rule.RPort
Description = $Rule.Desc
EmbedCtxt = $Rule.EmbedCtxt
Edge = $Rule.Edge
IFType = $Rule.IFType
Security = $Rule.Security
App = $Rule.App
Protocol = $Rule.Protocol
RMAuth = $Rule.RMAuth
RUAuth = $Rule.RUAuth
ICMP4 = $Rule.ICMP4
LocalName = $Rule.LocalName
}
}
$CreateGPO['Count'] = $CreateGPO['Settings'].Count
$CreateGPO['Linked'] = $GPO.Linked
$CreateGPO['LinksCount'] = $GPO.LinksCount
$CreateGPO['Links'] = $GPO.Links
[PSCustomObject] $CreateGPO
} else {
foreach ($Rule in $GPO.DataSet) {
[PSCustomObject]@{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
Version = $Rule.Version
Type = if ($Rule.Dir -eq 'In') { 'Inbound' } elseif ($Rule.Dir -eq 'Out') { 'Outbound' } else { $Rule.Dir }
Name = $Rule.Name
Action = $Rule.Action
Enabled = if ($Rule.Active -eq 'true') { $true } else { $false }
Profile = $Rule.Profile
Svc = $Rule.Svc
LocalAddressIPv4 = $Rule.LA4
LocalAddressIPv6 = $Rule.LA6
RemoteAddressIPV4 = $Rule.RA4
RemoteAddressIPV6 = $Rule.RA6
LocalPort = $Rule.LPort
RemotePort = $Rule.RPort
Description = $Rule.Desc
EmbedCtxt = $Rule.EmbedCtxt
Edge = $Rule.Edge
IFType = $Rule.IFType
Security = $Rule.Security
App = $Rule.App
Protocol = $Rule.Protocol
RMAuth = $Rule.RMAuth
RUAuth = $Rule.RUAuth
ICMP4 = $Rule.ICMP4
LocalName = $Rule.LocalName
Linked = $GPO.Linked
LinksCount = $GPO.LinksCount
Links = $GPO.Links
}
}
}
}
<#
Version : 2.30
Action : Allow
Name : @%SystemRoot%\system32\firewallapi.dll,-37303
Dir : In
App : %SystemRoot%\system32\svchost.exe
Svc : dnscache
Profile : Public
RA4 : LocalSubnet
RA6 : LocalSubnet
LPort : 5353
Protocol : 17
Desc : @%SystemRoot%\system32\firewallapi.dll,-37304
Active : true
EmbedCtxt : @%SystemRoot%\system32\firewallapi.dll,-37302
Version : 2.30
Action : Allow
Name : TEST APP
Dir : In
App : C:\Test\exe.exe
Active : true
Version : 2.30
Action : Block
Name : Blo
Dir : Out
App : dfdff
Active : true
Version : 2.30
Action : Block
Name : @FirewallAPI.dll,-36012
Dir : Out
App : %SystemRoot%\system32\svchost.exe
Svc : Qwave
Profile : {Private, Public}
RPort : 2177
Protocol : 17
Desc : @FirewallAPI.dll,-36013
Active : true
EmbedCtxt : @FirewallAPI.dll,-36001
#>
@@ -0,0 +1,76 @@
function ConvertTo-XMLWindowsFirewallSecurityRules {
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[switch] $SingleObject
)
if ($SingleObject) {
$CreateGPO = [ordered]@{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
#GpoCategory = $GPOEntry.GpoCategory
#GpoSettings = $GPOEntry.GpoSettings
Count = 0
Settings = $null
}
[Array] $CreateGPO['Settings'] = foreach ($Rule in $GPO.DataSet) {
[PSCustomObject] @{
Version = $Rule.Version
Name = $Rule.Name
Action = $Rule.Action
Enabled = if ($Rule.Active -eq 'true') { $true } else { $false }
Auth1Set = $Rule.Auth1Set
Auth2Set = $Rule.Auth2Set
Crypto2Set = $Rule.Crypto2Set
Description = $Rule.Desc
}
}
$CreateGPO['Count'] = $CreateGPO['Settings'].Count
$CreateGPO['Linked'] = $GPO.Linked
$CreateGPO['LinksCount'] = $GPO.LinksCount
$CreateGPO['Links'] = $GPO.Links
[PSCustomObject] $CreateGPO
} else {
foreach ($Rule in $GPO.DataSet) {
[PSCustomObject]@{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.GUID
GpoType = $GPO.GpoType
Version = $Rule.Version
Name = $Rule.Name
Action = $Rule.Action
Enabled = if ($Rule.Active -eq 'true') { $true } else { $false }
Auth1Set = $Rule.Auth1Set
Auth2Set = $Rule.Auth2Set
Crypto2Set = $Rule.Crypto2Set
Description = $Rule.Desc
Linked = $GPO.Linked
LinksCount = $GPO.LinksCount
Links = $GPO.Links
}
}
}
}
<#
Version : 2.30
Action : Boundary
Name : TeST Aut
Auth1Set : {E5A5D32A-4BCE-4e4d-B07F-4AB1BA7E5FE3}
Auth2Set : {E5A5D32A-4BCE-4e4d-B07F-4AB1BA7E5FE4}
Crypto2Set : {E5A5D32A-4BCE-4e4d-B07F-4AB1BA7E5FE2}
Desc :
Active : true
Version : 2.30
Action : Boundary
Name : CA TEST
Auth1Set : {0E3A2DDC-F31B-42B5-BEAC-890752F9C0BB}
Auth2Set : EmptySet
Crypto2Set : {E5A5D32A-4BCE-4e4d-B07F-4AB1BA7E5FE2}
Desc :
Active : true
#>