SlideShare a Scribd company logo
Exploiting the Linux Dynamic Loader with LD_PRELOAD David Kaplan [email_address] DC9723 – June 2011
The Executable and linking format (ELF) } linkers loaders libraries
Linkers combine compiled code fragments into single memory-loadable executable $ ld obj1.o obj2.o –o linked.o symbol resolution program components reference each other through symbols (ELF .symtab) Relocation adjustment of code/data sections (also performed by the loader)
Loaders copy code and data into memory memory allocation/mapping relocation Also performed by the linker execve()
Libraries statically-linked dynamically-linked (shared)* collections of reusable compiled code *historically: a shared library was something else entirely
Statically-linked libraries code copied into final binary be aware of: cyclic dependencies, multiple symbol definitions $ld obj1.o obj2.o /usr/lib/libname.a CODE my_print() { printf(); } main() { my_print(); } main() { my_print(); } my_print() { printf(); } printf() { vfprintf(); } LIBC STATICALLY LINKED FILESIZE
Dynamically-linked libraries dynamic loader (ld.so) resolves symbols at exectime Process: - execve() loads executable code into memory
- control is passed to the dynamic linker (ld.so) which maps shared objects to program  address space (resolves symbols)
- control is then passed to the application can be called from within the application at runtime By linking ld and calling dlopen(), etc. CODE my_print() { printf(); } main() { my_print(); } main() { my_print(); } my_print() { printf(); } printf(); DYNAMICALLY LINKED FILESIZE LIBC
So what is LD_PRELOAD? environment var queried by dynamic linker on exec allows dynamic linker to prioritize linking defined shared libs $ LD_PRELOAD=“./mylib.so” ./myexec
Attack enablers OS  ‘features’ weak   system   security good   coding   practices general_rule: good_for_devs  ==   good_for_hackers ; goto   general_rule ;
Attack advantages easy, effective on  unprotected  systems code  interception code   injection program  flow manipulation debugging using  wrapper functions
Attack disadvantages } can be  protected  against requires  access   to executable requires relevant  privileges works on  used, imported symbols
Example 1 – Hello World $ nm -D make_goodbye.so 000000000000069c T printf U stdout U vfprintf $ nm -D hello w __gmon_start__ U __libc_start_main U printf Undefined symbol Symbol exists in .text
Example 1 – Hello World – cont. *in practice it works slightly differently – this is just a conceptual explanation NORMAL SYMBOL RESOLUTION: LOADER HELLO printf()  ?? DYNAMIC LINKER LIBC.SO Hello World! REDIRECTED SYMBOL RESOLUTION: LOADER HELLO printf()  ?? DYNAMIC LINKER GOODBYE.SO Goodbye World! LIBC.SO fprintf()  ??
Example 2 – OpenSSH MITM dynamically links openssl checks public key against known_hosts with BN_cmp() BN_cmp() must pass (== 0) for iterations 3 and 5
Example 3 – OpenSSH password logger catch write() w/ string literal “’s password” log read()s until ‘\n’
Example 4 – Extending ‘cat’ functionality intercept __snprintf_check() to add to usage() wrap getopt_long() to catch new command line option catch write(), vfork() and launch browser for each link
provides reusable library of function sigs (sorry about the code quality!) ./preloader reduces repetitive tasks tool that does *some* of the work for you http://www.github.com/2of1/preloader

More Related Content

What's hot (20)

PPTX
Yacc (yet another compiler compiler)
omercomail
 
DOC
Lex tool manual
Sami Said
 
PPTX
Loader and Its types
Parth Dodiya
 
PPT
Compilation
David Halliday
 
PPTX
Introduction to loaders
Tech_MX
 
PPT
Loaders
Mohd Arif
 
PPTX
Lex & yacc
Taha Malampatti
 
DOCX
LEX & YACC
Mahbubur Rahman
 
PDF
loaders and linkers
Temesgen Molla
 
PDF
Assembler
rahulmnnit_cs
 
PPTX
Loaders ( system programming )
Adarsh Patel
 
PDF
ANSI C Macros
Srikrishnan Suresh
 
PPTX
Yacc
BBDITM LUCKNOW
 
PDF
Lexyacc
unifesptk
 
ODP
Runtime Symbol Resolution
Ken Kawamoto
 
