This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-PAMEnvironment.ps1
270 lines (224 loc) · 9.27 KB
/
Get-PAMEnvironment.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
Function Get-PAMEnvironment {
<#
.SYNOPSIS
Retrieves environment details relating to integration with PAM from local system.
.DESCRIPTION
Retrieves environment and remote desktop configuration from local system.
Includes the OS environment, Network Authentication Level, Security Layer, Secure Boot, NetBIOSName, etc.
Also verifies connectivity for AppSSO feature.
.PARAMETER RDP
Retrieve RDP Environment.
.PARAMETER Hotfix
Retrieve the hotfixes that are installed from local system.
.PARAMETER AppSSO
Verify connectivity with configured PAM server.
.PARAMETER PasswordManagement
Retrieve prerequisite environment configuration.
.EXAMPLE
PS > . .\Get-PAMEnvironment.ps1
PS > Get-PAMEnvironment -RDP 1
-------------------------------
Environment
-------------------------------
Caption : Microsoft Windows Server 2012 R2 Standard
ServicePackMajorVersion : 0
OSArchitecture : 64-bit
BuildNumber : 9600
CSName : COMPUTERNAME
SecureBoot : False
NetBIOSName : DOMAIN (i.e. DOMAIN\User)
-------------------------------
RDP
-------------------------------
PSComputerName : COMPUTERNAME
TerminalProtocol : Microsoft RDP 8.0
TerminalName : RDP-Tcp
UserAuthenticationRequired (NLA) : False
SecurityLayer : 1
MinEncryptionLevel : 2
#>
[CmdletBinding()]
Param(
[Parameter(
Mandatory=$false,
HelpMessage="Retrieve RDP Environment?"
)]
[bool]$RDP,
[Parameter(
Mandatory=$false,
HelpMessage="Retrieve Hotfix history?"
)]
[bool]$Hotfix,
[Parameter(
Mandatory=$false,
HelpMessage="AppSSO verification"
)]
[bool]$AppSSO,
[Parameter(
Mandatory=$false,
HelpMessage="Password Management verification"
)]
[bool]$PasswordManagement
)
Begin {
$Lines = "-------------------------------`r`n"
$RDP_ConfigProperties = 'PSComputername', 'TerminalProtocol', 'TerminalName',
@{L='UserAuthenticationRequired (NLA)';E={[bool]$RDP.UserAuthenticationRequired}},
'SecurityLayer', 'MinEncryptionLevel'
$WMIParams = @{
Class = 'Win32_TSGeneralSetting'
Namespace = 'root\CIMV2\TerminalServices'
Filter = "TerminalName='RDP-Tcp'"
ErrorAction = 'Stop'
}
$SecureBootParams = @{
ErrorAction = 'Stop'
}
$RDP_PORT_PATH = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp'
$PAM_SL_PATH_RestEndpoint = 'HKLM:\SOFTWARE\Protocom\SecureLogin\RestCredentials'
}
Process {
# General Environment Info
Try {
Write-Output "$Lines Environment`r`n$Lines"
# Is Secure Boot enabled?
Try {
$SecureBoot = Confirm-SecureBootUEFI @SecureBootParams
} Catch [System.PlatformNotSupportedException] {
$SecureBoot = $false
} Catch {
Write-Error "[SecureBoot] $_"
}
# Gather more environment info
$Environment = Get-CimInstance Win32_OperatingSystem | Select-Object Caption, OSArchitecture, ServicePackMajorVersion, Version, BuildNumber, CSName
$NetBIOSName = (Get-ADDomain -Current LocalComputer).NetBIOSName
# Consolidate for report
$Environment | Add-Member -NotePropertyName "SecureBoot" -NotePropertyValue $SecureBoot
$Environment | Add-Member -NotePropertyName "NetBIOSName" -NotePropertyValue $NetBIOSName
$Environment
} Catch {
Write-Error "[Environment] $_"
}
# RDP Environment
if ($RDP) {
Try {
Write-Output "$Lines RDP`r`n$Lines"
$RDP_Config = Get-WMIObject @WMIParams
$RDP_Report = $RDP_Config | Select-Object $RDP_ConfigProperties
$RDP_Port = (Get-ItemProperty -PATH $RDP_PORT_PATH).PortNumber
$RDP_Listening = Get-NetTCPConnection -State LISTEN -LocalPort $RDP_PORT
# Consolidate for report
$RDP_Report | Add-Member -NotePropertyName "PortNumber" -NotePropertyValue $RDP_PORT
$RDP_Report
$RDP_Listening | Format-Table
} Catch {
Write-Error "[RDP] $_"
}
}
# Hotfixes
if ($Hotfix) {
Try {
Write-Output "$Lines Hotfix`r`n$Lines"
Get-HotFix | Format-Table
} Catch {
Write-Error "[Hotfix] $_"
}
}
# AppSSO
if ($AppSSO) {
Write-Output "$Lines AppSSO`r`n$Lines"
$REST_ENDPOINT = (Get-ItemProperty -PATH $PAM_SL_PATH_RestEndpoint).Server
$URI = [System.Uri]$REST_ENDPOINT
Write-Output "REST_ENDPOINT: $REST_ENDPOINT`r`n"
# Connectivity
Try {
Write-Output "Connectivity`r`n$Lines"
$Connectivity = Test-NetConnection $URI.dnsSafeHost -Port $URI.Port
$Connectivity | Select-Object SourceAddress, ComputerName, RemoteAddress, RemotePort, NameResolutionSucceeded, PingSucceeded, TcpTestSucceeded
} Catch {
Write-Error "[AppSSO_Connectivity] $_"
}
# Certificate
Try {
Write-Output "Certificate`r`n$Lines"
Get-CertInfoTcp $URI.dnsSafeHost $URI.Port
} Catch {
Write-Error "[AppSSO_Certificate] $_"
}
}
# Password Management
if ($PasswordManagement) {
Write-Output "$Lines Password Management`r`n$Lines"
Try {
# Powershell Version
Write-Output "Powershell Version`r`n$Lines" $PSVersiontable.PSVersion
# WinRM service
Write-Output "WinRM Service`r`n$Lines"
Get-Service winrm -ErrorAction SilentlyContinue
# WinRM config
Write-Output "Client Config:`r`n"
winrm get winrm/config/client
# Powershell Execution Policy
Write-Output "PS Execution Policy`r`n$Lines"
Get-ExecutionPolicy
} Catch {
Write-Error "[Password Management] $_"
}
}
}
}
function Get-CertInfoTcp {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory)]
[string] $ComputerName,
[Parameter(Position = 1)]
[int] $Port = 443,
[Parameter()]
[int] $Timeout = 3000,
[Parameter()]
[switch] $ReturnCertificate
)
try {
$tcpClient = New-Object -TypeName System.Net.Sockets.TcpClient
$iar = $tcpClient.BeginConnect($ComputerName,$Port,$null,$null)
$wait = $iar.AsyncWaitHandle.WaitOne($Timeout,$false)
if (!$wait) {
$tcpClient.Close()
Write-Warning 'Connection attempt timed out'
}
else {
$null = $tcpClient.EndConnect($iar)
if ($tcpClient.Connected) {
$tcpStream = $tcpClient.GetStream()
$sslStream = New-Object -TypeName System.Net.Security.SslStream -ArgumentList ($tcpStream, $false)
$sslStream.AuthenticateAsClient($ComputerName, $null, [System.Security.Authentication.SslProtocols]::Tls12, $false)
$certificate = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList ($sslStream.RemoteCertificate)
Write-Output "TLS connection has been established."
if ($ReturnCertificate) {
Write-Output $certificate
}
else {
Write-Output ([PSCustomObject] [Ordered] @{
IssuerCN = $certificate.Issuer.Split(', ',[System.StringSplitOptions]::RemoveEmptyEntries)[0].Split('=')[1]
SubjectCN = $certificate.Subject.Split(', ',[System.StringSplitOptions]::RemoveEmptyEntries)[0].Split('=')[1]
ValidFrom = $certificate.NotBefore
ValidTo = $certificate.NotAfter
})
}
$certificate.Dispose()
$sslStream.Close()
$sslStream.Dispose()
$tcpStream.Close()
$tcpStream.Dispose()
}
else {
Write-Warning "Unable to establish connection to $ComputerName on port $Port"
}
$tcpClient.Close()
}
}
catch {
Write-Warning $_.Exception.InnerException.Message
}
}