This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 134
/
Get-WLANProfile.ps1
164 lines (134 loc) · 4.63 KB
/
Get-WLANProfile.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
###############################################################################################################
# Language : PowerShell 5.0
# Filename : Get-WLANProfile.ps1
# Autor : BornToBeRoot (https://github.com/BornToBeRoot)
# Description : Get WLAN profiles, include password as SecureString or as plain text
# Repository : https://github.com/BornToBeRoot/PowerShell
###############################################################################################################
<#
.SYNOPSIS
Get WLAN profiles, include password as SecureString or as plain text
.DESCRIPTION
Get WLAN profiles on your local system, include Name, SSID, Authentication and Password as secure string or plain text. You don't need an additional application, which is full of advertising. And for learning purposes it shows, how easy it is to find out the WLAN password, if you have physical/remote access to the computer.
All this just by parsing the output of netsh.exe, which can be called without admin permissions.
.EXAMPLE
Get-WLANProfile
Name SSID Authentification Password
---- ---- --------------- ------
MyHomeNetwork01 MyHomeNetwork WPA2-Personal System.Security.SecureString
MyHomeNetwork02 MyHomenetwork5G WPA2-Personal System.Security.SecureString
.EXAMPLE
Get-WLANProfile -ShowPassword
Name SSID Authentification Password
---- ---- --------------- ------
MyHomeNetwork01 MyHomeNetwork WPA2-Personal MyPassword123456789
MyHomeNetwork02 MyHomenetwork5G WPA2-Personal MyPassword987654321
.LINK
https://github.com/BornToBeRoot/PowerShell/blob/master/Documentation/Function/Get-WLANProfile.README.md
#>
function Get-WLANProfile
{
[CmdletBinding()]
param(
[Parameter(
Position=0,
HelpMessage='Indicates that the password appears in plain text')]
[Switch]$ShowPassword,
[Parameter(
Position=1,
HelpMessage='Filter WLAN-Profiles by Name or SSID')]
[String]$Search,
[Parameter(
Position=2,
HelpMessage='Exact match, when filter WLAN-Profiles by Name or SSID')]
[Switch]$ExactMatch
)
Begin{
}
Process{
# Get all WLAN Profiles from netsh
$Netsh_WLANProfiles = (netsh WLAN show profiles)
# Some vars to filter netsh results
$IsProfile = 0
$WLAN_Names = @()
# Filter result and get the wlan profile names
foreach($Line in $Netsh_WLANProfiles)
{
if((($IsProfile -eq 2)) -and (-not([String]::IsNullOrEmpty($Line))))
{
$WLAN_Names += $Line.Split(':')[1].Trim()
}
if($Line.StartsWith("---"))
{
$IsProfile += 1
}
}
# Get details from every wlan profile, using the name (ssid/password/authentification/etc.)
foreach($WLAN_Name in $WLAN_Names)
{
$Netsh_WLANProfile = (netsh WLAN show profiles name="$WLAN_Name" key=clear)
# Counter to filter netsh result... (useful for multiple languages / split would only work for one language )
$InProfile = 0
$IsConnectivity = 0
$IsSecurity = 0
foreach($Line in $Netsh_WLANProfile)
{
if((($InProfile -eq 2)) -and (-not([String]::IsNullOrEmpty($Line))))
{
if($IsConnectivity -eq 1)
{
$WLAN_SSID = $Line.Split(':')[1].Trim()
$WLAN_SSID = $WLAN_SSID.Substring(1,$WLAN_SSID.Length -2)
}
$IsConnectivity += 1
}
if((($InProfile -eq 3)) -and (-not([String]::IsNullOrEmpty($Line))))
{
if($IsSecurity -eq 0) # Get the authentication mode
{
$WLAN_Authentication = $Line.Split(':')[1].Trim()
}
elseif($IsSecurity -eq 3) # Get the password
{
$WLAN_Password_PlainText = $Line.Split(':')[1].Trim()
}
$IsSecurity += 1
}
if($Line.StartsWith("---"))
{
$InProfile += 1
}
}
# As SecureString or plain text
if($ShowPassword)
{
$WLAN_Password = $WLAN_Password_PlainText
}
else
{
$WLAN_Password = ConvertTo-SecureString -String "$WLAN_Password_PlainText" -AsPlainText -Force
}
# Built the custom PSObject
$WLAN_Profile = [pscustomobject] @{
Name = $WLAN_Name
SSID = $WLAN_SSID
Authentication = $WLAN_Authentication
Password = $WLAN_Password
}
# Add the custom PSObject to the array
if($PSBoundParameters.ContainsKey('Search'))
{
if((($WLAN_Profile.Name -like $Search) -or ($WLAN_Profile.SSID -like $Search)) -and (-not($ExactMatch) -or ($WLAN_Profile.Name -eq $Search) -or ($WLAN_Profile.SSID -eq $Search)))
{
$WLAN_Profile
}
}
else
{
$WLAN_Profile
}
}
}
End{
}
}