aki*_*uri 3 c# xml encryption wlanapi wifi
我使用的是 Windows 8.1,它没有工具(带有 GUI)来管理 wifi 网络配置文件。所以我正在写一篇对我有帮助的文章。我做了一些谷歌搜索并找到了Managed Wifi API,在教程的帮助下,我设法将这段代码放在一起:
foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
{
foreach (Wlan.WlanProfileInfo profileInfo in wlanIface.GetProfiles())
{
string profileName = profileInfo.profileName;
ListViewItem item = new ListViewItem(profileName);
string profileXML = wlanIface.GetProfileXml(profileInfo.profileName);
XmlDocument doc = new XmlDocument();
doc.LoadXml(profileXML);
var NSManager = new XmlNamespaceManager(doc.NameTable);
NSManager.AddNamespace("d", "http://www.microsoft.com/networking/WLAN/profile/v1");
XmlNode node = doc.DocumentElement.SelectSingleNode("//d:WLANProfile/d:MSM/d:security/d:authEncryption/d:authentication", NSManager);
item.SubItems.Add(node.InnerText);
Profiles.Items.Add(item);
}
}
Run Code Online (Sandbox Code Playgroud)
获取保存的网络配置文件列表并将它们打印在 ListView 上。我有两个问题。一是如何使用 Managed Wifi API 获取完整的个人资料信息?因为我唯一能得到的就是个人资料名称。网站上没有文档。
第二个问题是,由于无法使用API 获取完整的网络信息,因此我使用API以XML格式打印配置文件信息,然后解析XML并读取它。一个示例 XML:
<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>MEDO PUB</name>
<SSIDConfig>
<SSID>
<hex>4D45444F20505542</hex>
<name>MEDO PUB</name>
</SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>manual</connectionMode>
<MSM>
<security>
<authEncryption>
<authentication>WPA2PSK</authentication>
<encryption>AES</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey>
<keyType>passPhrase</keyType>
<protected>true</protected>
<keyMaterial>someReallyLongStringLike500+chars</keyMaterial>
</sharedKey>
</security>
</MSM>
</WLANProfile>
Run Code Online (Sandbox Code Playgroud)
我需要获取wifi密码,但我认为它是加密的。如何获取实际密码或解码加密密码?
更新:我发现了两个链接:Exposing the WiFi Password Secrets和[C++] Dump wireless passwords,但我不确定它们是否有效,或者更确切地说如何在 C# 中实现它们。
小智 7
正如我在评论中提到的,你可以用
netsh wlan show profiles
Run Code Online (Sandbox Code Playgroud)
然后
netsh wlan show profile "<a profile from the last step>" key=clear
Run Code Online (Sandbox Code Playgroud)
如果您仍想在代码中执行此操作,请继续阅读:
您使用的托管 WiFi API 没有此功能,但您可以轻松添加。
将 Interop.cs 中的 WlanProfileFlags 枚举修改为:
[Flags]
public enum WlanProfileFlags
{
/// <remarks>
/// The only option available on Windows XP SP2.
/// </remarks>
AllUser = 0,
GroupPolicy = 1,
User = 2,
GetPlaintextKey = 4
}
Run Code Online (Sandbox Code Playgroud)
将此函数添加到 WlanApi.cs 文件,可能靠近 GetProfileXml 函数(为了组织)。
/// <summary>
/// Gets the profile's XML specification. Key is unencrypted.
/// </summary>
/// <param name="profileName">The name of the profile.</param>
/// <returns>The XML document.</returns>
public string GetProfileXmlUnencrypted(string profileName)
{
IntPtr profileXmlPtr;
Wlan.WlanProfileFlags flags = Wlan.WlanProfileFlags.GetPlaintextKey;
Wlan.WlanAccess access;
Wlan.ThrowIfError(
Wlan.WlanGetProfile(client.clientHandle, info.interfaceGuid, profileName, IntPtr.Zero, out profileXmlPtr, out flags, out access));
try
{
return Marshal.PtrToStringUni(profileXmlPtr);
}
finally
{
Wlan.WlanFreeMemory(profileXmlPtr);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以调用此函数来获取未加密的密钥。
我还没有测试过这个,但它应该可以工作。如果您有任何问题,请告诉我。
| 归档时间: |
|
| 查看次数: |
6845 次 |
| 最近记录: |