-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path306_Network.ps1
1275 lines (1061 loc) · 61.8 KB
/
306_Network.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function Get-RpcRange {
<#
.SYNOPSIS
Helper - Dynamically identifies the range of randomized RPC ports from a list of ports.
Author: @itm4n
License: BSD 3-Clause
.DESCRIPTION
This function is a helper for the Invoke-TcpEndpointsCheck function. Windows uses a set of RPC ports that are randomly allocated in the range 49152-65535 by default. If we want to filter out these listening ports we must first figure out this set of ports. The aim of this function is to guess this range using basic statistics on a given array of port numbers. We can quite reliably identify the RPC port set because they are concentrated in a very small range. It's not 100% reliable but it will do the job most of the time.
.PARAMETER Ports
An array of port numbers
.EXAMPLE
PS C:\> Get-RpcRange -Ports $Ports
MinPort MaxPort
------- -------
49664 49672
#>
[CmdletBinding()]Param(
[Parameter(Mandatory=$true)]
[Int[]]
$Ports
)
function Get-Stats {
[CmdletBinding()]Param(
[Int[]]$Ports,
[Int]$MinPort,
[Int]$MaxPort,
[Int]$Span
)
$Stats = @()
For ($i = $MinPort; $i -lt $MaxPort; $i += $Span) {
$Counter = 0
foreach ($Port in $Ports) {
if (($Port -ge $i) -and ($Port -lt ($i + $Span))) {
$Counter += 1
}
}
$RangeStats = New-Object -TypeName PSObject
$RangeStats | Add-Member -MemberType "NoteProperty" -Name "MinPort" -Value $i
$RangeStats | Add-Member -MemberType "NoteProperty" -Name "MaxPort" -Value ($i + $Span)
$RangeStats | Add-Member -MemberType "NoteProperty" -Name "PortsInRange" -Value $Counter
$Stats += $RangeStats
}
$Stats
}
# We split the range 49152-65536 into blocks of size 32 and then, we take the block which has
# greater number of ports in it.
$Stats = Get-Stats -Ports $Ports -MinPort 49152 -MaxPort 65536 -Span 32
$MaxStat = $null
foreach ($Stat in $Stats) {
if ($Stat.PortsInRange -gt $MaxStat.PortsInRange) {
$MaxStat = $Stat
}
}
For ($i = 0; $i -lt 8; $i++) {
$Span = ($MaxStat.MaxPort - $MaxStat.MinPort) / 2
$NewStats = Get-Stats -Ports $Ports -MinPort $MaxStat.MinPort -MaxPort $MaxStat.MaxPort -Span $Span
if ($NewStats) {
if ($NewStats[0].PortsInRange -eq 0) {
$MaxStat = $NewStats[1]
}
elseif ($NewStats[1].PortsInRange -eq 0) {
$MaxStat = $NewStats[0]
}
else {
break
}
}
}
$Result = New-Object -TypeName PSObject
$Result | Add-Member -MemberType "NoteProperty" -Name "MinPort" -Value $MaxStat.MinPort
$Result | Add-Member -MemberType "NoteProperty" -Name "MaxPort" -Value $MaxStat.MaxPort
$Result
}
function Invoke-NetworkAdaptersCheck {
<#
.SYNOPSIS
Collect detailed information about all Ethernet and Wi-Fi network adapters.
Author: @itm4n
License: BSD 3-Clause
.DESCRIPTION
Collect detailed information about all active Ethernet adapters.
.EXAMPLE
PS C:\> Invoke-NetworkAdaptersCheck
Name : {B52615AE-995C-415B-9925-0C0815A81598}
FriendlyName : Ethernet0
Type : Ethernet
Status : Up
DnsSuffix : localdomain
Description : Intel(R) 82574L Gigabit Network Connection
PhysicalAddress : 00:0c:29:1e:2b:00
Flags : DdnsEnabled, Dhcpv4Enabled, Ipv4Enabled, Ipv6Enabled
IPv6 : fe80::1e9:ec0a:a7a2:993f (/64)
IPv4 : 192.168.140.130 (/24)
Gateway : 192.168.140.2
DHCPv4Server : 192.168.140.254
DHCPv6Server :
DnsServers : 192.168.140.2
DNSSuffixList :
#>
[CmdletBinding()] Param()
Get-NetworkAdaptersList | Where-Object { $_.Type -eq "Ethernet" -or $_.Type -eq "IEEE80211" } | Select-Object -Property Name,FriendlyName,Type,Status,DnsSuffix,Description,PhysicalAddress,Flags,IPv6,IPv4,Gateway,DHCPv4Server,DHCPv6Server,DnsServers,DNSSuffixList
}
function Invoke-TcpEndpointsCheck {
<#
.SYNOPSIS
Enumerates all TCP endpoints on the local machine (IPv4 and IPv6)
Author: @itm4n
License: BSD 3-Clause
.DESCRIPTION
It uses the custom "Get-NetworkEndpoints" function to enumerate all the TCP endpoints on the local machine, IPv4 and IPv6. The list can then be filtered based on a list of known ports.
.PARAMETER Filtered
Use this switch to filter out the list of endpoints returned by this function. The filter excludes all the standard ports such as 445 or 139 and all the random RPC ports. The RPC port range is dynamically guessed using the helper function "Get-RpcRange".
.EXAMPLE
PS C:\> Invoke-TcpEndpointsCheck | ft
IP Proto LocalAddress State PID Name
-- ----- ------------ ----- --- ----
IPv4 TCP 0.0.0.0:135 LISTENING 968 svchost
IPv4 TCP 0.0.0.0:445 LISTENING 4 System
IPv4 TCP 0.0.0.0:5040 LISTENING 5408 svchost
IPv4 TCP 0.0.0.0:49664 LISTENING 732 lsass
IPv4 TCP 0.0.0.0:49665 LISTENING 564 wininit
IPv4 TCP 0.0.0.0:49666 LISTENING 1208 svchost
IPv4 TCP 0.0.0.0:49667 LISTENING 1412 svchost
IPv4 TCP 0.0.0.0:49668 LISTENING 2416 spoolsv
IPv4 TCP 0.0.0.0:49669 LISTENING 656 services
IPv4 TCP 192.168.74.136:139 LISTENING 4 System
IPv6 TCP [::]:135 LISTENING 968 svchost
IPv6 TCP [::]:445 LISTENING 4 System
IPv6 TCP [::]:49664 LISTENING 732 lsass
IPv6 TCP [::]:49665 LISTENING 564 wininit
IPv6 TCP [::]:49666 LISTENING 1208 svchost
IPv6 TCP [::]:49667 LISTENING 1412 svchost
IPv6 TCP [::]:49668 LISTENING 2416 spoolsv
IPv6 TCP [::]:49669 LISTENING 656 services
#>
[CmdletBinding()] Param(
[Switch]$Filtered
)
$IgnoredPorts = @(135, 139, 445)
$Endpoints = Get-NetworkEndpoints
$Endpoints += Get-NetworkEndpoints -IPv6
if ($Filtered) {
$FilteredEndpoints = @()
$AllPorts = @()
$Endpoints | ForEach-Object { $AllPorts += $_.LocalPort }
$AllPorts = $AllPorts | Sort-Object -Unique
$RpcRange = Get-RpcRange -Ports $AllPorts
Write-Verbose "Excluding port range: $($RpcRange.MinPort)-$($RpcRange.MaxPort)"
$Endpoints | ForEach-Object {
if (-not ($IgnoredPorts -contains $_.LocalPort)) {
if ($RpcRange) {
if (($_.LocalPort -lt $RpcRange.MinPort) -or ($_.LocalPort -ge $RpcRange.MaxPort)) {
$FilteredEndpoints += $_
}
}
}
}
$Endpoints = $FilteredEndpoints
}
$Endpoints | ForEach-Object {
$TcpEndpoint = New-Object -TypeName PSObject
$TcpEndpoint | Add-Member -MemberType "NoteProperty" -Name "IP" -Value $_.IP
$TcpEndpoint | Add-Member -MemberType "NoteProperty" -Name "Proto" -Value $_.Proto
$TcpEndpoint | Add-Member -MemberType "NoteProperty" -Name "LocalAddress" -Value $_.Endpoint
$TcpEndpoint | Add-Member -MemberType "NoteProperty" -Name "State" -Value $_.State
$TcpEndpoint | Add-Member -MemberType "NoteProperty" -Name "PID" -Value $_.PID
$TcpEndpoint | Add-Member -MemberType "NoteProperty" -Name "Name" -Value $_.Name
$TcpEndpoint
}
}
function Invoke-UdpEndpointsCheck {
<#
.SYNOPSIS
Enumerates all UDP endpoints on the local machine (IPv4 and IPv6)
Author: @itm4n
License: BSD 3-Clause
.DESCRIPTION
It uses the custom "Get-NetworkEndpoints" function to enumerate all the UDP endpoints on the local machine, IPv4 and IPv6. The list can be filtered based on a list of known ports.
.PARAMETER Filtered
Use this switch to filter out the list of endpoints returned by this function. The filter excludes all the standard ports such as 139 or 500.
.EXAMPLE
PS C:\> Invoke-UdpEndpointsCheck | ft
IP Proto LocalAddress State PID Name
-- ----- ------------ ----- --- ----
IPv4 UDP 0.0.0.0:5050 N/A 5408 svchost
IPv4 UDP 0.0.0.0:5353 N/A 2176 svchost
IPv4 UDP 0.0.0.0:5355 N/A 2176 svchost
IPv4 UDP 0.0.0.0:54565 N/A 3100 SkypeApp
IPv4 UDP 127.0.0.1:1900 N/A 5088 svchost
IPv4 UDP 127.0.0.1:51008 N/A 5088 svchost
IPv4 UDP 127.0.0.1:60407 N/A 3052 svchost
IPv4 UDP 192.168.74.136:137 N/A 4 System
IPv4 UDP 192.168.74.136:138 N/A 4 System
IPv4 UDP 192.168.74.136:1900 N/A 5088 svchost
IPv4 UDP 192.168.74.136:51007 N/A 5088 svchost
IPv6 UDP [::]:5353 N/A 2176 svchost
IPv6 UDP [::]:5355 N/A 2176 svchost
IPv6 UDP [::]:54565 N/A 3100 SkypeApp
IPv6 UDP [::1]:1900 N/A 5088 svchost
IPv6 UDP [::1]:51006 N/A 5088 svchost
IPv6 UDP [fe80::3a:b6c0:b5f0:a05e%12]:1900 N/A 5088 svchost
IPv6 UDP [fe80::3a:b6c0:b5f0:a05e%12]:51005 N/A 5088 svchost
#>
[CmdletBinding()] Param(
[Switch]$Filtered
)
# https://support.microsoft.com/en-us/help/832017/service-overview-and-network-port-requirements-for-windows
$IgnoredPorts = @(53, 67, 123, 137, 138, 139, 500, 1701, 2535, 4500, 445, 1900, 5050, 5353, 5355)
$Endpoints = Get-NetworkEndpoints -UDP
$Endpoints += Get-NetworkEndpoints -UDP -IPv6
if ($Filtered) {
$FilteredEndpoints = @()
$Endpoints | ForEach-Object {
if (-not ($IgnoredPorts -contains $_.LocalPort)) {
$FilteredEndpoints += $_
}
}
$Endpoints = $FilteredEndpoints
}
$Endpoints | ForEach-Object {
if (-not ($_.Name -eq "dns")) {
$UdpEndpoint = New-Object -TypeName PSObject
$UdpEndpoint | Add-Member -MemberType "NoteProperty" -Name "IP" -Value $_.IP
$UdpEndpoint | Add-Member -MemberType "NoteProperty" -Name "Proto" -Value $_.Proto
$UdpEndpoint | Add-Member -MemberType "NoteProperty" -Name "LocalAddress" -Value $_.Endpoint
$UdpEndpoint | Add-Member -MemberType "NoteProperty" -Name "State" -Value $_.State
$UdpEndpoint | Add-Member -MemberType "NoteProperty" -Name "PID" -Value $_.PID
$UdpEndpoint | Add-Member -MemberType "NoteProperty" -Name "Name" -Value $_.Name
$UdpEndpoint
}
}
}
function Invoke-WlanProfilesCheck {
<#
.SYNOPSIS
List saved WLAN profiles and try to determine if they are vulnerable.
Author: @itm4n
License: BSD 3-Clause
.DESCRIPTION
This cmdlet invokes the 'Get-WlanProfileList' helper and then performs a series of tests on each returned item. For now, only 802.1x profiles are checked. Therefore, we assume that any other profile is 'compliant' by default. Example of a typical vulnerability: the authentication method is PEAP+MSCHAPv2, but the identity of the authentication server is not verified; an evil twin attack could therefore be used to capture or relay the credentials of the user/machine.
#>
[CmdletBinding()] Param()
Get-WlanProfileList | ForEach-Object {
# Assume not vulnerable by default because there are authentication schemes that we do not support
# (yet?). We will perform a series of checks on some parameters. As soon as a parameter does not
# pass a test, we set the 'Vulnerable' status to 'True'. If a test does not pass, the description
# variable is populated with a text that provides a description of the issue.
$Description = ""
$Vulnerable = $false
if ($_.Dot1X) {
$PerformServerValidation = $_.Eap.PerformServerValidation
$PerformServerValidationDescription = $_.Eap.PerformServerValidationDescription
if ($null -ne $PerformServerValidation) {
if ($PerformServerValidation -eq $false) {
$Vulnerable = $true
$Description = "$($Description)$($PerformServerValidationDescription) "
}
}
$ServerValidationDisablePrompt = $_.Eap.ServerValidationDisablePrompt
$ServerValidationDisablePromptDescription = $_.Eap.ServerValidationDisablePromptDescription
if ($null -ne $ServerValidationDisablePrompt) {
if ($ServerValidationDisablePrompt -eq $false) {
$Vulnerable = $true
$Description = "$($Description)$($ServerValidationDisablePromptDescription) "
}
}
$TrustedRootCAs = $_.Eap.TrustedRootCAs
if ($null -eq $TrustedRootCAs) {
$Vulnerable = $true
$Description = "$($Description)No explicit trusted root CA is specified. "
}
else {
# TODO: ensure that only a domain CA is specified. Not sure how I should do that yet...
}
if ($null -ne $_.InnerEap) {
if ($_.InnerEapTypeId -eq 26) {
# If MS-CHAPv2 is used for authentication, user (or machine) credentials are used. It is
# recommended to use certificate-based authentication instead as user credentials could be cracked
# or relayed.
$Vulnerable = $true
$Description = "$($Description)MS-CHAPv2 is used for authentication. "
}
}
}
if ($Vulnerable) {
$_ | Add-Member -MemberType "NoteProperty" -Name "Description" -Value $Description
$_ | Select-Object -Property * -ExcludeProperty Eap,InnerEap
}
}
}
function Invoke-AirstrikeAttackCheck {
<#
.SYNOPSIS
Check whether the 'Do not display network selection UI' policy is enforced.
.DESCRIPTION
This cmdlet first checks whether the tested machined is a workstation with a version of Windows that supports the policy 'Do not display network selection UI'. If so, it checks wheter it was enforced by reading the corresponding registry key/value. If the value is not set to 1, the result is not compliant.
.EXAMPLE
PS C:\> Invoke-AirstrikeAttackCheck
Key : HKLM\SOFTWARE\Policies\Microsoft\Windows\System
Value : DontDisplayNetworkSelectionUI
Data : (null)
Description : The network selection UI is displayed on the logon screen (default).
.LINK
https://shenaniganslabs.io/2021/04/13/Airstrike.html
https://admx.help/?Category=Windows_10_2016&Policy=Microsoft.Policies.WindowsLogon::DontDisplayNetworkSelectionUI
#>
[CmdletBinding()] param()
# Check whether the machine is a workstation, otherwise irrelevant.
$MachineRole = Get-MachineRole
if ($MachineRole.Name -ne "WinNT") {
Write-Verbose "Not a workstation, this check is irrelevant."
return
}
# Check Windows version, if < 7, irrelevant.
$WindowsVersion = Get-WindowsVersion
if ((($WindowsVersion.Major -eq 6) -and ($WindowsVersion.Minor -lt 2)) -or ($WindowsVersion.Major -lt 6)) {
Write-Verbose "This version of Windows is not supported."
return
}
# Read the value of the 'DontDisplayNetworkSelectionUI' policy.
$RegKey = "HKLM\SOFTWARE\Policies\Microsoft\Windows\System"
$RegValue = "DontDisplayNetworkSelectionUI"
$RegData = (Get-ItemProperty -Path "Registry::$($RegKey)" -ErrorAction SilentlyContinue).$RegValue
# If the policy is enabled, the machine is not vulnerable.
if ($RegData -ge 1) {
Write-Verbose "The policy 'DontDisplayNetworkSelectionUI' is enabled, not vulnerable."
return
}
$Result = New-Object -TypeName PSObject
$Result | Add-Member -MemberType "NoteProperty" -Name "Key" -Value $RegKey
$Result | Add-Member -MemberType "NoteProperty" -Name "Value" -Value $RegValue
$Result | Add-Member -MemberType "NoteProperty" -Name "Data" -Value $(if ($null -eq $RegData) { "(null)" } else { $RegData })
$Result | Add-Member -MemberType "NoteProperty" -Name "Description" -Value "The network selection UI is displayed on the logon screen (default)."
$Result
}
function Convert-SocketAddressToObject {
[CmdletBinding()] Param(
[object] # SOCKET_ADDRESS struct
$SocketAddress
)
if ($SocketAddress.SockAddr -eq [IntPtr]::Zero) {
Write-Verbose "SOCKET_ADDRESS.lpSockaddr is null"
return
}
# The type of structure pointed to by SOCKET_ADDRESS.lpSockaddr depends on the address family
# (AF_INET or AF_INT6). The address family is the first member of the target structure, so it is
# necessary to first read this value in order to determine whether a SOCKADDR or a SOCKADDR_IN6
# structure should be used.
$AddressFamily = [System.Runtime.InteropServices.Marshal]::ReadInt16($SocketAddress.SockAddr)
if ($AddressFamily -eq 2) {
$AddressFamilyName = "AF_INET"
$Addr = [System.Runtime.InteropServices.Marshal]::PtrToStructure($SocketAddress.SockAddr, [type]$SOCKADDR)
$StringAddr = (@($Addr.Data[2], $Addr.Data[3], $Addr.Data[4], $Addr.Data[5]) -join ".")
}
elseif ($AddressFamily -eq 23) {
$AddressFamilyName = "AF_INET6"
$Addr = [System.Runtime.InteropServices.Marshal]::PtrToStructure($SocketAddress.SockAddr, [type]$SOCKADDR_IN6)
$LeadingZero = $true
$MidZero = $true
$Result = ""
$(for ($i = 0; $i -lt $Addr.Addr.Addr.Length; $i += 2) {
$c = $Addr.Addr.Addr[$i]
$d = $Addr.Addr.Addr[$i + 1]
$t = $c * 256 + $d
if (($t -eq 0) -and $LeadingZero) { if ($i -eq 0) { $Result += "::" }; continue } else { $LeadingZero = $false }
if (($t -eq 0) -and (-not $LeadingZero)) { if ($MidZero) { $Result += ":"; $MidZero = $false }; continue }
$Result += "$('{0:x}' -f $t):"
})
$StringAddr = $Result.TrimEnd(":")
}
else {
# Silently fail rather than throwing an exception
Write-Verbose "Unknown family: $AddressFamily"
return
}
$Result = New-Object -TypeName PSObject
$Result | Add-Member -MemberType "NoteProperty" -Name "IPAddress" -Value $StringAddr
$Result | Add-Member -MemberType "NoteProperty" -Name "Family" -Value $AddressFamily
$Result | Add-Member -MemberType "NoteProperty" -Name "FamilyName" -Value $AddressFamilyName
$Result
}
function Get-NetworkAdaptersList {
<#
.SYNOPSIS
List network adpaters.
Author: @itm4n
License: BSD 3-Clause
.DESCRIPTION
This function leverages the Windows API (GetAdaptersAddresses) to list the network adapters.
.PARAMETER All
Specify this option to list all NDIS interfaces.
.EXAMPLE
PS C:\> Get-NetworkInterfaceList
Name : {B52615AE-995C-415B-9925-0C0815A81598}
FriendlyName : Ethernet0
Type : Ethernet
Status : Up
ConnectionType : Dedicated
TunnelType : None
TxSpeed : 1000000000
RxSpeed : 1000000000
DnsSuffix : localdomain
Description : Intel(R) 82574L Gigabit Network Connection
PhysicalAddress : 00:0c:29:1e:2b:00
Flags : DdnsEnabled, Dhcpv4Enabled, Ipv4Enabled, Ipv6Enabled
IPv6 : fe:80::1:e9:ec:a:a7:a2:99:3f (/64)
IPv4 : 192.168.140.130 (/24)
Gateway : 192.168.140.2
DHCPv4Server : 192.168.140.254
DHCPv6Server :
DHCPv6IAID : 100666409
DHCPv6ClientDUID : 00:01:00:01:28:2e:96:5d:00:0c:29:1e:2b:00
DnsServers : 192.168.140.2
WINSServers : 192.168.140.2
DnsSuffixList :
#>
[CmdletBinding()] Param(
[switch]
$All = $false
)
$InterfaceTypes = @{
'Other' = 1
'Ethernet' = 6
'TokenRing' = 9
'PPP' = 23
'Loopback' = 24
'ATM' = 37
'IEEE80211' = 71
'Tunnel' = 131
'IEEE1394' = 144
}
$InterfacesStatuses = @{
'Up' = 1
'Down' = 2
'Testing' = 3
'Unknown' = 4
'Dormant' = 5
'NotPresent' = 6
'LowerLayerDown' = 7
}
$ConnectionTypes = @{
'Dedicated' = 1
'Passive' = 2
'Demand' = 3
'Maximum' = 4
}
$TunnelTypes = @{
'None' = 0
'Other' = 1
'Direct' = 2
'6to4' = 11
'ISATAP' = 13
'TEREDO' = 14
'IPHTTPS' = 15
}
$GAA_FLAG_INCLUDE_PREFIX = 0x0010
$GAA_FLAG_INCLUDE_WINS_INFO = 0x0040
$GAA_FLAG_INCLUDE_GATEWAYS = 0x0080
$GAA_FLAG_INCLUDE_ALL_INTERFACES = 0x0100
$Family = 0 # AF_UNSPEC
$Flags = $GAA_FLAG_INCLUDE_PREFIX -bor $GAA_FLAG_INCLUDE_WINS_INFO -bor $GAA_FLAG_INCLUDE_GATEWAYS
if ($All) { $Flags = $Flgas -bor $GAA_FLAG_INCLUDE_ALL_INTERFACES }
$AdaptersSize = 0
$Result = $Iphlpapi::GetAdaptersAddresses($Family, $Flags, [IntPtr]::Zero, [IntPtr]::Zero, [ref]$AdaptersSize)
if ($AddressesSize -eq 0) {
Write-Verbose "GetAdaptersAddresses KO - Error: $Result"
return
}
Write-Verbose "GetAdaptersAddresses OK - Size: $AdaptersSize"
$AdaptersPtr = [System.Runtime.InteropServices.Marshal]::AllocHGlobal($AdaptersSize)
$Result = $Iphlpapi::GetAdaptersAddresses($Family, $Flags, [IntPtr]::Zero, $AdaptersPtr, [ref]$AdaptersSize)
if ($Result -ne 0) {
Write-Verbose "GetAdaptersAddresses KO - Error: $Result"
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($AdaptersSize)
return
}
Write-Verbose "GetAdaptersAddresses OK"
do {
$Adapter = [System.Runtime.InteropServices.Marshal]::PtrToStructure($AdaptersPtr, [type]$IP_ADAPTER_ADDRESSES)
# Interface type
$InterfaceType = $InterfaceTypes.GetEnumerator() | Where-Object { $_.value -eq $Adapter.IfType } | ForEach-Object { $_.Name }
# Status
$InterfaceStatus = $InterfacesStatuses.GetEnumerator() | Where-Object { $_.value -eq $Adapter.OperStatus } | ForEach-Object { $_.Name }
# Connection type
$ConnectionType = $ConnectionTypes.GetEnumerator() | Where-Object { $_.value -eq $Adapter.ConnectionType } | ForEach-Object { $_.Name }
# Tunnel type
$TunnelType = $TunnelTypes.GetEnumerator() | Where-Object { $_.value -eq $Adapter.TunnelType } | ForEach-Object { $_.Name }
# Friendly representation of the physical address
$AdapterPhysicalAddress = ""
if ($Adapter.PhysicalAddressLength -ne 0) {
$AdapterPhysicalAddress = $(for ($i = 0; $i -lt $Adapter.PhysicalAddressLength; $i++) { "{0:x2}" -f $Adapter.PhysicalAddress[$i] }) -join ":"
}
# Unicast addresses
$UnicastAddresses = @()
$UnicastAddressPtr = $Adapter.FirstUnicastAddress
while ($UnicastAddressPtr -ne [IntPtr]::Zero) {
$UnicastAddress = [System.Runtime.InteropServices.Marshal]::PtrToStructure($UnicastAddressPtr, [type]$IP_ADAPTER_UNICAST_ADDRESS_LH)
$AddrObject = Convert-SocketAddressToObject -SocketAddress $UnicastAddress.Address
$AddrObject.IPAddress = "$($AddrObject.IPAddress) (/$($UnicastAddress.OnLinkPrefixLength))"
$UnicastAddresses += $AddrObject
$UnicastAddressPtr = $UnicastAddress.Next
}
# DNS servers
$DnsServerAddresses = @()
$DnsServerAddressPtr = $Adapter.FirstDnsServerAddress
while ($DnsServerAddressPtr -ne [IntPtr]::Zero) {
$DnsServerAddress = [System.Runtime.InteropServices.Marshal]::PtrToStructure($DnsServerAddressPtr, [type]$IP_ADAPTER_DNS_SERVER_ADDRESS_XP)
$AddrObject = Convert-SocketAddressToObject -SocketAddress $DnsServerAddress.Address
$DnsServerAddresses += $AddrObject
$DnsServerAddressPtr = $DnsServerAddress.Next
}
# WINS server
$WinsServerAddresses = @()
$WinsServerAddressPtr = $Adapter.FirstWinsServerAddress
while ($WinsServerAddressPtr -ne [IntPtr]::Zero) {
$WinServerAddress = [System.Runtime.InteropServices.Marshal]::PtrToStructure($WinsServerAddressPtr, [type]$IP_ADAPTER_WINS_SERVER_ADDRESS_LH)
$AddrObject = Convert-SocketAddressToObject -SocketAddress $WinServerAddress.Address
$WinsServerAddresses += $AddrObject
$WinsServerAddressPtr = $WinServerAddress.Next
}
# Gateway
$GatewayAddresses = @()
$GatewayAddressPtr = $Adapter.FirstGatewayAddress
while ($GatewayAddressPtr -ne [IntPtr]::Zero) {
$GatewayAddress = [System.Runtime.InteropServices.Marshal]::PtrToStructure($GatewayAddressPtr, [type]$IP_ADAPTER_GATEWAY_ADDRESS_LH)
$AddrObject = Convert-SocketAddressToObject -SocketAddress $GatewayAddress.Address
$GatewayAddresses += $AddrObject
$GatewayAddressPtr = $GatewayAddress.Next
}
# DNS suffix search list
$DnsSuffixList = @()
$DnsSuffixPtr = $Adapter.FirstDnsSuffix
while ($DnsSuffixPtr -ne [IntPtr]::Zero) {
$DnsSuffix = [System.Runtime.InteropServices.Marshal]::PtrToStructure($DnsSuffixPtr, [type]$IP_ADAPTER_DNS_SUFFIX)
[string[]]$DnsSuffixList += $DnsSuffix.String
$DnsSuffixPtr = $DnsSuffix.Next
}
# DHCPv4 server
$Dhcpv4Server = Convert-SocketAddressToObject -SocketAddress $Adapter.Dhcpv4Server
# DHCPv6 server
$Dhcpv6Server = Convert-SocketAddressToObject -SocketAddress $Adapter.Dhcpv6Server
$Dhcpv6ClientDuid = $(for ($i = 0; $i -lt $Adapter.Dhcpv6ClientDuidLength; $i++) { '{0:x2}' -f $Adapter.Dhcpv6ClientDuid[$i] }) -join ":"
$Result = New-Object -TypeName PSObject
$Result | Add-Member -MemberType "NoteProperty" -Name "Name" -Value $Adapter.AdapterName
$Result | Add-Member -MemberType "NoteProperty" -Name "FriendlyName" -Value $Adapter.FriendlyName
$Result | Add-Member -MemberType "NoteProperty" -Name "Type" -Value $InterfaceType
$Result | Add-Member -MemberType "NoteProperty" -Name "Status" -Value $InterfaceStatus
$Result | Add-Member -MemberType "NoteProperty" -Name "ConnectionType" -Value $ConnectionType
$Result | Add-Member -MemberType "NoteProperty" -Name "TunnelType" -Value $TunnelType
$Result | Add-Member -MemberType "NoteProperty" -Name "TxSpeed" -Value $Adapter.TransmitLinkSpeed
$Result | Add-Member -MemberType "NoteProperty" -Name "RxSpeed" -Value $Adapter.ReceiveLinkSpeed
$Result | Add-Member -MemberType "NoteProperty" -Name "DnsSuffix" -Value $Adapter.DnsSuffix
$Result | Add-Member -MemberType "NoteProperty" -Name "Description" -Value $Adapter.Description
$Result | Add-Member -MemberType "NoteProperty" -Name "PhysicalAddress" -Value $AdapterPhysicalAddress
$Result | Add-Member -MemberType "NoteProperty" -Name "Flags" -Value ($Adapter.Flags -as $IP_ADAPTER_FLAGS)
$Result | Add-Member -MemberType "NoteProperty" -Name "IPv6" -Value (($UnicastAddresses | Where-Object { $_.Family -eq 23 } | ForEach-Object { $_.IPAddress }) -join ", ")
$Result | Add-Member -MemberType "NoteProperty" -Name "IPv4" -Value (($UnicastAddresses | Where-Object { $_.Family -eq 2 } | ForEach-Object { $_.IPAddress }) -join ", ")
$Result | Add-Member -MemberType "NoteProperty" -Name "Gateway" -Value (($GatewayAddresses | ForEach-Object { $_.IPAddress }) -join ", ")
$Result | Add-Member -MemberType "NoteProperty" -Name "DHCPv4Server" -Value $Dhcpv4Server.IPAddress
$Result | Add-Member -MemberType "NoteProperty" -Name "DHCPv6Server" -Value $Dhcpv6Server.IPAddress
$Result | Add-Member -MemberType "NoteProperty" -Name "DHCPv6IAID" -Value $(if ($Adapter.Dhcpv6Iaid -ne 0) { $Adapter.Dhcpv6Iaid } else { $null })
$Result | Add-Member -MemberType "NoteProperty" -Name "DHCPv6ClientDUID" -Value $Dhcpv6ClientDuid
$Result | Add-Member -MemberType "NoteProperty" -Name "DnsServers" -Value (($DnsServerAddresses | ForEach-Object { $_.IPAddress }) -join ", ")
$Result | Add-Member -MemberType "NoteProperty" -Name "WINSServers" -Value (($WinsServerAddresses | ForEach-Object { $_.IPAddress }) -join ", ")
$Result | Add-Member -MemberType "NoteProperty" -Name "DNSSuffixList" -Value ($DnsSuffixList -join ", ")
$Result
[IntPtr]$AdaptersPtr = $Adapter.Next
} while ($AdaptersPtr -ne [IntPtr]::Zero)
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($AdaptersPtr)
}
function Get-NetworkEndpoints {
<#
.SYNOPSIS
Get a list of listening ports (TCP/UDP)
Author: @itm4n
License: BSD 3-Clause
.DESCRIPTION
It uses the 'GetExtendedTcpTable' and 'GetExtendedUdpTable' functions of the Windows API to list the TCP/UDP endpoints on the local machine. It handles both IPv4 and IPv6. For each entry in the table, a custom PS object is returned, indicating the IP version (IPv4/IPv6), the protocol (TCP/UDP), the local address (e.g.: "0.0.0.0:445"), the state, the PID of the associated process and the name of the process. The name of the process is retrieved through a call to "Get-Process -PID <PID>".
.EXAMPLE
PS C:\> Get-NetworkEndpoints | ft
IP Proto LocalAddress LocalPort Endpoint State PID Name
-- ----- ------------ --------- -------- ----- --- ----
IPv4 TCP 0.0.0.0 135 0.0.0.0:135 LISTENING 1216 svchost
IPv4 TCP 0.0.0.0 445 0.0.0.0:445 LISTENING 4 System
IPv4 TCP 0.0.0.0 5040 0.0.0.0:5040 LISTENING 8580 svchost
IPv4 TCP 0.0.0.0 49664 0.0.0.0:49664 LISTENING 984 lsass
IPv4 TCP 0.0.0.0 49665 0.0.0.0:49665 LISTENING 892 wininit
IPv4 TCP 0.0.0.0 49666 0.0.0.0:49666 LISTENING 1852 svchost
IPv4 TCP 0.0.0.0 49667 0.0.0.0:49667 LISTENING 1860 svchost
IPv4 TCP 0.0.0.0 49668 0.0.0.0:49668 LISTENING 2972 svchost
IPv4 TCP 0.0.0.0 49669 0.0.0.0:49669 LISTENING 4480 spoolsv
IPv4 TCP 0.0.0.0 49670 0.0.0.0:49670 LISTENING 964 services
.EXAMPLE
PS C:\> Get-NetworkEndpoints -UDP -IPv6 | ft
IP Proto LocalAddress LocalPort Endpoint State PID Name
-- ----- ------------ --------- -------- ----- --- ----
IPv6 UDP :: 500 [::]:500 N/A 5000 svchost
IPv6 UDP :: 3702 [::]:3702 N/A 4128 dasHost
IPv6 UDP :: 3702 [::]:3702 N/A 4128 dasHost
IPv6 UDP :: 4500 [::]:4500 N/A 5000 svchost
IPv6 UDP :: 62212 [::]:62212 N/A 4128 dasHost
IPv6 UDP ::1 1900 [::1]:1900 N/A 5860 svchost
IPv6 UDP ::1 63168 [::1]:63168 N/A 5860 svchost
#>
[CmdletBinding()] Param(
[Switch]$IPv6 = $false, # IPv4 by default
[Switch]$UDP = $false # TCP by default
)
$AF_INET6 = 23
$AF_INET = 2
if ($IPv6) {
$IpVersion = $AF_INET6
}
else {
$IpVersion = $AF_INET
}
if ($UDP) {
$UDP_TABLE_OWNER_PID = 1
[Int]$BufSize = 0
$Result = $Iphlpapi::GetExtendedUdpTable([IntPtr]::Zero, [ref]$BufSize, $true, $IpVersion, $UDP_TABLE_OWNER_PID, 0)
$LastError = [Runtime.InteropServices.Marshal]::GetLastWin32Error()
}
else {
$TCP_TABLE_OWNER_PID_LISTENER = 3
[Int]$BufSize = 0
$Result = $Iphlpapi::GetExtendedTcpTable([IntPtr]::Zero, [ref]$BufSize, $true, $IpVersion, $TCP_TABLE_OWNER_PID_LISTENER, 0)
$LastError = [Runtime.InteropServices.Marshal]::GetLastWin32Error()
}
if ($Result -eq 122) {
Write-Verbose "GetExtendedProtoTable() OK - Size: $BufSize"
[IntPtr]$TablePtr = [System.Runtime.InteropServices.Marshal]::AllocHGlobal($BufSize)
if ($UDP) {
$Result = $Iphlpapi::GetExtendedUdpTable($TablePtr, [ref]$BufSize, $true, $IpVersion, $UDP_TABLE_OWNER_PID, 0)
}
else {
$Result = $Iphlpapi::GetExtendedTcpTable($TablePtr, [ref]$BufSize, $true, $IpVersion, $TCP_TABLE_OWNER_PID_LISTENER, 0)
}
if ($Result -eq 0) {
if ($UDP) {
if ($IpVersion -eq $AF_INET) {
$Table = [System.Runtime.InteropServices.Marshal]::PtrToStructure($TablePtr, [type] $MIB_UDPTABLE_OWNER_PID)
}
elseif ($IpVersion -eq $AF_INET6) {
$Table = [System.Runtime.InteropServices.Marshal]::PtrToStructure($TablePtr, [type] $MIB_UDP6TABLE_OWNER_PID)
}
}
else {
if ($IpVersion -eq $AF_INET) {
$Table = [System.Runtime.InteropServices.Marshal]::PtrToStructure($TablePtr, [type] $MIB_TCPTABLE_OWNER_PID)
}
elseif ($IpVersion -eq $AF_INET6) {
$Table = [System.Runtime.InteropServices.Marshal]::PtrToStructure($TablePtr, [type] $MIB_TCP6TABLE_OWNER_PID)
}
}
$NumEntries = $Table.NumEntries
Write-Verbose "GetExtendedProtoTable() OK - NumEntries: $NumEntries"
$Offset = [IntPtr] ($TablePtr.ToInt64() + 4)
For ($i = 0; $i -lt $NumEntries; $i++) {
if ($UDP) {
if ($IpVersion -eq $AF_INET) {
$TableEntry = [System.Runtime.InteropServices.Marshal]::PtrToStructure($Offset, [type] $MIB_UDPROW_OWNER_PID)
$LocalAddr = (New-Object -TypeName System.Net.IPAddress($TableEntry.LocalAddr)).IPAddressToString
}
elseif ($IpVersion -eq $AF_INET6) {
$TableEntry = [System.Runtime.InteropServices.Marshal]::PtrToStructure($Offset, [type] $MIB_UDP6ROW_OWNER_PID)
$LocalAddr = New-Object -TypeName System.Net.IPAddress($TableEntry.LocalAddr, $TableEntry.LocalScopeId)
}
}
else {
if ($IpVersion -eq $AF_INET) {
$TableEntry = [System.Runtime.InteropServices.Marshal]::PtrToStructure($Offset, [type] $MIB_TCPROW_OWNER_PID)
$LocalAddr = (New-Object -TypeName System.Net.IPAddress($TableEntry.LocalAddr)).IPAddressToString
}
elseif ($IpVersion -eq $AF_INET6) {
$TableEntry = [System.Runtime.InteropServices.Marshal]::PtrToStructure($Offset, [type] $MIB_TCP6ROW_OWNER_PID)
$LocalAddr = New-Object -TypeName System.Net.IPAddress($TableEntry.LocalAddr, [Int64] $TableEntry.LocalScopeId)
}
}
$LocalPort = $TableEntry.LocalPort[0] * 0x100 + $TableEntry.LocalPort[1]
$ProcessId = $TableEntry.OwningPid
if ($IpVersion -eq $AF_INET) {
$LocalAddress = "$($LocalAddr):$($LocalPort)"
}
elseif ($IpVersion -eq $AF_INET6) {
# IPv6.ToString doesn't work in PSv2 for some reason
try { $LocalAddress = "[$($LocalAddr)]:$($LocalPort)" } catch { $LocalAddress = "????:$($LocalPort)" }
}
$Result = New-Object -TypeName PSObject
$Result | Add-Member -MemberType "NoteProperty" -Name "IP" -Value $(if ($IpVersion -eq $AF_INET) { "IPv4" } else { "IPv6" } )
$Result | Add-Member -MemberType "NoteProperty" -Name "Proto" -Value $(if ($UDP) { "UDP" } else { "TCP" } )
$Result | Add-Member -MemberType "NoteProperty" -Name "LocalAddress" -Value $LocalAddr
$Result | Add-Member -MemberType "NoteProperty" -Name "LocalPort" -Value $LocalPort
$Result | Add-Member -MemberType "NoteProperty" -Name "Endpoint" -Value $LocalAddress
$Result | Add-Member -MemberType "NoteProperty" -Name "State" -Value $(if ($UDP) { "N/A" } else { "LISTENING" } )
$Result | Add-Member -MemberType "NoteProperty" -Name "PID" -Value $ProcessId
$Result | Add-Member -MemberType "NoteProperty" -Name "Name" -Value (Get-Process -PID $ProcessId -ErrorAction SilentlyContinue).ProcessName
$Result
$Offset = [IntPtr] ($Offset.ToInt64() + [System.Runtime.InteropServices.Marshal]::SizeOf($TableEntry))
}
}
else {
Write-Verbose ([ComponentModel.Win32Exception] $LastError)
}
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($TablePtr)
}
else {
Write-Verbose ([ComponentModel.Win32Exception] $LastError)
}
}
function Convert-WlanXmlProfile {
<#
.SYNOPSIS
Convert a WLAN XML profile to a custom PS object.
Author: @itm4n
License: BSD 3-Clause
.DESCRIPTION
This cmdlet takes a WLAN XML profile as an input, parses it, and return a custom object that contains the profile's key information, based on the type of authentication in use. For 802.1x profiles, it returns object(s) containing the detailed configuration. Only the main 802.1x authentication schemes are supported (see the 'Notes' section).
.PARAMETER WlanProfile
A string representing a WLAN profile as an XML document.
.EXAMPLE
PS C:\> Convert-WlanXmlProfile -WlanProfile $WlanProfile
SSID : wp2-access-point
ConnectionType : ESS (Infrastructure)
ConnectionMode : auto
Authentication : WPA2PSK
Encryption : AES
Dot1X : False
.EXAMPLE
PS C:\> Convert-WlanXmlProfile -WlanProfile $WlanProfile
SSID : eap-tls-access-point
ConnectionType : ESS (Infrastructure)
ConnectionMode : auto
Authentication : WPA2
Encryption : AES
Dot1X : True
AuthenticationModeRaw : user
AuthenticationMode : Use user credentials only.
EapTypeId : 13
EapType : EAP-TLS
Eap : @{CredentialsSource=Certificate; ServerValidationDisablePrompt=True; ServerValidationDisablePromptComment=Authentication fails is the certificate is not trusted.; ServerValidationNames=; AcceptServerName=False; AcceptServerNameComment=The server name is not verified.; TrustedRootCAs=0563b8630d62d75abbc8ab1e4bdfb5a899b24d43; TrustedRootCAsComment=DigiCert Assured ID Root CA; PerformServerValidation=False; PerformServerValidationComment=Server validation is not performed.}
.NOTES
Supported EAP methods:
Microsoft implements the following EAP methods: MS-EAP / MSCHAPv2 (26), TLS (13), PEAP (25), SIM (18), AKA (23), AKA' (50), TTLS (21), TEAP (55). In this function, we handle only TLS (13), PEAP (25), TTLS (21), and MSCHAPv2 (26).
.LINK
https://docs.microsoft.com/en-us/windows/win32/nativewifi/portal
#>
[CmdletBinding()] Param(
[ValidateNotNullOrEmpty()]
[string]$WlanProfile
)
BEGIN {
function ConvertTo-Boolean {
param([object]$Text)
if ($null -eq $Text) { Write-Warning "$($MyInvocation.MyCommand.Name) | Null input, assuming False"; return $False }
if ($Text.GetType() -like "*XmlElement") { $Text = $(if ([string]::IsNullOrEmpty($Text.innerText)) { $Text } else { $Text.innerText }) }
try { [System.Convert]::ToBoolean($Text) } catch { Write-Warning "Failed to convert to boolean: $($Text)" }
}
function Get-ConnectionTypeName {
param([string]$ConnectionType)
if ([string]::IsNullOrEmpty($ConnectionType)) { return }
$Enumeration = @{ "ESS" = "Infrastructure" ; "IBSS" = "Ad-hoc" }
try { $Enumeration[$ConnectionType] } catch { Write-Warning "Unknown connection type: $($ConnectionType)" }
}
function Get-EapTypeName {
param([string]$MethodType)
if ([string]::IsNullOrEmpty($MethodType)) { return }
$Enumeration = @{ "13" = "EAP-TLS" ; "18" = "EAP-SIM" ; "21" = "EAP-TTLS" ; "23" = "EAP-AKA" ; "25" = "PEAP" ; "26" = "MS-EAP" ; "29" = "EAP-MSCHAP-V2" ; "50" = "EAP-AKA'" ; "55" = "TEAP" }
try { $Enumeration[$MethodType] } catch { "Unknown" }
}
function Get-CertificateName {
param([string]$Thumbprint)
if ([string]::IsNullOrEmpty($Thumbprint)) { ""; return }
$Certificate = Get-ChildItem "Cert:\LocalMachine\Root\$($Thumbprint.Replace(' ', ''))" -ErrorAction SilentlyContinue
if ($null -eq $Certificate) { "Unknown Certificate"; return }
($Certificate.Subject.Split(',')[0]).Split('=')[1]
}
function Get-AuthModeDescription {
param([string]$AuthMode)
if ([string]::IsNullOrEmpty($AuthMode)) { return }
$Enumeration = @{ "machineOrUser" = "Use user credentials when a user is logged on, use machine credentials otherwise." ; "machine" = "Use machine credentials only." ; "user" = "Use user credentials only." ; "guest" = "Use guest (empty) credentials only." }
try { $Enumeration[$AuthMode] } catch { "Unknown" }
}
function Get-ServerValidationPromptDescription {
param([boolean]$PromptDisabled)
if ($PromptDisabled) { "Authentication fails is the certificate is not trusted." } else { "The user can be prompted for server validation." }
}
function Get-ServerValidationDescription {
param([boolean]$PerformValidation)
if ($PerformValidation) { "Server validation is performed." } else { "Server validation is not performed." }
}
function Get-AcceptServerNameDescription {
param([boolean]$AcceptServerName)
if ($AcceptServerName) { "The server name is verified." } else { "The server name is not verified." }
}
function Get-UseWinLogonCredentialsDescription {
param([boolean]$UseWinLogonCredentials)
if ($UseWinLogonCredentials) { "EAP MS-CHAPv2 obtains credentials from winlogon." } else { "EAP MS-CHAPv2 obtains credentials from the user." }
}
function Get-TrustedRootCAs {
param([System.Xml.XmlElement]$Node, [string]$Name)
if ($null -eq $Node) { Write-Warning "$($MyInvocation.MyCommand.Name) | Input node is null."; return }
$TrustedRootCAs = $Node.GetElementsByTagName($Name) | ForEach-Object { $_.InnerText.Replace(" ", "") }
$TrustedRootCANames = $TrustedRootCAs | ForEach-Object { Get-CertificateName -Thumbprint $_ }
$Result = New-Object -TypeName PSObject
$Result | Add-Member -MemberType "NoteProperty" -Name "Thumbprints" -Value ($TrustedRootCAs -join ", ")
$Result | Add-Member -MemberType "NoteProperty" -Name "DisplayNames" -Value ($TrustedRootCANames -join ", ")
$Result
}
function Get-EapType {
param([System.Xml.XmlElement]$Node)
if ($null -eq $Node) { Write-Warning "$($MyInvocation.MyCommand.Name) | Input node is null."; return }
$EapTypeId = $(if ([string]::IsNullOrEmpty($Node.Type.InnerText)) { $Node.Type } else { $Node.Type.InnerText })
$Result = New-Object -TypeName PSObject
$Result | Add-Member -MemberType "NoteProperty" -Name "Id" -Value $EapTypeId
$Result | Add-Member -MemberType "NoteProperty" -Name "Name" -Value (Get-EapTypeName -MethodType $EapTypeId)
$Result
}
function Get-EapTlsConfig {
param([System.Xml.XmlElement]$Node)
if ($null -eq $Node) { Write-Warning "$($MyInvocation.MyCommand.Name) | Input node is null."; return }
$CredentialsSource = $(
if ($null -ne $Node.EapType.CredentialsSource.SmartCard) { "SmartCard" }
elseif ($null -ne $Node.EapType.CredentialsSource.CertificateStore) { "Certificate" }
)
$ServerValidationNode = $Node.EapType.ServerValidation
$ServerValidationDisablePrompt = ConvertTo-Boolean -Text $ServerValidationNode.DisableUserPromptForServerValidation
$AcceptServerName = ConvertTo-Boolean -Text $Node.EapType.AcceptServerName
$PerformServerValidation = ConvertTo-Boolean -Text $Node.EapType.PerformServerValidation
$TrustedRootCAs = Get-TrustedRootCAs -Node $ServerValidationNode -Name "TrustedRootCA"
$Result = New-Object -TypeName PSObject
$Result | Add-Member -MemberType "NoteProperty" -Name "CredentialsSource" -Value $CredentialsSource
$Result | Add-Member -MemberType "NoteProperty" -Name "ServerValidationDisablePrompt" -Value $ServerValidationDisablePrompt
$Result | Add-Member -MemberType "NoteProperty" -Name "ServerValidationDisablePromptDescription" -Value (Get-ServerValidationPromptDescription -PromptDisabled $ServerValidationDisablePrompt)
$Result | Add-Member -MemberType "NoteProperty" -Name "ServerValidationNames" -Value $ServerValidationNode.ServerNames
$Result | Add-Member -MemberType "NoteProperty" -Name "AcceptServerName" -Value $AcceptServerName