SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
Reverse-enigneering embedded
         MIPS devices
   Case study: Draytek SOHO routers


            Nikita Abdullin
         nabdullin@gmail.com

              25.11.2011
Reverse-enigneering embedded MIPS
              devices
Embedded systems: overview

Firmware research

MIPS: Introduction

MIPS: Reversing and exploitation

Case study: DrayTek SOHO routers
Reverse-enigneering embedded MIPS
              devices
Embedded systems: overview

Firmware research

MIPS: Introduction

MIPS: Reversing and exploitation

Case study: DrayTek SOHO routers
Embedded systems: overview
•   Everywhere: mobile, media, CPE, …
•   High level of integration: mostly SoC
•   Compact size, low power consumption
•   ARM, MIPS, xScale, …
•   A real challenge for a reverser
    – Variety of models
    – Variety of architectures, conventions and APIs
    – Lack of information
Embedded systems: overview
Why ever reverse a MIPS box ?
• Ubiquitous devices – especially network & CPE
• A well-known RISC platform
• Surprisingly, a little of security research:
Reverse-enigneering embedded MIPS
              devices
Embedded systems: overview

Firmware research

MIPS: Introduction

MIPS: Reversing and exploitation

Case study: DrayTek SOHO routers
Firmware research
Firmware – how to get it?
• Download from device …
  – JTAG
  – Serial / UART console / other ports
  – read EEPROM directly, etc.
• … or simply find a firmware upgrade
  – Single file, several MB’s in size
  – Encrypted / compressed
Firmware research
Typical firmware binary:
• Bootloader
• Code
• Filesystem image
How to extract them?
• Manual review
• Tools
Firmware research :: Tools
• Signature search
  – binwalk
  – signsrch, offzip
  – trid
• Scriptable hex editor
  – <Your favourite here>
• A set of archivers / unpackers
  – <Your favourite here>
• %script_lang_name%
Firmware research :: Manual review
•   Sequences of 0x00’s and 0xFF’s
•   First byte/word may be block size
•   Last byte/word may be block checksum
•   Magic signatures
•   Text strings
    – Extract, sort, guess and google
• Entropy
Firmware research :: Manual review
• Filesystem extraction
  – Use binwalk
  – Or look for magic headers
     •   JFFS2        = 85 19 (for FS nodes)
     •   cramfs       = 45 3D CD 28
     •   YAFFS        = 03 00 00 00 01 00 00 00 FF FF
     •   SquashFS     = "hsqs"
     •   VFAT, etc.   …
Reverse-enigneering embedded MIPS
              devices
Embedded systems: overview

Firmware research

MIPS: Introduction

MIPS: Reversing and exploitation

Case study: DrayTek SOHO routers
MIPS: Introduction
•   RISC ISA (instruction set architecture)
•   Fixed 4-byte length instructions
•   32-bit and 64-bit
•   Both big-endian and little-endian
•   Popular and even more promising with multi-
    core Loongson series from China
MIPS: registers
 Name      Number           Purpose
 $zero       $0            Const = 0
  $at        $1           Temporary
$v0—$v1     $2-$3        Return values
$a0—$a3     $4-$7        Function args
$t0—$t7    $8-$15         Temporary
$s0—$s7    $16-$23       Saved values
$t8—$t9    $24-$25        Temporary
$k0—$k1    $26-$27   Reserved for OS kernel
  $gp        $28         Global pointer
  $sp        $29         Stack pointer
  $fp        $30         Frame pointer
  $ra        $31        Return address
MIPS: delay slot
• MIPS is a pipelined architecture




• So not all instructions are safe to be executed
  right after others
   – branches & jumps (bne beq j jr jal)
   – Loads (lb lw ld)
MIPS: memory layout
MIPS: memory layout
Reverse-enigneering embedded MIPS
              devices
Embedded systems: overview

Firmware research

MIPS: Introduction

MIPS: Reversing and exploitation

Case study: DrayTek SOHO routers
MIPS: Reversing and exploitation
• objdump / disasmips / radare
• IDA
  – IDAPython
  – QEMU-MIPS
• MIPS emulator
  – SPIM
  – OVPsim
MIPS: Reversing and exploitation
• Delay slots
MIPS: Reversing and exploitation
• Finding code patterns
   –   03   E0   00   08   (jr $ra -- return)
   –   0C   xx   xx   xx   (jal)
   –   3C   xx   xx   xx   (load – lui, la, ...)
   –   1x   xx   xx   xx   (branches)
MIPS: Reversing and exploitation
• Finding more details about the target system is a key to
  understanding kernel procedures
