-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAuditTenantSettings.ps1
158 lines (151 loc) · 8.28 KB
/
AuditTenantSettings.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
$clientID = Get-Secret 'SophosCentral-Partner-ClientID' -Vault AzKV -AsPlainText
$clientSecret = Get-Secret -Name 'SophosCentral-Partner-ClientSecret' -Vault AzKV
Connect-SophosCentral -ClientID $clientID -ClientSecret $clientSecret
$tenants = Get-SophosCentralCustomerTenant
<#
custom settings to audit, and their values to audit against
do not include settings that have a 'recommendedValue' returned by the API, as those will automatically be audited (this is mainly under threat-protection)
settings reference: https://developer.sophos.com/endpoint-policy-settings-all
#>
$types = @{
'agent-updating' = @{
Enabled = $true
}
'threat-protection' = @{
Enabled = 'True'
'endpoint.threat-protection.web-control.tls-decryption.enabled' = 'True'
'endpoint.threat-protection.malware-protection.scheduled-scan.enabled' = 'True'
'endpoint.threat-protection.malware-protection.scheduled-scan.scan-all-files.enabled' = 'True'
'endpoint.threat-protection.malware-protection.scheduled-scan.deep-scanning.enabled' = 'True'
'endpoint.threat-protection.network-protection.self-isolation.enabled' = 'True'
'endpoint.threat-protection.malware-protection.deep-learning.detection-level' = 'default'
}
'web-control' = @{
Enabled = 'True'
'endpoint.web-control.enabled' = 'True'
'endpoint.web-control.web-monitoring.enabled' = 'yes'
'endpoint.web-control.categories.9.action' = 'block' #criminal
'endpoint.web-control.categories.37.action' = 'block' #proxy and translators
'endpoint.web-control.categories.31.action' = 'block' #p2p
'endpoint.web-control.categories.2.action' = 'block' #ads
'endpoint.web-control.categories.19.action' = 'block' #hacking
'endpoint.web-control.categories.1.action' = 'block' #adult
'endpoint.web-control.categories.0.action' = 'warn' #uncategorized
}
'server-agent-updating' = @{
Enabled = $true
}
'server-file-integrity-monitoring' = @{
Enabled = $true
}
'server-lockdown' = @{
Enabled = $true
}
'server-threat-protection' = @{
Enabled = $true
'endpoint.threat-protection.web-control.tls-decryption.enabled' = 'True'
'endpoint.threat-protection.malware-protection.scheduled-scan.enabled' = 'True'
'endpoint.threat-protection.malware-protection.scheduled-scan.scan-all-files.enabled' = 'True'
'endpoint.threat-protection.malware-protection.scheduled-scan.deep-scanning.enabled' = 'True'
'endpoint.threat-protection.network-protection.self-isolation.enabled' = 'True'
'endpoint.threat-protection.malware-protection.file-reputation.reputation-level' = 'recommended'
'endpoint.threat-protection.malware-protection.deep-learning.detection-level' = 'default'
'endpoint.threat-protection.journal-hashing.exclude-remote-files.enabled' = 'False'
'endpoint.threat-protection.exploit-mitigation.cpu-branch-tracing.enabled' = 'True'
}
'server-web-control' = @{
Enabled = $true
'endpoint.web-control.web-filtering.enabled' = 'True'
'endpoint.web-control.web-monitoring.enabled' = 'yes'
'endpoint.web-control.categories.9.action' = 'block' #criminal
'endpoint.web-control.categories.37.action' = 'block' #proxy and translators
'endpoint.web-control.categories.2.action' = 'block' #ads
'endpoint.web-control.categories.19.action' = 'block' #hacking
'endpoint.web-control.categories.1.action' = 'block' #adult
}
'server-windows-firewall' = @{
'endpoint.windows-firewall.profiles.domain-networks' = 'block'
'endpoint.windows-firewall.monitoring-only.enabled' = 'false'
'endpoint.windows-firewall.profiles.private-networks' = 'block'
'endpoint.windows-firewall.profiles.public-networks' = 'blockall'
}
'windows-firewall' = @{
'endpoint.windows-firewall.profiles.domain-networks' = 'block'
'endpoint.windows-firewall.monitoring-only.enabled' = 'false'
'endpoint.windows-firewall.profiles.private-networks' = 'block'
'endpoint.windows-firewall.profiles.public-networks' = 'blockall'
}
}
$results = foreach ($tenant in $tenants) {
$connectionSuccessful = $true
try {
Connect-SophosCentralCustomerTenant -CustomerTenantID $tenant.id
} catch {
$connectionSuccessful = $false
}
if ($connectionSuccessful -eq $true) {
$policies = Get-SophosCentralEndpointPolicy -All
foreach ($type in $types.Keys) {
$typePolicies = $policies | Where-Object { $_.type -eq $type }
$typeProps = $types[$type]
foreach ($prop in $typeProps.Keys) {
if ($prop -notlike '*.*') {
#audit top level settings on the policy, such as '$typePolicy.enabled'
foreach ($typePolicy in $typePolicies) {
if ($typePolicy."$prop" -ne $typeProps[$prop]) {
$result = [PSCustomObject]@{
ID = $typePolicy.id
Name = $typePolicy.name
Type = $typePolicy.type
TenantID = $typePolicy.tenant.id
TenantName = $tenant.name
Property = $prop
Value = $typePolicy."$prop"
}
$result
}
}
} else {
#audit settings under 'settings'. such as '$typePolicy.settings.endpoint.threat-protection.web-control.tls-decryption.enabled'
foreach ($typePolicy in $typePolicies) {
if ($typePolicy.settings."$prop".value -ne $typeProps[$prop]) {
$result = [PSCustomObject]@{
ID = $typePolicy.id
Name = $typePolicy.name
Type = $typePolicy.type
TenantID = $typePolicy.tenant.id
TenantName = $tenant.name
Property = $prop
Value = $typePolicy.settings."$prop".value
}
$result
}
}
}
}
#audit settings with a recommendedValue provided by the API
foreach ($typePolicy in $typePolicies) {
foreach ($setting in ($typePolicy.settings | Get-Member | Where-Object { $_.MemberType -eq 'NoteProperty' }).Name) {
if ($typePolicy.settings."$setting".recommendedValue) {
if ($typePolicy.settings."$setting".recommendedValue -ne $typePolicy.settings."$setting".value) {
$result = [PSCustomObject]@{
ID = $typePolicy.id
Name = $typePolicy.name
Type = $typePolicy.type
TenantID = $typePolicy.tenant.id
TenantName = $tenant.name
Property = $setting
Value = $typePolicy.settings."$setting".value
}
$result
}
}
}
}
}
}
}
#export to csv and open in default app
$filePath = "$($env:LOCALAPPDATA)\temp\$((New-Guid).guid).csv"
$results | Export-Csv -Path $filePath -NoTypeInformation
Start-Process $filePath