GithubHelp home page GithubHelp logo

ld-shatner's Introduction

                              ld-shatner


Purpose
-------

Inject code at runtime, just between the ELF loader and target
binary. It is an alternative to LD_PRELOAD feature, just a little bit
more intrusive :)

Screenshot
----------

$ make clean all
$ cp /lib/ld-linux.so.2 /bin/ls .
$ ./ld-shatner ld-linux.so.2 obj.elf
$ sudo cp ld-hook.so /lib/
$ ./interpatch ls
$ ./ls 
ld-hook <---------------------- output of obj.elf
[...]

The newly generated 'ls' uses our freshly generated 'ld-hook.so' acting
as its dynamic interpreter. The code from 'obj.elf' is executed before
'ls' entry point.

How to
------

When an ELF binary is execve(), the kernel extracts from the file the
interpreter to be executed, usually, it is /lib/ld-linux.so.2.

The kernel creates a new process and prepares the environment
(arguments and auxiliary data). The target ELF entry point is set in
auxiliary vector of type "ENTRY".

Then the kernel opens the requested interpreter, maps the memory
regions and start its execution at ld's ELF entry point. Then the
loader analyzes the target ELF file, do its loader work and set EIP to
target ELF entry point (extracted from auxv). At this point, main()'s
program is eventually executed.

Our goal was to permit the execution of code for abitrary dynamically
linked binary without patching each of them. So our interest moved on
the loader, the common point between most executables. Thus, we
decided to patch a normal ld in order to inject code. Welcome
ld-shatner!

Its task is to modify the ld-linux.so file accordingly:

  1. After ELF header, we shift "ELF program header" a few pages away

  2. In this new section, we inject a "loader routine" (hooked.s) and
     the embedded code to be executed at runtime

  3. After having been saved in our section, ld's ELF entry point is
     overwritten to jump directly on our routine. This routine
     extracts from auxiliary vectors the target ELF entry point and
     overwrites it with a pointer to our embedded code (the payload).

  4. Original ld's entry point is called and ld works as usual

  5. Eventually, it calls entry point set in auxiliary vector (which
     was replaced by a pointer to our payload)

  6. Injected code runs

  7. It returns to our routine which finally jumps on original target
     entry point


Why this name?
--------------

This tool provides a way to hook ELF binary, it would have been too
easy to call this project ld-"hooker". Instead, we dedicate this tool
to one of the greatest TV show of all time, played by William Shatner,
Hooker. Sorry :)

Authors
-------

Stéphane Duverger, Nicolas Bareil (EADS France)

ld-shatner's People

Contributors

nbareil avatar sduverger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.