14000000    14000FFF     external bus general purpose i/o
18000300    180003FF     general purpose timer
1E100400    1E1007FF     first serial port
...
1E103100    1E1031FF     hardware crypto
1E104100    1E1041FF     dma controller
1E105300    1E1053FF     external bus controller
1E105400    1E1057FF     PCI bus controller
1E116000    1E117000     DSL interface
1E180000    1E1BFFFF     ethernet controller
1F101000    1F101FFF     external interrupt controller
...
1F203000    1F203FFF     reset controller
1F880200    1F8802FF     interrupt controller
1F8803F0    1F8803FF     watchdog timer
MIPS: Reversing and exploitation
• Basic buffer overflow
  – Owerwrite the old $ra stored on stack
  – ret2libc
  –…
MIPS: Reversing and exploitation
• Exploitation is more difficult than on x86 and
  ARM
   –   Fixed-length instructions with a lot of ull bytes
   –   Word-aligned instructions (32 bit)
   –   Word-aligned memory words (32 bit)
   –   I-Cache vs. D-Cache (exploit has no effect, data &
       code is read & executed from cache)
• But protection techniques are still rather new
   – ASLR (MIPS Linux > 2.6.23)
   – Stack canaries (GCC > 4.5)
   – W ^ X not standardized and rarely implemented
Reverse-enigneering embedded MIPS
              devices
Embedded systems: overview

Firmware research

MIPS: Introduction

MIPS: Reversing and exploitation

Case study: DrayTek SOHO routers
Case study: DrayTek SOHO routers
Case study: DrayTek SOHO routers
• DrayTek Vigor V2xxx series – network devices
  – Over 35 models, widely deployed by ISP’s over
    Australia, Germany, UK
     • Routers
     • ADSL-modems
     • CPE & combo devices (dual wan + VoIP + … )
• MIPS and ARM platforms
  – POI: Infineon Danube-S (MIPS, dual-core, HW crypto)
• Proprietary closed-source OS: DrayOS
  – Single static non-relocatable binary
  – Capable of loading Linux drivers
Case study: DrayTek SOHO routers
• Router Web UI allows to download obviously
  obfuscated binary config for further reloading
• Firmware upgrades available from vendor, but
  they are compressed using unknown
  algorithm
• Rumours are that a master key based on MAC
  address exist
Case study: DrayTek SOHO routers
Research steps.
  1. Config file – decrypt
  2. UART console and debug menu
       1.   Firmware dumped through UART hexdump 100 bytes at a
            time 
  3.    Firmware reversing
  4.    Config file – decompress
  5.    Firmware – decompress
  6.    Filesystem – decompress & extract
  7.    Master password generation algorithm discovered
Config file
1. A way to get encrypted and unencrypted configs
   simultaneously was discovered
  1. Immediate result – a cipher used is definitely in ECB
     mode, bytewise substitution table is made
  2. Substitution table shows strong symmetry, the cipher
     is extremely weak
2. Now try to uncompress – firmware research
   suggests to try LZO algorithm
3. Success!
4. Passwords offsets are found to be constant in
   the config file
Config file




• The config file content itself is a slice of memory
Config file
Config file
Firmware file
[4 bytes   ] =     the size of (loader code + main code).
[4 bytes   ] =     currently unknown purpose
[248 bytes ] =     rest of header, zeroes
[varies    ] =     firmware loader code (uncompressed)
[8 bytes   ] =     loader end signature - 8 bytes ending
  in A55AA55A,     XXA5A5A55AA55A or XX5A5AA55AA55A

[4 bytes   ]   =   compressed   code size
[varies    ]   =   compressed   firmware code
[4 bytes   ]   =   compressed   filesystem image total size
[4 bytes   ]   =   compressed   filesystem image data size
[varies    ]   =   compressed   filesystem image
[varies    ]   =   garbage or   padding at the end
Filesystem
[16 bytes   ] = filesystem header block
[N*44 bytes ] = file nodes block, 44 bytes in each node
[N*variable ] = compressed files block, all files are simply
   concatenated, no padding or alignment

struct FS_HEAD {
    char magic [8];     // "PFS/1.0x00"
    byte unused [6];    // zeroes
    uint16 num_files;   // number of files
}
struct FS_ENTRY {
    char fname [32];    // file name, right zero-padded
    uint32 hash;        // some hash, not researched yet
    uint32 offset;      // offset from the beginning of common compressed
   file block
    uint32 size;        // compressed file size
}
Master key
•   Derived from local interface MAC address
•   8-byte, alternating case letters , e.g. ‘AaBbCcDd’
•   Login allowed only from local addresses to FTP
•   The same algorithm for all V2xxx devices (from
    2002 to 2012)
    – Compute a simple polynom over MAC address bytes
    – Divide by 26 and map result to reordered alphabet
    – Repeat until all chars filled
Strange findings
Keywords & links
binwalk , signsrch, SPIM, disasmips, OVPsim,
  QEMU-mips
MIPS linux wiki        www.linux-mips.org



Case study reference:
draytools             github.com/ammonium

Más contenido relacionado

La actualidad más candente

Windows Threat Hunting
Windows Threat HuntingWindows Threat Hunting
Windows Threat HuntingGIBIN JOHN
 
DerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting RevisitedDerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting RevisitedWill Schroeder
 
PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)Will Schroeder
 
Threat-Based Adversary Emulation with MITRE ATT&CK
Threat-Based Adversary Emulation with MITRE ATT&CKThreat-Based Adversary Emulation with MITRE ATT&CK
Threat-Based Adversary Emulation with MITRE ATT&CKKatie Nickels
 
Super Easy Memory Forensics
Super Easy Memory ForensicsSuper Easy Memory Forensics
Super Easy Memory ForensicsIIJ
 
Social Engineering the Windows Kernel by James Forshaw
Social Engineering the Windows Kernel by James ForshawSocial Engineering the Windows Kernel by James Forshaw
Social Engineering the Windows Kernel by James ForshawShakacon
 
Overview of the Cyber Kill Chain [TM]
Overview of the Cyber Kill Chain [TM]Overview of the Cyber Kill Chain [TM]
Overview of the Cyber Kill Chain [TM]David Sweigert
 
PHDays 2018 Threat Hunting Hands-On Lab
PHDays 2018 Threat Hunting Hands-On LabPHDays 2018 Threat Hunting Hands-On Lab
PHDays 2018 Threat Hunting Hands-On LabTeymur Kheirkhabarov
 
Semmle Codeql
Semmle Codeql Semmle Codeql
Semmle Codeql M. S.
 
Practical Malware Analysis: Ch 8: Debugging
Practical Malware Analysis: Ch 8: Debugging Practical Malware Analysis: Ch 8: Debugging
Practical Malware Analysis: Ch 8: Debugging Sam Bowne
 
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
0x003 - Exploiting LOLDrivers - Physical Memory MayhemRussell Sanford
 
Windows Operating System Archaeology
Windows Operating System ArchaeologyWindows Operating System Archaeology
Windows Operating System Archaeologyenigma0x3
 
Windows privilege escalation by Dhruv Shah
Windows privilege escalation by Dhruv ShahWindows privilege escalation by Dhruv Shah
Windows privilege escalation by Dhruv ShahOWASP Delhi
 
Penetration Testing Tutorial | Penetration Testing Tools | Cyber Security Tra...
Penetration Testing Tutorial | Penetration Testing Tools | Cyber Security Tra...Penetration Testing Tutorial | Penetration Testing Tools | Cyber Security Tra...
Penetration Testing Tutorial | Penetration Testing Tools | Cyber Security Tra...Edureka!
 
Understanding Windows Access Token Manipulation
Understanding Windows Access Token ManipulationUnderstanding Windows Access Token Manipulation
Understanding Windows Access Token ManipulationJustin Bui
 
Fantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find ThemFantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find ThemRoss Wolf
 
Linux Kernel Image
Linux Kernel ImageLinux Kernel Image
Linux Kernel Image艾鍗科技
 
Network Penetration Testing
Network Penetration TestingNetwork Penetration Testing
Network Penetration TestingMohammed Adam
 

La actualidad más candente (20)

Windows Threat Hunting
Windows Threat HuntingWindows Threat Hunting
Windows Threat Hunting
 
DerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting RevisitedDerbyCon 2019 - Kerberoasting Revisited
DerbyCon 2019 - Kerberoasting Revisited
 
PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)
 
Threat-Based Adversary Emulation with MITRE ATT&CK
Threat-Based Adversary Emulation with MITRE ATT&CKThreat-Based Adversary Emulation with MITRE ATT&CK
Threat-Based Adversary Emulation with MITRE ATT&CK
 
Super Easy Memory Forensics
Super Easy Memory ForensicsSuper Easy Memory Forensics
Super Easy Memory Forensics
 
Social Engineering the Windows Kernel by James Forshaw
Social Engineering the Windows Kernel by James ForshawSocial Engineering the Windows Kernel by James Forshaw
Social Engineering the Windows Kernel by James Forshaw
 
Overview of the Cyber Kill Chain [TM]
Overview of the Cyber Kill Chain [TM]Overview of the Cyber Kill Chain [TM]
Overview of the Cyber Kill Chain [TM]
 
PHDays 2018 Threat Hunting Hands-On Lab
PHDays 2018 Threat Hunting Hands-On LabPHDays 2018 Threat Hunting Hands-On Lab
PHDays 2018 Threat Hunting Hands-On Lab
 
Firmware Reverse Engineering
Firmware Reverse EngineeringFirmware Reverse Engineering
Firmware Reverse Engineering
 
Semmle Codeql
Semmle Codeql Semmle Codeql
Semmle Codeql
 
Practical Malware Analysis: Ch 8: Debugging
Practical Malware Analysis: Ch 8: Debugging Practical Malware Analysis: Ch 8: Debugging
Practical Malware Analysis: Ch 8: Debugging
 
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
0x003 - Exploiting LOLDrivers - Physical Memory Mayhem
 
