This repository has been archived by the owner on Feb 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ApplySQLSTIGs.ps1
105 lines (63 loc) · 3.09 KB
/
ApplySQLSTIGs.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
# Host name of the SQL Server to be STIGed #
$hostname = "SQLServerHostName"
# Instance name of the SQL Server to be STIGed #
# If the default instance, set equal to MSSQLSERVER #
$instanceName = "MSSQLSERVER"
# Number of max connections for V-41422 #
$maxConnections = 3000
# New name of SA account #
$newName = "SharePointSA"
# Trace audit file variables #
# The folder must already exist or else SQL Server will throw an error creating the trace #
$traceFile = "'H:\STIG\STIG_Trace'"
$maxFileSize = 500
$fileCount = 10
# Location where STIG Scripts copied #
$folderRoot = "C:\STIG_Scripts\"
$ConfigureAuditingScript = "C:\STIG_Scripts\SQL\ConfigureAuditing.sql"
if ($instanceName -EQ "MSSQLSERVER") {
$sqlServerName = $hostname
}
else {
$sqlServerName = Join-Path -Path $hostname -ChildPath $instanceName
}
# Load SQL 2012 Module #
Import-Module sqlps -DisableNameChecking
# Load permissions functions #
Write-Output "`n----- Importing permissions functions -----"
. (Join-Path $folderRoot "SQL\Database\V-41422.ps1")
. (Join-Path $folderRoot "SQL\Instance\V-40936.ps1")
. (Join-Path $folderRoot "SQL\Instance\V-40944.ps1")
. (Join-Path $folderRoot "SQL\Instance\V-40950.ps1")
. (Join-Path $folderRoot "SQL\Instance\V-41037.ps1")
. (Join-Path $folderRoot "SQL\Instance\V-54589.ps1")
. (Join-Path $folderRoot "SQL\RevokePermissions.ps1")
. (Join-Path $folderRoot "SQL\ConfigureAuditing.ps1")
. (Join-Path $folderRoot "SQL\HardenAuditing.ps1")
. (Join-Path $folderRoot "SQL\SSL\GenerateCSR.ps1")
# Call functions to apply SQL 2012 STIGs #
Write-Output "`n----- Applying STIGs for SQL 2012 -----"
Write-Output "`n----- Applying V-41422 for SQL 2012 Database -----"
Set-MaxConnections $sqlServerName $maxConnections
Write-Output "`n----- Applying V-40936 for SQL 2012 Instance -----"
Disable-SaAccount $sqlServerName
Write-Output "`n----- Configuring SQL Server Auditing -----"
Set-SQLServerAuditing $ConfigureAuditingScript $sqlServerName $instanceName $traceFile $maxFileSize $fileCount
Write-Output "`n----- Applying V-40944 for SQL 2012 Instance -----"
Set-SQLSoftwareLibrariesPermissions $instanceName
Write-Output "`n----- Applying V-40950 for SQL 2012 Instance -----"
Enable-FileAuditing $instanceName
Write-Output "`n----- Applying V-41037 for SQL 2012 Instance -----"
Rename-SaAccount $sqlServerName $newName
Write-Output "`n----- Applying V-41247 for SQL 2012 Instance -----"
Remove-Permisions $sqlServerName "AlterAnyAvailabilityGroup"
Write-Output "`n----- Applying V-41251 for SQL 2012 Instance -----"
Remove-Permisions $sqlServerName "ViewAnyDatabase"
Write-Output "`n----- Applying V-41294 for SQL 2012 Instance -----"
Remove-Permisions $sqlServerName "ViewServerState"
Write-Output "`n----- Applying V-54589 for SQL 2012 Instance -----"
Set-SQLDataRootDirectoryPermissions $instanceName
Write-Output "`n----- Harden SQL Server Auditing -----"
Harden-SQLServerAuditing $sqlServerName $instanceName
Write-Output "`n----- Generate CSR for SQL Server SSL Certificate -----"
New-CertificateSigningRequest