Last week, I was working with a client on a web-filtering solution, using one of their organizations laptops. We happened to notice the long-long-LONG list of SSIDs that were on this machine, may of them open SSIDs. The host we were looking at had the default dlink and linksys SSIDs as auto-connect, so not a great situation. Coincidentally, this was the same day Xavier posted his diary about collecting this same information (the ssid list) from live machines (https://isc.sans.edu/forums/diary/How+was+your+stay+at+the+Hotel+La+Playa/22069/). It really seems like people still have a pathological need to connect up to free WiFi.
I got to thinking about how to collect this information in an Active Directory domain using PowerShell. Its quite easy for Windows 10, but not so much for Windows 7 clients. For the older environment case, I ended up falling back to:
netsh wlan show profiles to get the list of wireless profiles
netsh wlan show profiles name=PROFILENAME to get the details for the profile PROFILENAME
Combine that up with psexec (because psexec *always* works - well, almost always), and some text manipulation, and you have the code below.
Yes, I do know that this could have been done by pulling everything out of the registry, but in this case perfect is the enemy of done - I had a few clients who wanted this done quickly, and this approach got it done in that quickly time frame.
The resulting script will list all wireless profiles across an AD domain. I did have a test connection line in there, but enough organizations have ping disabled now that I took that out.
How to use this information? For most organizations, this is a chance to do some outreach, some end-user education about safer computing. In most cases, this means that we recommend that they tether to their phone rather than connect to random free SSIDs.
In a more security conscious environment, say if its a bank or if clearances are involved, what this can be used for is as a simple audit. In higher security shops, its more common to see Group Policy be used to say only this short list of SSIDs are permitted, where the list is the organizations real wireless networks, as well as (in some cases) a pre-configured cell phone tethered network.
As always, let us know how this code works out. There are a few errors Im still trying to suppress, and it can take quite a long time to run this, but the clients that Ive used this with have gotten good use out of the information.
The code (recommend PowerShell 4.0 or better):
$nodenets = @()
$domainmembers = get-adcomputer -filter *
foreach ($node in $domainmembers) {
$netlist = iex (./psexec /accepteula \\+$node.name + netsh wlan show profiles) 2./a | Select-String -Pattern :
if(($netlist -like *was not found*) -or ($netlist.length -eq 0)) { write-host No Wireless on host $node.name }
else {
write-host Assessing Wireless on host $node.name
foreach ($net in $netlist) {
[console]::write(.)
$netprf = ($net -split(: ))[1]
$cmd = ./psexec /accepteula \\+$node.name + netsh wlan show profiles name=+ `+$netprf+`
$netparmlist = iex $cmd 2./a
$netparmlist2 = $netparmlist | select-string -pattern : | select-string -pattern Applied -NotMatch | select-string -pattern Profile -NotMatch
$x = New-Object psobject
$x | add-member -membertype NoteProperty -name Node -Value $node.name
foreach($parm in $netparmlist2) {
$t1 = $parm -split :
$x | add-member membertype NoteProperty name ($t1[0].trim( ))
}
$nodenets += $x
}
}
}
$nodenets | select Node, Name, Connection Mode, SSID Name, Authentication, Cipher, Security Key | Out-GridView
(watch for updates over the next few days at https://github.com/robvandenbrink/opw )
width:724px" />
===============
Rob VandenBrink
Compugen