SlideShare a Scribd company logo
IoT exploitation: from memory corruption
to code execution
Marco Romano
ROME - APRIL 13/14 2018
Marco
Romano
(In)Security Researcher
sometimes for fun,
sometimes for profit
FIND ME HERE
@nemux_
IoT exploitation
from memory corruption
to code execution
© Marco Romano - nemux.org
Independent
researches Publicly disclosed
vulnerabilities
2015
CVE-2015-7805
Heap-based buffer
overflow in libsndfile
1.0.25
2016
CVE-2016-2399
Integer overflow in the
quicktime_read_pascal
function in libquicktime
1.2.4
2018
CVE-2018-8072
????
2017
© Marco Romano - nemux.org
CVE-2018-8072
EDIMAX Network Cameras Stack Buffer Overflow
Models: IC-3140W, IC-5150W, IC-6220DC
An issue was
discovered on
EDIMAX IC-3140W
through 3.06,
IC-5150W through
3.09, and IC-6220DC
through 3.06 devices…
© Marco Romano - nemux.org
Stack Buffer Overflow
© Marco Romano - nemux.org
“2 minutes Crash Course”
Stack
For the sake of simplicity some stack info are missed
Stack Buffer Overflow
© Marco Romano - nemux.org
1) main() calls foo()
2) foo() copies “AA…” in buf[]
3) foo() “return;” —> go back in main()
“2 minutes Crash Course”
Stack
Stack Buffer Overflow
© Marco Romano - nemux.org
“2 minutes Crash Course”
Stack
Model number: IC-3140W
(1) …open-up the box…
(2) Information gathering
(3) Attack surface mapping
DAY 1 TARGET:
HD Wireless Day & Night Network Camera
© Marco Romano - nemux.org
Your are safe… you can see him…
© Marco Romano - nemux.org
…and yell at him
© Marco Romano - nemux.org
Image courtesy of: edimax.com
…but not at him!
(unauthenticated) Remote Code Execution
© Marco Romano - nemux.org
Information
Gathering & Attack
Hardware
Best friend: Screwdriver
Take note of the components
used in the device and collect
online resources
© Marco Romano - nemux.org
Software
Best friend: Google
Download everything the vendor
allows you to…
First of all the firmware!
Information
Gathering & Attack
© Marco Romano - nemux.org
They are 4 interesting holes!
UART Pinouts IC-3140W:
UART root shell:
3 Wires + 1 USB Serial Adapter +
Right baudrate (38400)
1. Tx 2. GND 3. Rx 4. Vcc
UART Exploitation
© Marco Romano - nemux.org
Get a root
shell
Goal: UART —> Serial Console —> telnetd &
© Marco Romano - nemux.org
Firmware
Firmware analysis
Best friend: binwalk
https://github.com/ReFirmLabs/
binwalk
binwalk -M -e IC-3140W_3.05.bin
© Marco Romano - nemux.org
Interesting
targets
Goal: Unauthenticated HTTP Request —> Binary CGI
got something to reverse….
© Marco Romano - nemux.org
telnetd.cgi?
sounds good!
Goal: HTTP Request —> telnetd.cgi —> telnetd &
(1) Undocumented “feature”
(2) Not available in the admin panel
(3) Run telnet daemon through an
HTTP GET request
…feature, really?
(it comes in handy for debugging
purpose)
© Marco Romano - nemux.org
telnetd.cgi
Reverse…
Goal: HTTP Request —> telnetd.cgi —> telnetd &
Typo here…
© Marco Romano - nemux.org
telnetd.cgi
Let’s test it!
Goal: HTTP Request —> telnetd.cgi —> telnetd &
No UART wires and “noise”,
from now on…
and typo here… so, it works :-)
© Marco Romano - nemux.org
Bug Hunting
Model number: IC-3140W
TARGET:
HD Wireless Day & Night Network Camera
DAY 2
© Marco Romano - nemux.org
Binary Reverse
Best friend: Debugger & Disassembler
How it works:
CGI manages parameter through
environment variables (take note for
debugging session)
Reverse ipcam_cgi
© Marco Romano - nemux.org
Goal: HTTP Request —> public/… —> vulnerability (?)
1) strcpy() —> dest with fixed size (1024)
2) strcpy() —> i can control the source
3) strcpy() —> no check on src size
ipcam_cgi
© Marco Romano - nemux.org
HACKED POTATO!
HTTPdHTTP GET getSysteminfo.cgi
2016 ipcam_cgiHTTPd set ENV variables
strcpy()ipcam_cgi parse & copy
Stack Buffer Overflow
Recipe… …result
Goal: HTTP Request —> public/… —> vulnerability (?)
ipcam_cgi
© Marco Romano - nemux.org
ipcam_cgi
Let’s test it!
Value length > 1024 byte (0x400)
Goal: HTTP Request —> public/… —> vulnerability (?)
© Marco Romano - nemux.org
ipcam_cgi
some math…
“action=“ + 1017 + “BBBB” (0x42424242)
Invalid Read Access
Goal: HTTP Request —> public/… —> vulnerability (!)
© Marco Romano - nemux.org
Exploiting
Model number: IC-3140W
TARGET:
HD Wireless Day & Night Network Camera
DAY 3
© Marco Romano - nemux.org
Protection
Mechanisms
Goal: HTTP Request —> ipcam_cgi —> code exec
ASLR = Address Space Layout Randomization
Randomly arranges the address space positions of key data areas of a process:
executable, stack, heap and libraries.
(2) Memory Map
Stack Base = 0x7fad6000
Stack Base = 0x7fdac000
Partially Enabled
(1) Memory Map
© Marco Romano - nemux.org
Protection
Mechanisms
Goal: HTTP Request —> ipcam_cgi —> code exec
(2) Memory Map
(1) Memory Map
W^X = Write XOR Execute
 Address space may be either writable or executable, but not both
