June 19, 2018

CVE Number

Summary

Multiple exploitable buffer overflow vulnerabilities exist in the PubNub message handler for the "cc" channel of Insteon Hub running firmware version 1012. Specially crafted commands sent through the PubNub service can cause a buffer overflow on a global section overwriting arbitrary data. An attacker should send an authenticated HTTP request to trigger this vulnerability.

Tested Versions

Insteon Hub 2245-222 - Firmware version 1012

Product URLs

CVSSv3 Score

CWE

Details

Insteon produces a series of devices aimed at controlling and monitoring a home: wall switches, led bulbs, thermostats, cameras, etc.
One of those is Insteon Hub, a central controller which allows an end-user to use his smartphone to connect to his own house remotely and manage any other device through it.
The Insteon Hub board utilizes several MCUs, the firmware in question is executed by a Microchip PIC32MX MCU, which has a MIPS32 architecture.

The firmware uses Microchip's "Libraries for Applications" as core for the application code.
Its functionality resides on a co-operative multitasking loop, which continuously executes all the existing tasks: the library already defines several tasks, e.g. for reading and sending network packets and calling the relative callbacks.
Custom applications building on this library simply need to add new functions at the end of the loop, taking care of executing tasks as quickly as possible, or splitting them in several loop cycles, in order to let other tasks running smoothly.

