Skip to main content

Firmware Slap - Discovering Vulnerabilities In Firmware Through Concolic Analysis And Function Clustering

Firmware Slap - Discovering Vulnerabilities In Firmware Through Concolic Analysis And Function Clustering


Firmware slap combines concolic analysis with function clustering for vulnerability discovery and function similarity in firmware. Firmware slap is built as a series of libraries and exports most information as either pickles or JSON for integration with other tools.

Slides from the talk can be found here

Setup
Firmware slap should be run in a virtual environment. It has been tested on Python3.6
python setup.py install
You will need rabbitmq and (radare2 or Ghidra)
# Ubuntu
sudo apt install rabbitmq-server
# OSX
brew install rabbitmq
# Radare2
git clone https://github.com/radare/radare2.git
sudo ./radare2/sys/install.sh
# Ghidra
wget https://ghidra-sre.org/ghidra_9.0.4_PUBLIC_20190516.zip
unzip ghidra_9.0.4_PUBLIC_20190516.zip -d ghidra
echo "export PATH=\$PATH:$PWD/ghidra/ghidra_9.0.4/support" >> ~/.bashrc
If you want to use the Elastic search stuff run the Elasticsearch_and_kibana.sh script

Quickstart
Ensure rabbitmq-server is running.
# In a Separate terminal
celery -A firmware_slap.celery_tasks worker --loglevel=info
# Basic buffer overflow
Discover_And_Dump.py examples/iwconfig
# Command injection
tar -xvf examples/Almond_libs.tar.gz
Vuln_Discover_Celery.py examples/upload.cgi -L Almond_Root/lib/

Usage
# Get the firmware used for examples
wget https://firmware.securifi.com/AL3_64MB/AL3-R024-64MB
binwalk -Mre AL3-R024-64MB
Start a celery work from the project root directory:
# In a separate terminal
celery -A firmware_slap.celery_tasks worker --loglevel=info
In a different terminal window, run a vulnerability discovery job.
$ Vuln_Discover_Celery.py Almond_Root/etc_ro/lighttpd/www/cgi-bin/upload_bootloader.cgi -L Almond_Root/lib/
[+] Getting argument functions
[+] Analyzing 1 functions
0%| | 0/1 [00:01<?, ?it/s]
{ 'Injected_Location': { 'base': '0x7ffefde8',
........................ SNIP ......................
'type': 'Command Injection'}
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]:

The returned vulnerability object
The above command will return an object in the result variable. This is a dictionary will all sorts of awesome information about the vulnerability. There are three major keys in the object: The function arguments, The memory, and the injected location.
In [3]: result.keys()
Out[3]: dict_keys(['args', 'file_name', 'type', 'mem', 'Injected_Location'])

Args
The args key will detail information about the recovered argument and what the argument values must be to recreate the vulnerability. In the below example, one argument is recovered, and to trigger the command injection that argument must be a char* that contains "`reboot`" to trigger a reboot.
In [1]: result['args']
Out[1]:
[{'base': 'a1',
'type': 'int',
'value': "0x0 -> b'`reboot`\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x00'"}]