Not Enabled
32bit arch no PAE
© Marco Romano - nemux.org
“Exploitation plan”
Steps
1) Hijack the control flow
2) Bypass Protections
3) Inject arbitrary code
…and jump there!
© Marco Romano - nemux.org
Mips Note
Goal: Low-level note…MIPS
registers
Image courtesy of hmc.edu
© Marco Romano - nemux.org
Hijack the
flow
Goal: Overwrite Saved Return Pointer -> Control RA
Control “Return Address” register
Exception: “Invalid Read Access”
=
Pointer(s) stored in the Stack
=
“CONSTRAINTS”
Constraints solved…
Stack SrP —> 0x46464646 —>
RA = SrP
Control Flow Hijacked!
© Marco Romano - nemux.org
Bypass Stack ASLR
Jump there…. where!?
Stack + ASLR
“Code-Reuse” Attack
Bypass
Protections
Goal: Find a stack pointer
© Marco Romano - nemux.org
Bypass Stack ASLR
Goal: Find a stack pointer
“Code reuse” attack… how it works?
Execute the code which is “already” present
in the memory
Usually used to bypass NX
Bypass
Protections
© Marco Romano - nemux.org
Bypass Stack ASLR
Goal: Find a stack pointer
“System” applies a restriction…
Bypass
Protections
© Marco Romano - nemux.org
Bypass Stack ASLR
Goal: Find a stack pointer
…but she’s smart!
Bypass
Protections
Answer is “NO”
© Marco Romano - nemux.org
Bypass Stack ASLR
Goal: Find a stack pointer
“Code reuse” attack… exploitation purpose
1. Libraries: Fixed location in memory
2. Plan: Concatenate “pieces” of (that) code
3. Get a (randomized) stack pointer to defeat ASLR
Bypass
Protections
© Marco Romano - nemux.org
Cache coherence
Goal: Defeat cache coherence
MIPS CPUs have 2 separate caches
(data and instructions)
Cache != Protection… but affect exploitation!
• Our payload will be in memory as data

• Hijack control flow… and Shellcode in D-cache

• How to move Shellcode in Main Memory?
Bypass
Protections
© Marco Romano - nemux.org
“Bypass” Cache coherence
Cache Flushing… how to
1. Filling the D-cache to force the CPU to write-back

2. cacheflush() systemcall

3. Call a blocking function (like sleep() or similar)
Cache != Protection… and we can defeat it!
Bypass
Protections
Goal: Defeat cache coherence
© Marco Romano - nemux.org
 put them all together…