Windows Operating System Archaeology
Windows Operating System ArchaeologyWindows Operating System Archaeology
Windows Operating System Archaeology
 
Windows privilege escalation by Dhruv Shah
Windows privilege escalation by Dhruv ShahWindows privilege escalation by Dhruv Shah
Windows privilege escalation by Dhruv Shah
 
Penetration Testing Tutorial | Penetration Testing Tools | Cyber Security Tra...
Penetration Testing Tutorial | Penetration Testing Tools | Cyber Security Tra...Penetration Testing Tutorial | Penetration Testing Tools | Cyber Security Tra...
Penetration Testing Tutorial | Penetration Testing Tools | Cyber Security Tra...
 
Understanding Windows Access Token Manipulation
Understanding Windows Access Token ManipulationUnderstanding Windows Access Token Manipulation
Understanding Windows Access Token Manipulation
 
Fantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find ThemFantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find Them
 
Linux Kernel Image
Linux Kernel ImageLinux Kernel Image
Linux Kernel Image
 
Network Penetration Testing
Network Penetration TestingNetwork Penetration Testing
Network Penetration Testing
 
XSS - Attacks & Defense
XSS - Attacks & DefenseXSS - Attacks & Defense
XSS - Attacks & Defense
 

Similar a REVERSING MIPS

Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-reviewabinaya m
 
Larson Macaulay apt_malware_past_present_future_out_of_band_techniques
Larson Macaulay apt_malware_past_present_future_out_of_band_techniquesLarson Macaulay apt_malware_past_present_future_out_of_band_techniques
Larson Macaulay apt_malware_past_present_future_out_of_band_techniquesScott K. Larson
 
Operating Systems 1 (5/12) - Architectures (Unix)
Operating Systems 1 (5/12) - Architectures (Unix)Operating Systems 1 (5/12) - Architectures (Unix)
Operating Systems 1 (5/12) - Architectures (Unix)Peter Tröger
 
Linux Perf Tools
Linux Perf ToolsLinux Perf Tools
Linux Perf ToolsRaj Pandey
 
Microprocessor.ppt
Microprocessor.pptMicroprocessor.ppt
Microprocessor.pptsafia kalwar
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsQUONTRASOLUTIONS
 
Intel® RDT Hands-on Lab
Intel® RDT Hands-on LabIntel® RDT Hands-on Lab
Intel® RDT Hands-on LabMichelle Holley
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsBrendan Gregg
 
BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!Linaro
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...Alexandre Moneger
 
Mac Memory Analysis with Volatility
Mac Memory Analysis with VolatilityMac Memory Analysis with Volatility
Mac Memory Analysis with VolatilityAndrew Case
 
Blackhat USA 2016 - What's the DFIRence for ICS?
Blackhat USA 2016 - What's the DFIRence for ICS?Blackhat USA 2016 - What's the DFIRence for ICS?
Blackhat USA 2016 - What's the DFIRence for ICS?Chris Sistrunk
 
Designs, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed SystemsDesigns, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed SystemsDaehyeok Kim
 
CNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsCNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsSam Bowne
 
Running Applications on the NetBSD Rump Kernel by Justin Cormack
Running Applications on the NetBSD Rump Kernel by Justin Cormack Running Applications on the NetBSD Rump Kernel by Justin Cormack
Running Applications on the NetBSD Rump Kernel by Justin Cormack eurobsdcon
 
Project Basecamp: News From Camp 4
Project Basecamp: News From Camp 4Project Basecamp: News From Camp 4
Project Basecamp: News From Camp 4Digital Bond
 
Java on arm theory, applications, and workloads [dev5048]
Java on arm  theory, applications, and workloads [dev5048]Java on arm  theory, applications, and workloads [dev5048]
Java on arm theory, applications, and workloads [dev5048]Aleksei Voitylov
 
Nodes and Networks for HPC computing
Nodes and Networks for HPC computingNodes and Networks for HPC computing
Nodes and Networks for HPC computingrinnocente
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONLyon Yang
 

Similar a REVERSING MIPS (20)

Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-review
 
Larson Macaulay apt_malware_past_present_future_out_of_band_techniques
Larson Macaulay apt_malware_past_present_future_out_of_band_techniquesLarson Macaulay apt_malware_past_present_future_out_of_band_techniques
Larson Macaulay apt_malware_past_present_future_out_of_band_techniques
 
Operating Systems 1 (5/12) - Architectures (Unix)
Operating Systems 1 (5/12) - Architectures (Unix)Operating Systems 1 (5/12) - Architectures (Unix)
Operating Systems 1 (5/12) - Architectures (Unix)
 
Linux Perf Tools
Linux Perf ToolsLinux Perf Tools
Linux Perf Tools
 
Microprocessor.ppt
Microprocessor.pptMicroprocessor.ppt
Microprocessor.ppt
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra Solutions
 