PPTX
Linking in MS-Dos System
Satyamevjayte Haxor
 
PPTX
File handling With Solve Programs
Rohan Gajre
 
PDF
Strategies to improve embedded Linux application performance beyond ordinary ...
André Oriani
 
PDF
Whirlwind tour of the Runtime Dynamic Linker
Gonçalo Gomes
 
Yacc (yet another compiler compiler)
omercomail
 
Lex tool manual
Sami Said
 
Loader and Its types
Parth Dodiya
 
Compilation
David Halliday
 
Introduction to loaders
Tech_MX
 
Loaders
Mohd Arif
 
Lex & yacc
Taha Malampatti
 
LEX & YACC
Mahbubur Rahman
 
loaders and linkers
Temesgen Molla
 
Assembler
rahulmnnit_cs
 
Loaders ( system programming )
Adarsh Patel
 
ANSI C Macros
Srikrishnan Suresh
 
Lexyacc
unifesptk
 
Runtime Symbol Resolution
Ken Kawamoto
 
Linking in MS-Dos System
Satyamevjayte Haxor
 
File handling With Solve Programs
Rohan Gajre
 
Strategies to improve embedded Linux application performance beyond ordinary ...
André Oriani
 
Whirlwind tour of the Runtime Dynamic Linker
Gonçalo Gomes
 

Viewers also liked (18)

PPTX
Ch 4 linker loader
Malek Sumaiya
 
PDF
Tips of Malloc & Free
Tetsuyuki Kobayashi
 
PDF
ELF 101
Chia-Hao Tsai
 
PDF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
Hackito Ergo Sum
 
PDF
Effective Modern C++
Wang Hsiangkai
 
PPT
Intro reverse engineering
Nitin kumar Gupta
 
PDF
Symbolic Debugging with DWARF
Samy Bahra
 
PPTX
Load-time Hacking using LD_PRELOAD
Dharmalingam Ganesan
 
PDF
DWARF Data Representation
Wang Hsiangkai
 
PDF
Crash dump analysis - experience sharing
James Hsieh
 
PPTX
Sp chap2
sushma sanisetty
 
PDF
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Ahmed El-Arabawy
 
PPTX
Linkers in compiler
Asaad Al-nour
 
PPT
Linkers And Loaders
Satpal Parmar
 
PPTX
Linkers
Tech_MX
 
PPT
Assembler
Maha Lakshmi
 
PPTX
System Programing Unit 1
Manoj Patil
 
Ch 4 linker loader
Malek Sumaiya
 
Tips of Malloc & Free
Tetsuyuki Kobayashi
 
ELF 101
Chia-Hao Tsai
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
Hackito Ergo Sum
 
Effective Modern C++
Wang Hsiangkai
 
Intro reverse engineering
Nitin kumar Gupta
 
Symbolic Debugging with DWARF
Samy Bahra
 
Load-time Hacking using LD_PRELOAD
Dharmalingam Ganesan
 
DWARF Data Representation
Wang Hsiangkai
 
Crash dump analysis - experience sharing
James Hsieh
 
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Ahmed El-Arabawy
 
Linkers in compiler
Asaad Al-nour
 
Linkers And Loaders
Satpal Parmar
 
Linkers
Tech_MX
 
Assembler
Maha Lakshmi
 
System Programing Unit 1
Manoj Patil
 
Ad

Similar to LD_PRELOAD Exploitation - DC9723 (20)

PPTX
C++ shared libraries and loading
Rahul Jamwal
 
ODP
Libraries
Ashwanth Selvam
 
PPTX
SECR'13 Lightweight linux shared libraries profiling
OSLL
 
PPT
Linkers
Koganti Ravikumar
 
PDF
Dynamic Linking On GNU/Linux
Florian Sowade
 
PDF
How to write shared libraries!
Stanley Ho
 
PPT
loaderfffffffffffffffffffffffffffflinker.ppt
ATHMARANJANBhandary
 
PPT
bh-europe-01-clowes
guest3e5046
 
PDF
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
Felipe Prado
 
PPT
Loaders complete
Faisal Shah
 
ODP
C Under Linux
mohan43u
 
PPT
Advanced c programming in Linux
Mohammad Golyani
 
PPT
From gcc to the autotools
Thierry Gayet
 