Goal: Execute a “connect back” shellcode
Chain of “Gadgets” - Step 1 - Defeat Cache
Inject
arbitrary
code
Hijack Control Flow “Init” Gadget “Double-Jump” Gadget
call usleep()
set usleep() arg jump next…
© Marco Romano - nemux.org
 put them all together…
Goal: Execute a “connect back” shellcode
Chain of “Gadgets” - Step 2 - Defeat Stack ASLR
Inject
arbitrary
code
Move Stack Pointer in $A1 Move $A1 in $V0 Jump to $V0
© Marco Romano - nemux.org
 put them all together…
Goal: Execute a “connect back” shellcode
Chain of “Gadgets” - Step 3 - Execute Shellcode
Inject
arbitrary
code
Ehi! That’s my code…
Connect back shell… port 8080
© Marco Romano - nemux.org
Wait for a root shell…
Goal: Execute a “connect back” shellcode
Execute
arbitrary
code
© Marco Romano - nemux.org
Let’s play
the bad guys
© Marco Romano - nemux.org
Botnet
…while you wait for the crypto
miner botnet
© Marco Romano - nemux.org
Don’t do this at home! :-)
TIMELINE
2016
February
2018
ME —> EDIMAX
Proof of concept
March
2018
EDIMAX —> ME
Private Beta version
April
2018
New Firmware (??)
CVE-2018-8072
© Marco Romano - nemux.org
Thank you!
© Marco Romano - nemux.org
https://gitlab.com/nemux/CVE-2018-8072

More Related Content

PDF
Digging for Android Kernel Bugs
PDF
Csw2017 bazhaniuk exploring_yoursystemdeeper_updated
PDF
CrySys guest-lecture: Virtual machine introspection on modern hardware
ODP
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
PDF
OffensiveCon2022: Case Studies of Fuzzing with Xen
PDF
31c3 Presentation - Virtual Machine Introspection
PDF
Larson Macaulay apt_malware_past_present_future_out_of_band_techniques
ODP
Virtual Machine Introspection with Xen on ARM
Digging for Android Kernel Bugs
Csw2017 bazhaniuk exploring_yoursystemdeeper_updated
CrySys guest-lecture: Virtual machine introspection on modern hardware
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
OffensiveCon2022: Case Studies of Fuzzing with Xen
31c3 Presentation - Virtual Machine Introspection
Larson Macaulay apt_malware_past_present_future_out_of_band_techniques
Virtual Machine Introspection with Xen on ARM

What's hot (20)

PDF
44CON London - Attacking VxWorks: from Stone Age to Interstellar
PDF
Kernel Recipes 2015: Anatomy of an atomic KMS driver
PDF
Cloud Security with LibVMI
PDF
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
PPTX
ShinoBOT Suite
PDF
How to Root 10 Million Phones with One Exploit
PPT
[ENG] IPv6 shipworm + My little Windows domain pwnie
PPTX
VM Forking and Hypervisor-based fuzzing
PDF
BSides Denver: Stealthy, hypervisor-based malware analysis
PDF
Pitfalls and limits of dynamic malware analysis
ODP
Pitfalls of virtual machine introspection on modern hardware
PDF
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
PDF
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
PDF
VM Forking and Hypervisor-based Fuzzing with Xen
PDF
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
PDF
Virtual Machine Introspection with Xen
ODP
Hacktivity2014: Virtual Machine Introspection to Detect and Protect
PDF
CSW2017 Qiang li zhibinhu_meiwang_dig into qemu security
PDF
SnakeGX (short version)
PDF
Shusei tomonaga pac_sec_20171026
44CON London - Attacking VxWorks: from Stone Age to Interstellar
Kernel Recipes 2015: Anatomy of an atomic KMS driver
Cloud Security with LibVMI
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
ShinoBOT Suite
How to Root 10 Million Phones with One Exploit
[ENG] IPv6 shipworm + My little Windows domain pwnie
VM Forking and Hypervisor-based fuzzing
BSides Denver: Stealthy, hypervisor-based malware analysis
Pitfalls and limits of dynamic malware analysis
Pitfalls of virtual machine introspection on modern hardware
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
VM Forking and Hypervisor-based Fuzzing with Xen
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
Virtual Machine Introspection with Xen
Hacktivity2014: Virtual Machine Introspection to Detect and Protect
CSW2017 Qiang li zhibinhu_meiwang_dig into qemu security
SnakeGX (short version)
Shusei tomonaga pac_sec_20171026
Ad

