首页
社区
课程
招聘
Dump wireless passwords
发表于: 2013-11-8 10:38 5083

Dump wireless passwords

2013-11-8 10:38
5083
此应用程序不是破解密码或者破解无线网络,只是读取本机上已经连接的无线网络密码。
代码:
#ifndef WLAN_PROFILE_GET_PLAINTEXT_KEY
#define WLAN_PROFILE_GET_PLAINTEXT_KEY 4 // Dont have the latest platform SDK on this box
#endif

#pragma comment(lib, "wlanapi.lib")

#include <stdio.h>
#include <windows.h>
#include <wlanapi.h>

BOOL IsElevated()
{
	DWORD dwSize = 0;
	HANDLE hToken = NULL;
	BOOL bReturn = FALSE;

	TOKEN_ELEVATION tokenInformation;
	
	if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
		return FALSE;

	if(GetTokenInformation(hToken, TokenElevation, &tokenInformation, sizeof(TOKEN_ELEVATION), &dwSize))
	{
		bReturn = (BOOL)tokenInformation.TokenIsElevated;
	}

	CloseHandle(hToken);
	return bReturn;
}

bool IsVistaOrHigher()
{
	OSVERSIONINFO osVersion; ZeroMemory(&osVersion, sizeof(OSVERSIONINFO));
	osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	
	if(!GetVersionEx(&osVersion))
		return false;

	if(osVersion.dwMajorVersion >= 6)
		return true;
	return false;
}

int main(int argc, char *argv[])
{
	HANDLE hWlan = NULL;

	DWORD dwError = 0;
	DWORD dwSupportedVersion = 0;
	DWORD dwClientVersion = (IsVistaOrHigher() ? 2 : 1);

	GUID guidInterface; ZeroMemory(&guidInterface, sizeof(GUID));
	
	WLAN_INTERFACE_INFO_LIST *wlanInterfaceList = (WLAN_INTERFACE_INFO_LIST*)WlanAllocateMemory(sizeof(WLAN_INTERFACE_INFO_LIST));
	ZeroMemory(wlanInterfaceList, sizeof(WLAN_INTERFACE_INFO_LIST));
	
	WLAN_PROFILE_INFO_LIST *wlanProfileList = (WLAN_PROFILE_INFO_LIST*)WlanAllocateMemory(sizeof(WLAN_PROFILE_INFO_LIST));
	ZeroMemory(wlanProfileList, sizeof(WLAN_PROFILE_INFO_LIST));

	if(!IsElevated()) printf("[!] Running without administrative rights\n");
	try
	{
		if(dwError = WlanOpenHandle(dwClientVersion, NULL, &dwSupportedVersion, &hWlan) != ERROR_SUCCESS)
			throw("[x] Unable access wireless interface");

		if(dwError = WlanEnumInterfaces(hWlan, NULL, &wlanInterfaceList) != ERROR_SUCCESS)
			throw("[x] Unable to enum wireless interfaces");
		
		if(wlanInterfaceList->dwNumberOfItems == 0) // Almost missed this before posting
			throw("[x] No wireless adapters detected");

		if(dwError = WlanGetProfileList(hWlan, &guidInterface, NULL, &wlanProfileList) != ERROR_SUCCESS)
			throw("[x] Unable to get profile list");
		
		LPWSTR profileXML;

		printf("\nNetwork\t\t\t\t\tPassword\n\n");
		for(int i = 0; i < wlanProfileList->dwNumberOfItems; i++)
		{
			DWORD dwFlags = WLAN_PROFILE_GET_PLAINTEXT_KEY, dwAccess = 0;

			wprintf(L"%s", wlanProfileList->ProfileInfo[i].strProfileName);
			int j = 20 - wcslen(wlanProfileList->ProfileInfo[i].strProfileName);

			for(int k = 0; k < j; k++)
				printf(" ");

			if(IsElevated())
			{
				if(WlanGetProfile(hWlan, &guidInterface, wlanProfileList->ProfileInfo[i].strProfileName,
								  NULL, &profileXML, &dwFlags, &dwAccess) == ERROR_SUCCESS)
				{

					// This is really half assed but I'm really hungover
					WCHAR *pszStr = wcstok(profileXML, L"<>");
					while(pszStr) {
						if(!wcscmp(pszStr, L"keyMaterial")) {
							pszStr = wcstok(NULL, L"<>"); 
							wprintf(L"\t\t\t%s\n", pszStr);
							break;
						}
						pszStr = wcstok(NULL, L"<>");
					}
					WlanFreeMemory(profileXML);
				} 
			}
			else
			{
				printf("\t\t\tAccess Denied.\n");
			}
		}

	}
	catch(char *szError)
	{
		printf("%s (0x%X)\nQuitting...\n", szError);
	}

	if(wlanProfileList)
		WlanFreeMemory(wlanProfileList);
	if(wlanInterfaceList)
		WlanFreeMemory(wlanInterfaceList);
	if(hWlan)
		WlanCloseHandle(hWlan, NULL);

	return dwError;
}


demo:

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

上传的附件:
收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 144
活跃值: (335)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
收藏 测试下 谢谢分享
2013-11-8 10:50
0
雪    币: 26
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
在xp下使用时候,为什么还要提示需要管理员权限呢?
2013-11-8 10:58
0
雪    币: 185
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
windows的无线是可以直接显示出来的吧。 这种代码按说很少场合会用得上。 除非是收集个人信息的
2013-11-8 11:20
0
雪    币: 238
活跃值: (55)
能力值: ( LV5,RANK:70 )
在线值:
发帖
回帖
粉丝
5
有码,收藏
2013-11-8 13:09
0
雪    币: 357
活跃值: (3448)
能力值: ( LV3,RANK:25 )
在线值:
发帖
回帖
粉丝
6
[x] Unable to get profile list (0x405287)
Quitting...
2013-11-8 13:21
0
游客
登录 | 注册 方可回帖
返回
//