PDF
Linker Wisdom
dmichelsen
 
PDF
Hackersuli - Linux game hacking with LD_PRELOAD
hackersuli
 
PPTX
Linkers
Rahul Dhiman
 
PPT
wk 4 -- linking.ppt
ankurgupta171066
 
PDF
Consuming and Creating Libraries in C++
Richard Thomson
 
PPT
Introduction to libraries in india and china
ssainishokkrishna
 
PPT
Purdue CS354 Operating Systems 2008
guestd9065
 
C++ shared libraries and loading
Rahul Jamwal
 
Libraries
Ashwanth Selvam
 
SECR'13 Lightweight linux shared libraries profiling
OSLL
 
Dynamic Linking On GNU/Linux
Florian Sowade
 
How to write shared libraries!
Stanley Ho
 
loaderfffffffffffffffffffffffffffflinker.ppt
ATHMARANJANBhandary
 
bh-europe-01-clowes
guest3e5046
 
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
Felipe Prado
 
Loaders complete
Faisal Shah
 
C Under Linux
mohan43u
 
Advanced c programming in Linux
Mohammad Golyani
 
From gcc to the autotools
Thierry Gayet
 
Linker Wisdom
dmichelsen
 
Hackersuli - Linux game hacking with LD_PRELOAD
hackersuli
 
Linkers
Rahul Dhiman
 
wk 4 -- linking.ppt
ankurgupta171066
 
Consuming and Creating Libraries in C++
Richard Thomson
 
Introduction to libraries in india and china
ssainishokkrishna
 
Purdue CS354 Operating Systems 2008
guestd9065
 
Ad

More from Iftach Ian Amit (20)

PPTX
Cyber Risk Quantification - CyberTLV
Iftach Ian Amit
 
PDF
Devsecops at Cimpress
Iftach Ian Amit
 
PPTX
BSidesTLV Closing Keynote
Iftach Ian Amit
 
PDF
Social Media Risk Metrics
Iftach Ian Amit
 
PDF
ISTS12 Keynote
Iftach Ian Amit
 
PDF
From your Pocket to your Heart and Back
Iftach Ian Amit
 
PDF
Painting a Company Red and Blue
Iftach Ian Amit
 
PDF
"Cyber" security - all good, no need to worry?
Iftach Ian Amit
 
PDF
Armorizing applications
Iftach Ian Amit
 
PDF
Seeing Red In Your Future?
Iftach Ian Amit
 
PPTX
Hacking cyber-iamit
Iftach Ian Amit
 
PDF
Passwords good badugly181212-2
Iftach Ian Amit
 
PDF
Bitcoin
Iftach Ian Amit
 
PDF
Sexy defense
Iftach Ian Amit
 
PDF
Cyber state
Iftach Ian Amit
 
PDF
Advanced Data Exfiltration - the way Q would have done it
Iftach Ian Amit
 
PDF
Infecting Python Bytecode
Iftach Ian Amit
 
PDF
Exploiting Second life
Iftach Ian Amit
 
PDF
Dtmf phreaking
Iftach Ian Amit
 
PDF
Cheating in Computer Games
Iftach Ian Amit
 
Cyber Risk Quantification - CyberTLV
Iftach Ian Amit
 
Devsecops at Cimpress
Iftach Ian Amit
 
BSidesTLV Closing Keynote
Iftach Ian Amit
 
Social Media Risk Metrics
Iftach Ian Amit
 
ISTS12 Keynote
Iftach Ian Amit
 
From your Pocket to your Heart and Back
Iftach Ian Amit
 
Painting a Company Red and Blue
Iftach Ian Amit
 
"Cyber" security - all good, no need to worry?
Iftach Ian Amit
 
Armorizing applications
Iftach Ian Amit
 
Seeing Red In Your Future?
Iftach Ian Amit
 
Hacking cyber-iamit
Iftach Ian Amit
 
Passwords good badugly181212-2
Iftach Ian Amit
 
Sexy defense
Iftach Ian Amit
 
Cyber state
Iftach Ian Amit
 
Advanced Data Exfiltration - the way Q would have done it
Iftach Ian Amit
 
Infecting Python Bytecode
Iftach Ian Amit
 
Exploiting Second life
Iftach Ian Amit
 