Intel® RDT Hands-on Lab
Intel® RDT Hands-on LabIntel® RDT Hands-on Lab
Intel® RDT Hands-on Lab
 
Lec05
Lec05Lec05
Lec05
 
Linux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old SecretsLinux Performance Analysis: New Tools and Old Secrets
Linux Performance Analysis: New Tools and Old Secrets
 
BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!BKK16-103 OpenCSD - Open for Business!
BKK16-103 OpenCSD - Open for Business!
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
 
Mac Memory Analysis with Volatility
Mac Memory Analysis with VolatilityMac Memory Analysis with Volatility
Mac Memory Analysis with Volatility
 
Blackhat USA 2016 - What's the DFIRence for ICS?
Blackhat USA 2016 - What's the DFIRence for ICS?Blackhat USA 2016 - What's the DFIRence for ICS?
Blackhat USA 2016 - What's the DFIRence for ICS?
 
Designs, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed SystemsDesigns, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed Systems
 
CNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection MechanismsCNIT 127 14: Protection Mechanisms
CNIT 127 14: Protection Mechanisms
 
Running Applications on the NetBSD Rump Kernel by Justin Cormack
Running Applications on the NetBSD Rump Kernel by Justin Cormack Running Applications on the NetBSD Rump Kernel by Justin Cormack
Running Applications on the NetBSD Rump Kernel by Justin Cormack
 
Project Basecamp: News From Camp 4
Project Basecamp: News From Camp 4Project Basecamp: News From Camp 4
Project Basecamp: News From Camp 4
 
Java on arm theory, applications, and workloads [dev5048]
Java on arm  theory, applications, and workloads [dev5048]Java on arm  theory, applications, and workloads [dev5048]
Java on arm theory, applications, and workloads [dev5048]
 
Nodes and Networks for HPC computing
Nodes and Networks for HPC computingNodes and Networks for HPC computing
Nodes and Networks for HPC computing
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCON
 

Más de DefconRussia