Memory
The memory component of the object keeps track of the required memory values set to trigger the vulnerability. It also offers stack addresses and .text addresses with the offending commands for setting the required memory constraints. The first memory event required is at mtd_write_firmware+0x0 and the second is at mtd_write_firmware+0x38. Assembly is provided to help prettify future display work.
In [2]: result['mem']
Out[2]:
[{'BBL_ADDR': '0x401138',
'BBL_DESC': {'DESCRIPTION': 'mtd_write_firmware+0x0 in upload_bootloader.cgi (0x401138)',
'DISASSEMBLY': ['0x401138:\tlui\t$gp, 0x42',
'0x40113c:\taddiu\t$sp, $sp, -0x228',
'0x401140:\taddiu\t$gp, $gp, -0x5e90',
'0x401144:\tlw\t$t9, -0x7f84($gp)',
'0x401148:\tsw\t$a2, 0x10($sp)',
'0x40114c:\tlui\t$a2, 0x40',
'0x401150:\tmove\t$a3, $a1',
'0x401154:\tsw\t$ra, 0x224($sp)',
'0x401158:\tsw\t$gp, 0x18($sp)',
'0x40115c:\tsw\t$a0, 0x14($sp)',
'0x401160:\taddiu\t$a1, $zero, 0x200',
'0x401164:\taddiu\t$a0, $sp, 0x20',
'0x401168:\tjalr\t$t9',
'0x40116c:\taddiu\t$a2, $a2, 0x196c']},
'DATA': "b'`reboot`\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01 \\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\ x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'",
'DATA_ADDRS': ['0x0']},
{'BBL_ADDR': '0x401170',
'BBL_DESC': {'DESCRIPTION': 'mtd_write_firmware+0x38 in upload_bootloader.cgi (0x401170)',
'DISASSEMBLY': ['0x401170:\tlw\t$gp, 0x18($sp)',
'0x401174:\tnop\t',
'0x401178:\tlw\t$t9, -0x7f68($gp)',
'0x40117c:\tnop\t',
'0x401180:\tjalr\t$t9',
'0x401184:\taddiu\t$a0, $sp, 0x20']},
'DATA': "b'/bin/mtd_write -o 0 -l 0 write `reboot`'",
'DATA_ADDRS': ['0x7ffefe07']}]

Command Injection Specific
Since command injections are the easiest to demo, I've created a convenience dictionary key to demonstrate the location of the command injection easily.
In [4]: result['Injected_Location']
Out[4]: {'base': '0x7ffefde8', 'type': 'char *', 'value': '/bin/mtd_write -o 0 -l 0 write `reboot`'}

Sample Vulnerability Cluster Script
The vulnerability cluster script will attempt to discover vulnerabilities using the method in the Sample Vulnerability Discovery script and then build k-means clusters of a set of given functions across an extracted firmware to find similar functions to vulnerable ones.
$ Vuln_Cluster_Celery.py -h
usage: Vuln_Cluster_Celery.py [-h] [-L LD_PATH] [-F FUNCTION] [-V VULN_PICKLE]
Directory
positional arguments:
Directory
optional arguments:
-h, --help show this help message and exit
-L LD_PATH, --LD_PATH LD_PATH
Path to libraries to load
-F FUNCTION, --Function FUNCTION
-V VULN_PICKLE, --Vuln_Pickle VULN_PICKLE
The below command takes -F as a known vulnerable function. -V as a dumped pickle from a previous run to not need to discover new vulnerabilites and -L for the library path. A sample usage:
$ python Vuln_Cluster_Celery.py -F mtd_write_firmware -L Almond_Root/lib/ Almond_Root/etc_ro/lighttpd/www/cgi-bin/
[+] Reading Files
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████& #9608;██████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 2.80it/s]
Getting functions from executables
Starting main
... Snip ...


Popular posts from this blog

[Apk Setup] Alpine-term App | without using termux

Install and Setup Alpine Term in Android App Welcome to the world of terminal and Linux environment on your Android device! 📲 In this blog post, we will guide you through the installation and setup process of Alpine Term, an amazing application that brings the power of Alpine Linux to your fingertips. Let's get started! 🚀 What is Alpine Term App? 🏔️ Alpine Term is a terminal and Linux environment application for Android. It utilizes Alpine Linux, running inside a headless x86_64 machine emulated with QEMU. The interaction with the operating system is done through terminals attached to the serial consoles of the virtual machine. This allows you to run commands, execute scripts, and experience a Linux environment on your Android device. System Requirements 📋 To install and use Alpine Term, make sure your device meets the following requirements: 📱 AArch64-based device. 🆙 Android 7.0 or higher. 💾 At least 500 MB of free space on the internal storage. 🌐 ...