Dtmf phreaking
Iftach Ian Amit
 
Cheating in Computer Games
Iftach Ian Amit
 

Recently uploaded (20)

PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 

LD_PRELOAD Exploitation - DC9723

  • 1. Exploiting the Linux Dynamic Loader with LD_PRELOAD David Kaplan [email_address] DC9723 – June 2011
  • 2. The Executable and linking format (ELF) } linkers loaders libraries
  • 3. Linkers combine compiled code fragments into single memory-loadable executable $ ld obj1.o obj2.o –o linked.o symbol resolution program components reference each other through symbols (ELF .symtab) Relocation adjustment of code/data sections (also performed by the loader)
  • 4. Loaders copy code and data into memory memory allocation/mapping relocation Also performed by the linker execve()
  • 5. Libraries statically-linked dynamically-linked (shared)* collections of reusable compiled code *historically: a shared library was something else entirely
  • 6. Statically-linked libraries code copied into final binary be aware of: cyclic dependencies, multiple symbol definitions $ld obj1.o obj2.o /usr/lib/libname.a CODE my_print() { printf(); } main() { my_print(); } main() { my_print(); } my_print() { printf(); } printf() { vfprintf(); } LIBC STATICALLY LINKED FILESIZE
  • 7. Dynamically-linked libraries dynamic loader (ld.so) resolves symbols at exectime Process: - execve() loads executable code into memory
  • 8. - control is passed to the dynamic linker (ld.so) which maps shared objects to program address space (resolves symbols)
  • 9. - control is then passed to the application can be called from within the application at runtime By linking ld and calling dlopen(), etc. CODE my_print() { printf(); } main() { my_print(); } main() { my_print(); } my_print() { printf(); } printf(); DYNAMICALLY LINKED FILESIZE LIBC
  • 10. So what is LD_PRELOAD? environment var queried by dynamic linker on exec allows dynamic linker to prioritize linking defined shared libs $ LD_PRELOAD=“./mylib.so” ./myexec
  • 11. Attack enablers OS ‘features’ weak system security good coding practices general_rule: good_for_devs == good_for_hackers ; goto general_rule ;
  • 12. Attack advantages easy, effective on unprotected systems code interception code injection program flow manipulation debugging using wrapper functions
  • 13. Attack disadvantages } can be protected against requires access to executable requires relevant privileges works on used, imported symbols
  • 14. Example 1 – Hello World $ nm -D make_goodbye.so 000000000000069c T printf U stdout U vfprintf $ nm -D hello w __gmon_start__ U __libc_start_main U printf Undefined symbol Symbol exists in .text
  • 15. Example 1 – Hello World – cont. *in practice it works slightly differently – this is just a conceptual explanation NORMAL SYMBOL RESOLUTION: LOADER HELLO printf() ?? DYNAMIC LINKER LIBC.SO Hello World! REDIRECTED SYMBOL RESOLUTION: LOADER HELLO printf() ?? DYNAMIC LINKER GOODBYE.SO Goodbye World! LIBC.SO fprintf() ??
  • 16. Example 2 – OpenSSH MITM dynamically links openssl checks public key against known_hosts with BN_cmp() BN_cmp() must pass (== 0) for iterations 3 and 5
  • 17. Example 3 – OpenSSH password logger catch write() w/ string literal “’s password” log read()s until ‘\n’
  • 18. Example 4 – Extending ‘cat’ functionality intercept __snprintf_check() to add to usage() wrap getopt_long() to catch new command line option catch write(), vfork() and launch browser for each link
  • 19. provides reusable library of function sigs (sorry about the code quality!) ./preloader reduces repetitive tasks tool that does *some* of the work for you http://www.github.com/2of1/preloader
  • 20. Reverse Engineering with LD_PRELOAD (Itzik Kotler) http://securityvulns.com/articles/reveng/ Linkers and Loaders (Sandeep Grover) http://www.linuxjournal.com/article/6463 Dynamic Linker (Wikipedia) http://en.wikipedia.org/wiki/Dynamic_linker man ld.so Further reading
  • 21. “ Know your enemy and know yourself and you can fight a thousand battles without disaster” Sun Wu Tzu, The Art of War “ There is no right and wrong. There’s only fun and boring” The Plague, Hackers 1995 Final thoughts