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

    Greetings, colleagues!
    Many of you who develop applications for mobile platforms on iOS have encountered the problem of the inaccessibility of many key data.
    One of these parameters is the current encryption mode in a Wi-Fi network.
    Since this parameter can obviously be obtained only in an "illegal" way through the Private Framework, it is considered that it is impossible to recognize it using 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 cannot really be obtained. But it is quite simply obtained by "secondary sexual characteristics."
    Of course, you paid attention to the fact that the moment of connecting to the network with messages of this kind is logged in the logs of your device:

    Oct  5 11:37:58 ISOX-iPhone kernel[0] : 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 kernel with a debug level. It contains the necessary parameter "encryption", which determines the current encryption mode.
    Accordingly, our task is to receive this message and process inside the program using legal methods.

    To do this, we need to work with ASL iOS system (do not forget about #import)

            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 “Time” parameter will be correct.
    The problem is resolved: you have the value of the current encryption mode. Getting it from the Message line is easy.
    The next legitimate question is what does it mean?
    To do this, it was necessary to conduct a small search on the source codes of drivers for Wi-Fi devices.
    The decoding of the values ​​is as follows (when translating the value into a decimal 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, this is not without drawbacks: the message lifetime 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.

    Also popular now: