📜 ⬆️ ⬇️

Method for determining Wi-Fi encryption mode on iOS 5. *

Greetings, colleagues!
Many of you who develop applications for mobile platforms on iOS, faced with the problem of inaccessibility of many key data.
One of these parameters is the current encryption mode in the Wi-Fi network.
Since this parameter can obviously be obtained only in an “illegal” way through the Private Framework, it is considered that it cannot be known by its standard methods.
This is not true. I want to show you a workaround running on iOS 5 ( but closed, alas, on iOS6 ).


The reality is that programmatically this parameter really cannot be obtained. But it is quite simply obtained by "secondary sexual characteristics."
Of course, you paid attention to the fact that the logs of your device are logged when you connect to the network with messages of this type:

Oct 5 11:37:58 ISOX-iPhone kernel[0] <Debug>: 023881.292007 wlan.N[2599] AppleBCMWLAN Joined BSS: @ 0x80eb1400, BSSID = some_mac_address, rssi = -30, rate = 54 (100%), channel = 3, encryption = 0x8, ap = 1, failures = 0, age = 0, ssid[ 6] = "pretty_ssid" 

')
As you can see, this is an ASL message sent by a “kernel” with a “debug” level. It contains the necessary “encryption” parameter, which determines the current encryption mode.
Accordingly, our task is to receive this message and process it within the program by legal methods.

To do this, we need to work with ASL with iOS (do not forget about #import <asl.h> ).

  aslmsg asl, message; aslresponse searchResult; int i; const char *key, *val; NSMutableArray *result_dicts = [NSMutableArray array]; //    ASL asl = asl_new(ASL_TYPE_QUERY); if (!asl) { NSLog(@"Failed creating ASL query"); } //      asl_set_query(asl, "Sender", "kernel", ASL_QUERY_OP_EQUAL); //      asl_set_query(asl, "Message", "AppleBCMWLAN Joined BSS:", ASL_QUERY_OP_PREFIX|ASL_QUERY_OP_EQUAL); searchResult = asl_search(NULL, asl); while (NULL != (message = aslresponse_next(searchResult))) { NSMutableDictionary *tmpDict = [NSMutableDictionary dictionary]; for (i = 0; (NULL != (key = asl_key(message, i))); i++) { NSString *keyString = [NSString stringWithUTF8String:(char *)key]; val = asl_get(message, key); NSString *string = [NSString stringWithUTF8String:val]; [tmpDict setObject:string forKey:keyString]; } //    [result_dicts addObject:tmpDict]; } aslresponse_free(searchResult); asl_free(asl); 


In the results you will get an array of dictionaries of the form:

 { ASLMessageID = 723; Facility = kern; Level = 7; Message = "AppleBCMWLAN Joined BSS: @ 0xc1985200, BSSID = some_mac_address, rssi = -42, rate = 54 (100%), channel = 3, encryption = 0x8, ap = 1, failures = 0, age = 1, ssid[ 6] = \"pretty_ssid\""; PID = 0; Sender = kernel; Time = 1349423438; } 

The last message, sorted by the parameter "Time", will be correct.
Problem solved: you have the value of the current encryption mode. Getting it from the Message line is easy.
The next logical question is what does it mean?
To do this, it was necessary to make a small search in the source codes of Wi-Fi device drivers.
The decoding of values ​​is as follows (when converting a value to decimal numbering system):

 case 0: "None" case 1: "WEP" case 2: "WPA" case 4: "WPA PSK" case 6: "WPA2" case 8: "WPA2 PSK" case 10: "LEAP" case 12: "80211X" case 14: "WPS" 


The problem is solved, - the value of network encryption is obtained without using the Private Framework.
Of course, it is not without its drawbacks: the lifetime of messages is rather short and constant monitoring of ASL is required.

Unfortunately, Apple closed access to kernel log messages on the 6th firmware. Well, you have to look for a new way.

Thanks for attention. I hope I told you something interesting.

Source: https://habr.com/ru/post/153699/


All Articles