[Defcon Russia #29] Борис Савков - Bare-metal programming на примере Raspber...
[Defcon Russia #29] Борис Савков -  Bare-metal programming на примере Raspber...[Defcon Russia #29] Борис Савков -  Bare-metal programming на примере Raspber...
[Defcon Russia #29] Борис Савков - Bare-metal programming на примере Raspber...DefconRussia
 
[Defcon Russia #29] Александр Ермолов - Safeguarding rootkits: Intel Boot Gua...
[Defcon Russia #29] Александр Ермолов - Safeguarding rootkits: Intel Boot Gua...[Defcon Russia #29] Александр Ермолов - Safeguarding rootkits: Intel Boot Gua...
[Defcon Russia #29] Александр Ермолов - Safeguarding rootkits: Intel Boot Gua...DefconRussia
 
[Defcon Russia #29] Алексей Тюрин - Spring autobinding
[Defcon Russia #29] Алексей Тюрин - Spring autobinding[Defcon Russia #29] Алексей Тюрин - Spring autobinding
[Defcon Russia #29] Алексей Тюрин - Spring autobindingDefconRussia
 
[Defcon Russia #29] Михаил Клементьев - Обнаружение руткитов в GNU/Linux
[Defcon Russia #29] Михаил Клементьев - Обнаружение руткитов в GNU/Linux[Defcon Russia #29] Михаил Клементьев - Обнаружение руткитов в GNU/Linux
[Defcon Russia #29] Михаил Клементьев - Обнаружение руткитов в GNU/LinuxDefconRussia
 
Георгий Зайцев - Reversing golang
Георгий Зайцев - Reversing golangГеоргий Зайцев - Reversing golang
Георгий Зайцев - Reversing golangDefconRussia
 
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC [DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC DefconRussia
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneDefconRussia
 
Олег Купреев - Обзор и демонстрация нюансов и трюков из области беспроводных ...
Олег Купреев - Обзор и демонстрация нюансов и трюков из области беспроводных ...Олег Купреев - Обзор и демонстрация нюансов и трюков из области беспроводных ...
Олег Купреев - Обзор и демонстрация нюансов и трюков из области беспроводных ...DefconRussia
 
HTTP HOST header attacks
HTTP HOST header attacksHTTP HOST header attacks
HTTP HOST header attacksDefconRussia
 
Attacks on tacacs - Алексей Тюрин
Attacks on tacacs - Алексей ТюринAttacks on tacacs - Алексей Тюрин
Attacks on tacacs - Алексей ТюринDefconRussia
 
Weakpass - defcon russia 23
Weakpass - defcon russia 23Weakpass - defcon russia 23
Weakpass - defcon russia 23DefconRussia
 
nosymbols - defcon russia 20
nosymbols - defcon russia 20nosymbols - defcon russia 20
nosymbols - defcon russia 20DefconRussia
 
static - defcon russia 20
static  - defcon russia 20static  - defcon russia 20
static - defcon russia 20DefconRussia
 
Zn task - defcon russia 20
Zn task  - defcon russia 20Zn task  - defcon russia 20
Zn task - defcon russia 20DefconRussia
 
Vm ware fuzzing - defcon russia 20
Vm ware fuzzing  - defcon russia 20Vm ware fuzzing  - defcon russia 20
Vm ware fuzzing - defcon russia 20DefconRussia
 
Nedospasov defcon russia 23
Nedospasov defcon russia 23Nedospasov defcon russia 23
Nedospasov defcon russia 23DefconRussia
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23DefconRussia
 
Miasm defcon russia 23
Miasm defcon russia 23Miasm defcon russia 23
Miasm defcon russia 23DefconRussia
 
Andrey Belenko, Alexey Troshichev - Внутреннее устройство и безопасность iClo...
Andrey Belenko, Alexey Troshichev - Внутреннее устройство и безопасность iClo...Andrey Belenko, Alexey Troshichev - Внутреннее устройство и безопасность iClo...
Andrey Belenko, Alexey Troshichev - Внутреннее устройство и безопасность iClo...DefconRussia
 
Sergey Belov - Покажите нам Impact! Доказываем угрозу в сложных условиях
Sergey Belov - Покажите нам Impact! Доказываем угрозу в сложных условияхSergey Belov - Покажите нам Impact! Доказываем угрозу в сложных условиях
Sergey Belov - Покажите нам Impact! Доказываем угрозу в сложных условияхDefconRussia
 

Más de DefconRussia (20)

[Defcon Russia #29] Борис Савков - Bare-metal programming на примере Raspber...
[Defcon Russia #29] Борис Савков -  Bare-metal programming на примере Raspber...[Defcon Russia #29] Борис Савков -  Bare-metal programming на примере Raspber...
[Defcon Russia #29] Борис Савков - Bare-metal programming на примере Raspber...
 
[Defcon Russia #29] Александр Ермолов - Safeguarding rootkits: Intel Boot Gua...
[Defcon Russia #29] Александр Ермолов - Safeguarding rootkits: Intel Boot Gua...[Defcon Russia #29] Александр Ермолов - Safeguarding rootkits: Intel Boot Gua...
[Defcon Russia #29] Александр Ермолов - Safeguarding rootkits: Intel Boot Gua...
 
[Defcon Russia #29] Алексей Тюрин - Spring autobinding
[Defcon Russia #29] Алексей Тюрин - Spring autobinding[Defcon Russia #29] Алексей Тюрин - Spring autobinding
[Defcon Russia #29] Алексей Тюрин - Spring autobinding
 
[Defcon Russia #29] Михаил Клементьев - Обнаружение руткитов в GNU/Linux
[Defcon Russia #29] Михаил Клементьев - Обнаружение руткитов в GNU/Linux[Defcon Russia #29] Михаил Клементьев - Обнаружение руткитов в GNU/Linux
[Defcon Russia #29] Михаил Клементьев - Обнаружение руткитов в GNU/Linux
 
Георгий Зайцев - Reversing golang
Георгий Зайцев - Reversing golangГеоргий Зайцев - Reversing golang
Георгий Зайцев - Reversing golang
 
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC [DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
[DCG 25] Александр Большев - Never Trust Your Inputs or How To Fool an ADC
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
 
Олег Купреев - Обзор и демонстрация нюансов и трюков из области беспроводных ...
Олег Купреев - Обзор и демонстрация нюансов и трюков из области беспроводных ...Олег Купреев - Обзор и демонстрация нюансов и трюков из области беспроводных ...
Олег Купреев - Обзор и демонстрация нюансов и трюков из области беспроводных ...
 
HTTP HOST header attacks
HTTP HOST header attacksHTTP HOST header attacks
HTTP HOST header attacks
 
Attacks on tacacs - Алексей Тюрин
Attacks on tacacs - Алексей ТюринAttacks on tacacs - Алексей Тюрин
Attacks on tacacs - Алексей Тюрин
 
Weakpass - defcon russia 23
Weakpass - defcon russia 23Weakpass - defcon russia 23
Weakpass - defcon russia 23
 
nosymbols - defcon russia 20
nosymbols - defcon russia 20nosymbols - defcon russia 20
nosymbols - defcon russia 20
 
static - defcon russia 20
static  - defcon russia 20static  - defcon russia 20
static - defcon russia 20
 
Zn task - defcon russia 20
Zn task  - defcon russia 20Zn task  - defcon russia 20
Zn task - defcon russia 20
 
Vm ware fuzzing - defcon russia 20
Vm ware fuzzing  - defcon russia 20Vm ware fuzzing  - defcon russia 20
Vm ware fuzzing - defcon russia 20
 
Nedospasov defcon russia 23
Nedospasov defcon russia 23Nedospasov defcon russia 23
Nedospasov defcon russia 23
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23
 
Miasm defcon russia 23
Miasm defcon russia 23Miasm defcon russia 23
Miasm defcon russia 23
 
Andrey Belenko, Alexey Troshichev - Внутреннее устройство и безопасность iClo...
Andrey Belenko, Alexey Troshichev - Внутреннее устройство и безопасность iClo...Andrey Belenko, Alexey Troshichev - Внутреннее устройство и безопасность iClo...
Andrey Belenko, Alexey Troshichev - Внутреннее устройство и безопасность iClo...
 
Sergey Belov - Покажите нам Impact! Доказываем угрозу в сложных условиях
Sergey Belov - Покажите нам Impact! Доказываем угрозу в сложных условияхSergey Belov - Покажите нам Impact! Доказываем угрозу в сложных условиях
Sergey Belov - Покажите нам Impact! Доказываем угрозу в сложных условиях
 

Último

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Último (20)

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

REVERSING MIPS

  • 1. Reverse-enigneering embedded MIPS devices Case study: Draytek SOHO routers Nikita Abdullin nabdullin@gmail.com 25.11.2011
  • 2. Reverse-enigneering embedded MIPS devices Embedded systems: overview Firmware research MIPS: Introduction MIPS: Reversing and exploitation Case study: DrayTek SOHO routers
  • 3. Reverse-enigneering embedded MIPS devices Embedded systems: overview Firmware research MIPS: Introduction MIPS: Reversing and exploitation Case study: DrayTek SOHO routers
  • 4. Embedded systems: overview • Everywhere: mobile, media, CPE, … • High level of integration: mostly SoC • Compact size, low power consumption • ARM, MIPS, xScale, … • A real challenge for a reverser – Variety of models – Variety of architectures, conventions and APIs – Lack of information
  • 5. Embedded systems: overview Why ever reverse a MIPS box ? • Ubiquitous devices – especially network & CPE • A well-known RISC platform • Surprisingly, a little of security research:
  • 6. Reverse-enigneering embedded MIPS devices Embedded systems: overview Firmware research MIPS: Introduction MIPS: Reversing and exploitation Case study: DrayTek SOHO routers
  • 7. Firmware research Firmware – how to get it? • Download from device … – JTAG – Serial / UART console / other ports – read EEPROM directly, etc. • … or simply find a firmware upgrade – Single file, several MB’s in size – Encrypted / compressed
  • 8. Firmware research Typical firmware binary: • Bootloader • Code • Filesystem image How to extract them? • Manual review • Tools
  • 9. Firmware research :: Tools • Signature search – binwalk – signsrch, offzip – trid • Scriptable hex editor – <Your favourite here> • A set of archivers / unpackers – <Your favourite here> • %script_lang_name%
  • 10. Firmware research :: Manual review • Sequences of 0x00’s and 0xFF’s • First byte/word may be block size • Last byte/word may be block checksum • Magic signatures • Text strings – Extract, sort, guess and google • Entropy
  • 11. Firmware research :: Manual review • Filesystem extraction – Use binwalk – Or look for magic headers • JFFS2 = 85 19 (for FS nodes) • cramfs = 45 3D CD 28 • YAFFS = 03 00 00 00 01 00 00 00 FF FF • SquashFS = "hsqs" • VFAT, etc. …
  • 12. Reverse-enigneering embedded MIPS devices Embedded systems: overview Firmware research MIPS: Introduction MIPS: Reversing and exploitation Case study: DrayTek SOHO routers
  • 13. MIPS: Introduction • RISC ISA (instruction set architecture) • Fixed 4-byte length instructions • 32-bit and 64-bit • Both big-endian and little-endian • Popular and even more promising with multi- core Loongson series from China
  • 14. MIPS: registers Name Number Purpose $zero $0 Const = 0 $at $1 Temporary $v0—$v1 $2-$3 Return values $a0—$a3 $4-$7 Function args $t0—$t7 $8-$15 Temporary $s0—$s7 $16-$23 Saved values $t8—$t9 $24-$25 Temporary $k0—$k1 $26-$27 Reserved for OS kernel $gp $28 Global pointer $sp $29 Stack pointer $fp $30 Frame pointer $ra $31 Return address
  • 15. MIPS: delay slot • MIPS is a pipelined architecture • So not all instructions are safe to be executed right after others – branches & jumps (bne beq j jr jal) – Loads (lb lw ld)
  • 18. Reverse-enigneering embedded MIPS devices Embedded systems: overview Firmware research MIPS: Introduction MIPS: Reversing and exploitation Case study: DrayTek SOHO routers
  • 19. MIPS: Reversing and exploitation • objdump / disasmips / radare • IDA – IDAPython – QEMU-MIPS • MIPS emulator – SPIM – OVPsim
  • 20. MIPS: Reversing and exploitation • Delay slots
  • 21. MIPS: Reversing and exploitation • Finding code patterns – 03 E0 00 08 (jr $ra -- return) – 0C xx xx xx (jal) – 3C xx xx xx (load – lui, la, ...) – 1x xx xx xx (branches)
  • 22. MIPS: Reversing and exploitation • Finding more details about the target system is a key to understanding kernel procedures 14000000 14000FFF external bus general purpose i/o 18000300 180003FF general purpose timer 1E100400 1E1007FF first serial port ... 1E103100 1E1031FF hardware crypto 1E104100 1E1041FF dma controller 1E105300 1E1053FF external bus controller 1E105400 1E1057FF PCI bus controller 1E116000 1E117000 DSL interface 1E180000 1E1BFFFF ethernet controller 1F101000 1F101FFF external interrupt controller ... 1F203000 1F203FFF reset controller 1F880200 1F8802FF interrupt controller 1F8803F0 1F8803FF watchdog timer
  • 23. MIPS: Reversing and exploitation • Basic buffer overflow – Owerwrite the old $ra stored on stack – ret2libc –…
  • 24. MIPS: Reversing and exploitation • Exploitation is more difficult than on x86 and ARM – Fixed-length instructions with a lot of ull bytes – Word-aligned instructions (32 bit) – Word-aligned memory words (32 bit) – I-Cache vs. D-Cache (exploit has no effect, data & code is read & executed from cache) • But protection techniques are still rather new – ASLR (MIPS Linux > 2.6.23) – Stack canaries (GCC > 4.5) – W ^ X not standardized and rarely implemented
  • 25. Reverse-enigneering embedded MIPS devices Embedded systems: overview Firmware research MIPS: Introduction MIPS: Reversing and exploitation Case study: DrayTek SOHO routers
  • 26. Case study: DrayTek SOHO routers
  • 27. Case study: DrayTek SOHO routers • DrayTek Vigor V2xxx series – network devices – Over 35 models, widely deployed by ISP’s over Australia, Germany, UK • Routers • ADSL-modems • CPE & combo devices (dual wan + VoIP + … ) • MIPS and ARM platforms – POI: Infineon Danube-S (MIPS, dual-core, HW crypto) • Proprietary closed-source OS: DrayOS – Single static non-relocatable binary – Capable of loading Linux drivers
  • 28. Case study: DrayTek SOHO routers • Router Web UI allows to download obviously obfuscated binary config for further reloading • Firmware upgrades available from vendor, but they are compressed using unknown algorithm • Rumours are that a master key based on MAC address exist
  • 29. Case study: DrayTek SOHO routers Research steps. 1. Config file – decrypt 2. UART console and debug menu 1. Firmware dumped through UART hexdump 100 bytes at a time  3. Firmware reversing 4. Config file – decompress 5. Firmware – decompress 6. Filesystem – decompress & extract 7. Master password generation algorithm discovered
  • 30. Config file 1. A way to get encrypted and unencrypted configs simultaneously was discovered 1. Immediate result – a cipher used is definitely in ECB mode, bytewise substitution table is made 2. Substitution table shows strong symmetry, the cipher is extremely weak 2. Now try to uncompress – firmware research suggests to try LZO algorithm 3. Success! 4. Passwords offsets are found to be constant in the config file
  • 31. Config file • The config file content itself is a slice of memory
  • 34. Firmware file [4 bytes ] = the size of (loader code + main code). [4 bytes ] = currently unknown purpose [248 bytes ] = rest of header, zeroes [varies ] = firmware loader code (uncompressed) [8 bytes ] = loader end signature - 8 bytes ending in A55AA55A, XXA5A5A55AA55A or XX5A5AA55AA55A [4 bytes ] = compressed code size [varies ] = compressed firmware code [4 bytes ] = compressed filesystem image total size [4 bytes ] = compressed filesystem image data size [varies ] = compressed filesystem image [varies ] = garbage or padding at the end
  • 35. Filesystem [16 bytes ] = filesystem header block [N*44 bytes ] = file nodes block, 44 bytes in each node [N*variable ] = compressed files block, all files are simply concatenated, no padding or alignment struct FS_HEAD { char magic [8]; // "PFS/1.0x00" byte unused [6]; // zeroes uint16 num_files; // number of files } struct FS_ENTRY { char fname [32]; // file name, right zero-padded uint32 hash; // some hash, not researched yet uint32 offset; // offset from the beginning of common compressed file block uint32 size; // compressed file size }
  • 36. Master key • Derived from local interface MAC address • 8-byte, alternating case letters , e.g. ‘AaBbCcDd’ • Login allowed only from local addresses to FTP • The same algorithm for all V2xxx devices (from 2002 to 2012) – Compute a simple polynom over MAC address bytes – Divide by 26 and map result to reordered alphabet – Repeat until all chars filled
  • 38.
  • 39. Keywords & links binwalk , signsrch, SPIM, disasmips, OVPsim, QEMU-mips MIPS linux wiki www.linux-mips.org Case study reference: draytools github.com/ammonium