未加星标

View passwords of wireless profiles without using netsh.exe

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二05 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Ever since the GUI lost the ability to view the password of a wireless profile, I wanted to provide this functionality in PowerShell. A search of the Internet for how to view the password of a Wi-Fi profile returns numerous examples of how to use netsh.exe to accomplish this. I wrote a previousblog post about how to view Wi-Fi profiles, and the method I used returned objects, but still relied on netsh.exe. I had some free time, and I wanted to learn about p/invoke, so I wrote a PowerShell module to do this.

Let’s look at how to do this without netsh. If there isn’t a cmdlet or method in .NET to get what you want, the next step is to look at native (Win32) APIs. As luck would have it, there is aNative WiFi API that has a function for everything you need . Let me back up a bit. A native API is unmanaged code. PowerShell is managed code. For managed code to call unmanaged code, you need to leverage Platform Invocation Services or P/Invoke. This is easily done in PowerShell. All we need is a C# signature that defines a class that renames the C++ types to their C# equivalents and the Add-Type cmdlet.

The C# signatures can be obtained by using pinvoke.net as previously explained byBoe Prox. Here is the signature for the WlanGetProfile function.


View passwords of wireless profiles without using netsh.exe

I found it very helpful to look at the MSDN documentation for the function that I wanted to use. MSDN explains the parameters of the function and how the function can be used. The MSDN documentation forWlanGetProfile function is very thorough.

Another note, in my experience some of the signature will work by just copying from pinvoke.net, and others needs some trial-and-error. However, after you understand the concept of a signature and how it’s used, you will be able to adapt it to your scenario. I often found myself searching for the C# equivalents of the C++ types because I would get an error that would say something like “cannot convert DWord to type of Foo”, or something along those lines. After you get a working signature and see your happy new type in the PowerShell console, you will smile.


View passwords of wireless profiles without using netsh.exe

Here is the WiFiProfileManagement module in action. At the time of this blog writing, WifiProfileManagement as four cmdlets ( Get , Set , New , and Remove-WiFiProfile ). Let’s take a look at Get-WifiProfile. If I run Get-WiFiProfile without parameters, it will return all the WiFi profiles on my computer.


View passwords of wireless profiles without using netsh.exe

The Password property is blank. If we want to look at the Password, we must use the ClearKey switch.


View passwords of wireless profiles without using netsh.exe

It’s a lot easier than using netsh.exe. You can review the WiFiProfileManagement in it’s entirety on Github .

Jason Walker

Senior Consultant

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

主题: PowerShellC#SDNC++GitWiFiWord
分页:12
转载请注明
本文标题:View passwords of wireless profiles without using netsh.exe
本站链接:http://www.codesec.net/view/524529.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(47)