Code Monkey home page Code Monkey logo

broadlink-dissector's Introduction

broadlink-dissector

Wireshark LUA dissector for Broadlink protocol

Background

Everything has started with an RGBW Light bulb from Aliexpress. I configured the bulbs with their software and started using them, but since I alread had some sort of Home Assistant setup for few gadgets, I decided to search for other capabilities. Unfortunately these bulbs have never been mentioned anywhere else though. It was fairly easy to figure out, the bulbs are using Broadlink protocol to communicate.

Then I found broadlink-mqtt, a nice library which supports couple of Broadlink devices, but mine. Thanks to the blog and its very decent details of the protocol, I decided to write a Wireshark "plugin", so called dissector to see what kind of communication travels between my bulbs and the controller app in the hope to be able extend the broadlink-mqtt library to support my bulbs. And having them integrated with Home Assistant.

Wireshark supports dissectors written in C or in LUA languages. For me, LUA seemed to be easier to achieve the goal.

Pre-requisites

Since the Broadlink protol is based on AES128-CBC encryption, we need some kind of crypto library support. I chose luagcrypt. To install this library I followed these steps (please note, my development was done on macOS, but the principles are the same for Windows platform too)

  1. Wireshark requires Lua 5.2. By default I installed the most recent version from their website and unfortunately I received errors later and Wireshark was not able to load the library properly. So I followed the wiki page Install Lua 5.2 on Mac
  2. Then I added Luarocks
    1. Downloaded from https://luarocks.org/releases/luarocks-3.2.1.tar.gz
    2. After extraction, I run the command to install ./configure && make && make install
  3. I installed libgcrypt library via brew (brew install libgcrypt) which is the depencency of luagcrypt
  4. And finally cloned the luagcrypt library to complile
  5. After the successful luagcrypt library test, I just had to move the luagcrypt.so file to /usr/local/lib/lua/5.2/

Install

And just copied the dissector to ~/.local/lib/wireshark/plugins/broadlink.lua on the Mac

Usage

If everything went well, Wireshark will show the new plugin/dissector registered under About->Plugins

Ready to capture the communication.

Option 1: I have a DD-WRT router, so it was easy to install tcpdump on it and use the router for remote capture. The router is the central place where the traffic goes throuh, so it will "see" the whole communication.

The DHCP table showed me, the bulb got an IP address of 192.168.1.100 (it has been configured to my home network with the Android app I received from the manufacturer!)

So I just executed ssh [email protected] tcpdump -i any -s0 -w - "host 192.168.1.100" | /Applications/Wireshark.app/Contents/MacOS/Wireshark -k -i -

Option 2: From a rooted Android device, where the tcpdump is also available and can run the vendor's management application

adb shell su -c tcpdump -i any -s0 -w - "host 192.168.1.100" | /Applications/Wireshark.app/Contents/MacOS/Wireshark -k -i -

Analyze the captured packets and use the dissector

Let's look for the AES key. The first authentication is always done with the pre-set encryption keys and the client sends the auth request (command=0x65) to the device. The device responds back to this request and in the auth response (command=0x3e9) there is the AES key which is used in any further communication. To get to these packets, filter for these packets with broadlink.flags.command == 0x65 || broadlink.flags.command == 0x3e9.

image

If the AES key is successfully extracted from the payload, set it in the protocol preferences.

image

With the new AES key saved, the following packets can be decrypted. Now filter the capture for command/response (broadlink.flags.command == 0x6a || broadlink.flags.command == 0x3ee)

image

And see the response in the next packet

image

Conclusion

I have no other types of Broadlink device (such as RM2*, A1 etc), only these bulbs (devID: 0x60C8) so could not verify if the dissector works properly with other models, but I believe the plugin can be easily extended/modified for others.

Feel free to adjust, fork and use for your own benefit.

broadlink-dissector's People

Contributors

csabavirag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

xiangbinde

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.