Cloudflared in Termux to Create tunnels, Port Forwding

Step-by-Step Guide: Installing Cloudflared in Termux for Android (Alternative to ngrok) | 2024" J Link updated https://github.com/rajbhx/cloudflared-termux What is cloudflare Cloudflare, Inc. is an American content delivery network and DDoS mitigation company, founded in 2010. It acts as a reverse proxy between a website's visitor and the Cloudflare customer's hosting provider. Its headquarters are in San Francisco, California Usages cloudflared -url [localhost]:port_number] example : cloudflared -url localhost:8000 cloudflared tunnel localhost:[port_number] Installation Make sure your Termux app updated The commands you provided are the steps to install Cloudflared in Termux using the `rajbhx/cloudflared-termux` repository. Here's a breakdown of each command: 1. Update and upgrade packages:    ```    pkg update && pkg upgrade && pkg install git    ``` 2...

How to install and setup vShell in android app |कैसे इनस्टॉल करें

How to install and setup android vShell(Virtual Shell) app (no root) कैसे इनस्टॉल करें YouTube video link What is Android-vShell app vShell is a  virtual shell environment application  for the Android OS. A virtual Linux shell environment application for Android OS. Runs Alpine Linux in QEMU system emulator.  It provides a virtual machine running small Linux distribution ready for the use out-of-box. Application implements my view on how Linux terminal environments can look like on Android OS. As operating system security is getting more and more hardened over time (which is good btw), it become impossible to abuse design flaws such as executable user data to run Linux native executables. Ability to...

How to extract Details from any mobile number Using termux | rajbhx

How to extract Details from any mobile number | termux | jarvisstaraq.blogspot.com What is truecallerjs Truecallerjs : A simple package to search phone number details.this tool also work in android and Termux app jarvisstaraq.blogspot.com Requirements Android phone Termux Proper valid Mobile Number(Phone number verification for truecaller) Truecaller InstallationId jarvisstaraq.blogspot.com Installation in Termux Installing Node.js, Git, and Wget in Termux:  To install Node.js, Git, and Wget in Termux, follow these steps: 1. Open your Termux app. 2. Run the following command to update the package lists:     ```    pkg update    ``` 3. Next, install Node.js using the following command:    ```    pkg install nodejs    ``` 4. Install Git using the command:    ```    pkg install git    ``` 5. Lastly...

My Termux | How to install Lazymux in Termux #rajbhx

My Termux | How to install Lazymux in Termux Lazymux t00ls !nstaller !s very easy t0 use, 0nly pr0v!ded f0r lazy Termux users, just k!dd!ng. Lazymux !s a t00l that !s spec!ally made f0r Termux user wh!ch pr0v!des a l0t 0f t00l ma!nly used t00ls !n Termux, Lazymux !nstall any 0f the g!ven t00ls pr0v!ded by !t fr0m !tself w!th just 0ne cl!ck, and Lazymux always get updated.  What !s Python 3?   My Termux | How to install Lazymux in Termux @rajbhx How to Install Oh My Zsh How to download copyright free GAME PLAY CODM/PUBG/BGMI/FreeFire Call of duty mobile 60fps   How to install FacebookToolkit in Termux + linux + windows 10/11 Download any video with termux using youtube-dl | #rajbhx HOw to install Raspbian 9 (Stretch) in Termux #rajbhx On Decembe...

How to install & use report-fb-account-termux tool in termux

report-fb-account-termux   [+]  Disclaimer : This tool is only for educational purpose. The developer is not responsible for any abuse of it.   [+] Installation apt update && apt upgrade -y apt install git python -y git clone https://github.com/jarvisstar/report-fb-account-termux.git cd autoreport python3 ar.py Or, Use Single Command apt install git python -y && git clone https://github.com/KasRoudra/autoreport && cd autoreport && python3 ar.py Screenshots:   Usage: Search "findfbid" in google to get victim's profile link. Such as Website1 , Website2 , Website3 , Website4 . Enter the victim's facebook profile link in the website, generate and copy the numeric id in clipboard. Run the script and enter or paste that id when asked! [+] Note: AUTOREPORT DOES NOT DISABLE ACCOUNT UNLESS THERE IS SPECIFIC POST(S)...