Similar to IoT exploitation: from memory corruption to code execution by Marco Romano (20)

PPTX
Advanced SOHO Router Exploitation XCON
PDF
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
PDF
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
PDF
Filip palian mateuszkocielski. simplest ownage human observed… routers
PDF
Simplest-Ownage-Human-Observed… - Routers
PDF
DefCon 2012 - Rooting SOHO Routers
PPT
Software security
PPTX
The internet of $h1t
PDF
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
PDF
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
PPTX
Steelcon 2015 - 0wning the internet of trash
PDF
DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...
PPT
Attacking Embedded Devices (No Axe Required)
PDF
Linux Kernel Exploitation
PDF
Os Selbak
PPTX
hacking-embedded-devices.pptx
PDF
Hacklu11 Writeup
ODP
[Defcon] Hardware backdooring is practical
PDF
44CON London 2015 - Is there an EFI monster inside your apple?
PDF
Hacking school computers for fun profit and better grades short
Advanced SOHO Router Exploitation XCON
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
Filip palian mateuszkocielski. simplest ownage human observed… routers
Simplest-Ownage-Human-Observed… - Routers
DefCon 2012 - Rooting SOHO Routers
Software security
The internet of $h1t
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
Steelcon 2015 - 0wning the internet of trash
DEF CON 27 - XILING GONG PETER PI - exploiting qualcom wlan and modem over th...
Attacking Embedded Devices (No Axe Required)
Linux Kernel Exploitation
Os Selbak
hacking-embedded-devices.pptx
Hacklu11 Writeup
[Defcon] Hardware backdooring is practical
44CON London 2015 - Is there an EFI monster inside your apple?
Hacking school computers for fun profit and better grades short
Ad

More from Codemotion (20)

PDF
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
PDF
Pompili - From hero to_zero: The FatalNoise neverending story
PPTX
Pastore - Commodore 65 - La storia
PPTX
Pennisi - Essere Richard Altwasser
PPTX
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
PPTX
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
PPTX
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
PPTX
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
PDF
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
PDF
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
PDF
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
PDF
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
PDF
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
PDF
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
PPTX
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
PPTX
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
PDF
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
PDF
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
PDF
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
PDF
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Pompili - From hero to_zero: The FatalNoise neverending story
Pastore - Commodore 65 - La storia
Pennisi - Essere Richard Altwasser
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
Teaching material agriculture food technology
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Programs and apps: productivity, graphics, security and other tools
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Big Data Technologies - Introduction.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Teaching material agriculture food technology