To enable remote interaction via the Internet, Insteon Hub uses an online service called PubNub (https://www.pubnub.com/).
End-users install the "Insteon for Hub" application on their smartphone. Both the smartphone application and Insteon Hub include the PubNub SDK, which allows for a bi-directional communication using PubNub's REST API.

The interaction with PubNub happens by means of publish/subscribe methods. Each device has a series of channels it can subscribe to, in order to receive published messages.
To subscribe to a specific channel it's enough to call the function pubnub_subscribe (defined in the PubNub SDK), passing as parameter the channel name and a callback function that will be called when a message is received on the specified channel.

The device defines a function which parses messages received from PubNub on channel "cc": sub_9d014b1c. The function uses the cJSON library for parsing "JSON" messages and receives a cJSON object as parameter, which corresponds to the message sent from an authenticated smartphone application.
As an example, this is a valid JSON message which is used to set the volume on "sonos" speakers connected to Insteon Hub:

The function initially checks the cmd parameter, and depending on that it proceeds to extract other expected parameters, in this case sn_sonos_cmd and volume. The information is then either cached to be handled on the next multitasking loop, or immediately applied from within the current function.

The vulnerable code exists while parsing any JSON element, the example below follows the disassembly of the path for the "s_sonos" command:

The src parameter for strcpy at [1] is unconstrained, and can lead to a buffer overflow on the global section in RAM. In the example above the overflow happens on the global_s_vol variable which is at 0xa0001700 [2].
This same sequence of vulnerable instructions is present for every supported keyword in the message handler.

To send a message, an HTTP GET should be used which embeds the JSON string in the "path" portion of the URL:

$ curl https://pubsub.pubnub.com/publish/<pub>/<sub>/<callback>/<channel>/<payload>?auth=<auth-key>
<pub>: PubNub's publishKey. The device uses pub-c-a415cc66-b0ca-4d1d-8d9e-947390b35df3
<sub>: PubNub's subscribeKey. The device uses sub-c-e1c54032-1685-11e4-b69f-02ee2ddab7fe
<callback>: can be set to 0
<channel>: composed by "<insteon-id>-<channel-suffix>". <insteon-id> corresponds to the lower 3 octets of the MAC address and <channel-suffix> is the actual channel name, in this case "cc" (example of full channel name: 112233-cc)
<payload>: contains the JSON message string, the minimal JSON for Insteon is {"ser":""}
<auth-key>: key for access control, 16 bytes hex-encoded

The following is a list of vulnerable strcpy calls and their Proof-of-Concept.
Each PoC shows only the payload portion of the request and uses the placeholder "OVERFLOW" to highlight the vulnerable parameter, which can be replaced with "A"*0x400 to make the device crash.
All buffer overflows happen on a global section in RAM, defined from 0xa0000000 to 0xa001ffff, so they allow for overwriting global objects used both by custom and Microchip's library code.
A key with value "x" means that its value is irrelevant.

CVE-2017-16338 - cmd UpdateCheck, host key

At 0x9d01bad0 the value for the host key is copied using strcpy to the buffer at 0xa00016e0.
This buffer is 32 bytes large, sending anything longer will cause a buffer overflow.

{"cmd": "UpdateCheck", "host": "OVERFLOW"}

In this case the device won't crash right away since the overwritten global structures are not normally used.
Some of the structures are related to TCP networking functionality. To trigger the crash it is thus enough to connect to the device on any TCP port.

CVE-2017-16339 - cmd UpdateCheck, uri key

At 0x9d01bb1c the value for the uri key is copied using strcpy to the buffer at 0xa00016a0.
This buffer is 64 bytes large, sending anything longer will cause a buffer overflow.

{"cmd": "UpdateCheck", "host": "x", "uri": "OVERFLOW"}

CVE-2017-16340 - cmd ssonos, sdport key

At 0x9d01c0e8 the value for the s_dport key is copied using strcpy to the buffer at 0xa000180c.
This buffer is 6 bytes large, sending anything longer will cause a buffer overflow.

{"cmd": "s_sonos", "sn_discover": "0", "s_dport": "OVERFLOW"}

Note: In place of the cmd s_sonos, it's also possible to use g_sonos_players, g_sonos_preset, g_sonos_metadata, g_sonos_groups, g_sonos_bindex, g_sonos_vol.

Note: sn_discover needs to be a hex number lower than 0x100.

CVE-2017-16341 - cmd ssonos, svol_play key

At 0x9d01c224 the value for the s_vol_play key is copied using strcpy to the buffer at 0xa0000418.
This buffer is maximum 8 bytes large (this is the maximum size it could be, it is possible other global variables are stored between this variable and the next one that we could identify), sending anything longer will cause a buffer overflow.

{"cmd": "s_sonos", "s_vol_play": "OVERFLOW"}

Note: In place of the cmd s_sonos, it's also possible to use g_sonos_players, g_sonos_preset, g_sonos_metadata, g_sonos_groups, g_sonos_bindex, g_sonos_vol.

CVE-2017-16342 - cmd ssonos, svoldimdelta key

At 0x9d01c254 the value for the s_vol_dim_delta key is copied using strcpy to the buffer at 0xa0000514.
This buffer is 4 bytes large, sending anything longer will cause a buffer overflow.

{"cmd": "s_sonos", "s_vol_dim_delta": "OVERFLOW"}

Note: In place of the cmd s_sonos, it's also possible to use g_sonos_players, g_sonos_preset, g_sonos_metadata, g_sonos_groups, g_sonos_bindex, g_sonos_vol.

CVE-2017-16343 - cmd ssonos, svolbrtdelta key

At 0x9d01c284 the value for the s_vol_brt_delta key is copied using strcpy to the buffer at 0xa0000510.
This buffer is 4 bytes large, sending anything longer will cause a buffer overflow.

{"cmd": "s_sonos", "s_vol_brt_delta": "OVERFLOW"}

Note: In place of the cmd s_sonos, it's also possible to use g_sonos_players, g_sonos_preset, g_sonos_metadata, g_sonos_groups, g_sonos_bindex, g_sonos_vol.

CVE-2017-16344 - cmd ssonos, surl key

At 0x9d01c2c8 the value for the s_url key is copied using strcpy to the buffer at 0xa0001a0c.
This buffer is 16 bytes large, sending anything longer will cause a buffer overflow.
The destination can also be shifted by using an sn_speaker parameter between "0" and "3".

{"cmd": "s_sonos", "s_url": "OVERFLOW"}

Note: In place of the cmd s_sonos, it's also possible to use g_sonos_players, g_sonos_preset, g_sonos_metadata, g_sonos_groups, g_sonos_bindex, g_sonos_vol.

CVE-2017-16345 - cmd ssonos, sport key

At 0x9d01c318 the value for the s_port key is copied using strcpy to the buffer at 0xa00017f4.
This buffer is 6 bytes large, sending anything longer will cause a buffer overflow.
The destination can also be shifted by using an sn_speaker parameter between "0" and "3".

{"cmd": "s_sonos", "s_port": "OVERFLOW"}

Note: In place of the cmd s_sonos, it's also possible to use g_sonos_players, g_sonos_preset, g_sonos_metadata, g_sonos_groups, g_sonos_bindex, g_sonos_vol.

CVE-2017-16346 - cmd ssonos, smac key

At 0x9d01c368 the value for the s_mac key is copied using strcpy to the buffer at 0xa000170c.
This buffer is 25 bytes large, sending anything longer will cause a buffer overflow.
The destination can also be shifted by using an sn_speaker parameter between "0" and "3".

{"cmd": "s_sonos", "s_mac": "OVERFLOW"}

Note: In place of the cmd s_sonos, it's also possible to use g_sonos_players, g_sonos_preset, g_sonos_metadata, g_sonos_groups, g_sonos_bindex, g_sonos_vol.

CVE-2017-16347 - cmd ssonos, svol key

At 0x9d01e7d4 the value for the s_vol key is copied using strcpy to the buffer at 0xa0001700.
This buffer is maximum 12 bytes large (this is the maximum size it could be, it is possible other global variables are stored between this variable and the next one that we could identify), sending anything longer will cause a buffer overflow.

{"cmd": "s_sonos", "sn_sonos_cmd": "volume", "s_vol": "OVERFLOW"}

Note: In place of the cmd s_sonos, it's also possible to use g_sonos_players, g_sonos_preset, g_sonos_metadata, g_sonos_groups, g_sonos_bindex, g_sonos_vol.