How to install | instagram reporting 2 tool termux by jarvisstaraq

How to install | instagram reporting 2 tool termux by jarvisstaraq Assuming the client truly breaks the instagram rule then their is more opportunities to get prohibited. Instagram limits the reports per unit time, apparatus will auto quit revealing later arrived at limit at very nearly 40 reports. Shows "Detailed Succesfully" later Each Request. You can Report target again later some time (later 2-3 min). Use IP of same district for high effecivity. In the event that you enter invalid username it will in any case send report demand. Assuming that you getting mistake on utilizing intermediaries then, at that point, don't. Requirements Python3 Or Above  Need to install git in linux or termux Download GIT Usage Instagram mass reporter [ TERMUX ]  How to delete Instagram Account by mrwn007 Report tool Termux   [ TERMUX ]

How to Install Java (Open-JDK-8) in Termux | two Methods

How to Install Java (Open-JDK-8) in Termux Method 1: Java 8 Installation Introduction Install Java (Open-JDK-8) in Termux without rooting your Android device. Follow these steps to get Java up and running in your Termux environment. Step-by-Step Guide Step 1: Install Kali Linux in Termux (Optional) pkg install wget proot -y && wget https://raw.githubusercontent.com/MasterDevX/KaliTermux/master/InstallKali.sh && bash InstallKali.sh Step 2: Download OpenJDK-8-JRE Deb Package Visit ftp.debian and copy the link to the OpenJDK-8-JRE deb package. Step 3: Download Deb Package in Kali Machine wget http://ftp.debian.org/debian/pool/main/o/openjdk-8/openjdk-8-jre-headless_8u275-b01-1_arm64.deb Step 4: Install Deb Package Manually dpkg -i openjdk-8-jre-headless_8u275-b01-1_arm64.deb Step 5: Change Java Version (Optional) sudo update-alternatives --config java Final Step: Verify Java Version Select the desired Java version (in this case, Java 8) by typ...

How to delete Instagram Account by mrwn007 Report tool Termux

How to delete Instagram Account by mrwn007 Report tool Termux(Android) What is termux Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically - additional packages are available using the APT package manager. mrwn007 / 007spam-BOT Check out new updated repository Instagram mass reporter [ TERMUX ] Instagram Reporting 2 [ TERMUX ] Instagram delete new method by crevils [Termux] Why this tool not working:( Because this tool author removed all files and reposiory also just because this tool no working @__@ Installation  pkg install git pkg install python git clone https://github.com/mrwn007/007spam-BOT.git cd 007spam-BOT python3 -m pip install requests python3 bot.py this repo is dead for normal users to report in Ins...

🚀 The 2024 Java Developer Roadmap [UPDATED] 🚀

🚀 The 2024 Java Developer Roadmap [UPDATED] 🚀 Hello aspiring Java developers! 🌟 Welcome to the 2023 Java Developer Roadmap, a comprehensive guide designed to help you navigate your journey towards becoming a proficient Java professional. Whether you're just starting or looking to level up your Java skills, this roadmap will provide you with a clear path to success in the Java ecosystem. 🎉 Introduction Java, as a robust and versatile programming language, continues to be a leading choice for building enterprise-level applications, web services, mobile apps, and more. As we step into 2023, the Java landscape evolves, presenting exciting opportunities for developers like you. This updated Java Developer Roadmap encompasses years of expertise and industry insights to outline the key skills, tools, frameworks, libraries, and APIs that you should master to excel as a Java developer in 2023. 🔍 The Essentials Before diving into Java-specific to...