IoT exploitation: from memory corruption to code execution by Marco Romano

  • 1. IoT exploitation: from memory corruption to code execution Marco Romano ROME - APRIL 13/14 2018
  • 2. Marco Romano (In)Security Researcher sometimes for fun, sometimes for profit FIND ME HERE @nemux_ IoT exploitation from memory corruption to code execution © Marco Romano - nemux.org
  • 3. Independent researches Publicly disclosed vulnerabilities 2015 CVE-2015-7805 Heap-based buffer overflow in libsndfile 1.0.25 2016 CVE-2016-2399 Integer overflow in the quicktime_read_pascal function in libquicktime 1.2.4 2018 CVE-2018-8072 ???? 2017 © Marco Romano - nemux.org
  • 4. CVE-2018-8072 EDIMAX Network Cameras Stack Buffer Overflow Models: IC-3140W, IC-5150W, IC-6220DC An issue was discovered on EDIMAX IC-3140W through 3.06, IC-5150W through 3.09, and IC-6220DC through 3.06 devices… © Marco Romano - nemux.org
  • 5. Stack Buffer Overflow © Marco Romano - nemux.org “2 minutes Crash Course” Stack For the sake of simplicity some stack info are missed
  • 6. Stack Buffer Overflow © Marco Romano - nemux.org 1) main() calls foo() 2) foo() copies “AA…” in buf[] 3) foo() “return;” —> go back in main() “2 minutes Crash Course” Stack
  • 7. Stack Buffer Overflow © Marco Romano - nemux.org “2 minutes Crash Course” Stack
  • 8. Model number: IC-3140W (1) …open-up the box… (2) Information gathering (3) Attack surface mapping DAY 1 TARGET: HD Wireless Day & Night Network Camera © Marco Romano - nemux.org
  • 9. Your are safe… you can see him… © Marco Romano - nemux.org
  • 10. …and yell at him © Marco Romano - nemux.org Image courtesy of: edimax.com
  • 11. …but not at him! (unauthenticated) Remote Code Execution © Marco Romano - nemux.org
  • 12. Information Gathering & Attack Hardware Best friend: Screwdriver Take note of the components used in the device and collect online resources © Marco Romano - nemux.org
  • 13. Software Best friend: Google Download everything the vendor allows you to… First of all the firmware! Information Gathering & Attack © Marco Romano - nemux.org
  • 14. They are 4 interesting holes! UART Pinouts IC-3140W: UART root shell: 3 Wires + 1 USB Serial Adapter + Right baudrate (38400) 1. Tx 2. GND 3. Rx 4. Vcc UART Exploitation © Marco Romano - nemux.org
  • 15. Get a root shell Goal: UART —> Serial Console —> telnetd & © Marco Romano - nemux.org
  • 16. Firmware Firmware analysis Best friend: binwalk https://github.com/ReFirmLabs/ binwalk binwalk -M -e IC-3140W_3.05.bin © Marco Romano - nemux.org
  • 17. Interesting targets Goal: Unauthenticated HTTP Request —> Binary CGI got something to reverse…. © Marco Romano - nemux.org
  • 18. telnetd.cgi? sounds good! Goal: HTTP Request —> telnetd.cgi —> telnetd & (1) Undocumented “feature” (2) Not available in the admin panel (3) Run telnet daemon through an HTTP GET request …feature, really? (it comes in handy for debugging purpose) © Marco Romano - nemux.org
  • 19. telnetd.cgi Reverse… Goal: HTTP Request —> telnetd.cgi —> telnetd & Typo here… © Marco Romano - nemux.org
  • 20. telnetd.cgi Let’s test it! Goal: HTTP Request —> telnetd.cgi —> telnetd & No UART wires and “noise”, from now on… and typo here… so, it works :-) © Marco Romano - nemux.org
  • 21. Bug Hunting Model number: IC-3140W TARGET: HD Wireless Day & Night Network Camera DAY 2 © Marco Romano - nemux.org
  • 22. Binary Reverse Best friend: Debugger & Disassembler How it works: CGI manages parameter through environment variables (take note for debugging session) Reverse ipcam_cgi © Marco Romano - nemux.org
  • 23. Goal: HTTP Request —> public/… —> vulnerability (?) 1) strcpy() —> dest with fixed size (1024) 2) strcpy() —> i can control the source 3) strcpy() —> no check on src size ipcam_cgi © Marco Romano - nemux.org
  • 24. HACKED POTATO! HTTPdHTTP GET getSysteminfo.cgi 2016 ipcam_cgiHTTPd set ENV variables strcpy()ipcam_cgi parse & copy Stack Buffer Overflow Recipe… …result Goal: HTTP Request —> public/… —> vulnerability (?) ipcam_cgi © Marco Romano - nemux.org
  • 25. ipcam_cgi Let’s test it! Value length > 1024 byte (0x400) Goal: HTTP Request —> public/… —> vulnerability (?) © Marco Romano - nemux.org
  • 26. ipcam_cgi some math… “action=“ + 1017 + “BBBB” (0x42424242) Invalid Read Access Goal: HTTP Request —> public/… —> vulnerability (!) © Marco Romano - nemux.org
  • 27. Exploiting Model number: IC-3140W TARGET: HD Wireless Day & Night Network Camera DAY 3 © Marco Romano - nemux.org
  • 28. Protection Mechanisms Goal: HTTP Request —> ipcam_cgi —> code exec ASLR = Address Space Layout Randomization Randomly arranges the address space positions of key data areas of a process: executable, stack, heap and libraries. (2) Memory Map Stack Base = 0x7fad6000 Stack Base = 0x7fdac000 Partially Enabled (1) Memory Map © Marco Romano - nemux.org
  • 29. Protection Mechanisms Goal: HTTP Request —> ipcam_cgi —> code exec (2) Memory Map (1) Memory Map W^X = Write XOR Execute  Address space may be either writable or executable, but not both Not Enabled 32bit arch no PAE © Marco Romano - nemux.org
  • 30. “Exploitation plan” Steps 1) Hijack the control flow 2) Bypass Protections 3) Inject arbitrary code …and jump there! © Marco Romano - nemux.org
  • 31. Mips Note Goal: Low-level note…MIPS registers Image courtesy of hmc.edu © Marco Romano - nemux.org
  • 32. Hijack the flow Goal: Overwrite Saved Return Pointer -> Control RA Control “Return Address” register Exception: “Invalid Read Access” = Pointer(s) stored in the Stack = “CONSTRAINTS” Constraints solved… Stack SrP —> 0x46464646 —> RA = SrP Control Flow Hijacked! © Marco Romano - nemux.org
  • 33. Bypass Stack ASLR Jump there…. where!? Stack + ASLR “Code-Reuse” Attack Bypass Protections Goal: Find a stack pointer © Marco Romano - nemux.org
  • 34. Bypass Stack ASLR Goal: Find a stack pointer “Code reuse” attack… how it works? Execute the code which is “already” present in the memory Usually used to bypass NX Bypass Protections © Marco Romano - nemux.org
  • 35. Bypass Stack ASLR Goal: Find a stack pointer “System” applies a restriction… Bypass Protections © Marco Romano - nemux.org
  • 36. Bypass Stack ASLR Goal: Find a stack pointer …but she’s smart! Bypass Protections Answer is “NO” © Marco Romano - nemux.org
  • 37. Bypass Stack ASLR Goal: Find a stack pointer “Code reuse” attack… exploitation purpose 1. Libraries: Fixed location in memory 2. Plan: Concatenate “pieces” of (that) code 3. Get a (randomized) stack pointer to defeat ASLR Bypass Protections © Marco Romano - nemux.org
  • 38. Cache coherence Goal: Defeat cache coherence MIPS CPUs have 2 separate caches (data and instructions) Cache != Protection… but affect exploitation! • Our payload will be in memory as data • Hijack control flow… and Shellcode in D-cache • How to move Shellcode in Main Memory? Bypass Protections © Marco Romano - nemux.org
  • 39. “Bypass” Cache coherence Cache Flushing… how to 1. Filling the D-cache to force the CPU to write-back 2. cacheflush() systemcall 3. Call a blocking function (like sleep() or similar) Cache != Protection… and we can defeat it! Bypass Protections Goal: Defeat cache coherence © Marco Romano - nemux.org
  • 40.  put them all together… Goal: Execute a “connect back” shellcode Chain of “Gadgets” - Step 1 - Defeat Cache Inject arbitrary code Hijack Control Flow “Init” Gadget “Double-Jump” Gadget call usleep() set usleep() arg jump next… © Marco Romano - nemux.org
  • 41.  put them all together… Goal: Execute a “connect back” shellcode Chain of “Gadgets” - Step 2 - Defeat Stack ASLR Inject arbitrary code Move Stack Pointer in $A1 Move $A1 in $V0 Jump to $V0 © Marco Romano - nemux.org
  • 42.  put them all together… Goal: Execute a “connect back” shellcode Chain of “Gadgets” - Step 3 - Execute Shellcode Inject arbitrary code Ehi! That’s my code… Connect back shell… port 8080 © Marco Romano - nemux.org
  • 43. Wait for a root shell… Goal: Execute a “connect back” shellcode Execute arbitrary code © Marco Romano - nemux.org
  • 44. Let’s play the bad guys © Marco Romano - nemux.org Botnet
  • 45. …while you wait for the crypto miner botnet © Marco Romano - nemux.org Don’t do this at home! :-)
  • 46. TIMELINE 2016 February 2018 ME —> EDIMAX Proof of concept March 2018 EDIMAX —> ME Private Beta version April 2018 New Firmware (??) CVE-2018-8072 © Marco Romano - nemux.org
  • 47. Thank you! © Marco Romano - nemux.org https://gitlab.com/nemux/CVE-2018-8072