Code Monkey home page Code Monkey logo

e9syscall's Introduction

E9Syscall -- Linux System Call Interception

E9Syscall is a system call interception toolkit for x86_64 Linux.

E9Syscall uses E9Patch to statically rewrite libc.so into a new version with all system calls intercepted. Unlike other interception tools, E9Syscall does not rely on ptrace or signal handlers (SIGTRAP).

Build

To build E9Syscall, simply run the build.sh script:

     $ ./build.sh

Usage

To use E9Syscall:

  1. Implement your system call hook routine, e.g., in a file hook.c. See the examples/ directory for some examples.

  2. Build a replacement libc.so using the command:

      $ ./e9syscall hook.c
    

This will build a modified libc-hook.so file which will call the hook function every time a system call is executed. To use, simply LD_PRELOAD the new library to replace the default, e.g.:

    $ LD_PRELOAD=$PWD/libc-hook.so ls

The hook function has the following type signature:

    int hook(intptr_t arg1,
             intptr_t arg2,
             intptr_t arg3,
             intptr_t arg4,
             intptr_t arg5,
             intptr_t arg6,
             intptr_t *result);

The behavior depends on the return value of the took function.

  • If zero, the original system call will be executed as normal.
  • If non-zero, the original system call will be replaced with by *result.

This allows for system calls to be instrumented (if zero) or replaced (if non-zero), depending on the application. This design was inspired by syscall_intercept.

Example

The examples/encrypt.c hook will "encrypt" all stderr/stdout using ROT13. To build, simply run:

    $ ./e9syscall examples/encrypt.c

This will build a modified libc-encrypt.so file.

By default, the output of the ls command is not encrypted:

Default ls

By using LD_PRELOAD and libc-encrypt.so, the output of the ls command is automatically encrypted:

Encrypted ls

See the examples/*.c files for other example hook functions.

Limitations

For technical reasons, the SYS_rt_sigreturn and SYS_clone system calls cannot be replaced.

The instrumentation code is somewhat limited, including:

  • Cannot directly call libc functions (using system calls directly is OK)
  • Cannot safely use/clobber floating point registers
  • Stack may not be aligned

These limitations are inherited from the underlying E9Patch tool.

There is a chance that not call system calls can be intercepted, in which case a warning will be printed. However, it seems to work for all versions of libc tested so far.

About

E9Syscall is a thin E9Patch wrapper, which is a powerful static binary rewriting tool for x86_64 Linux.

Basically, E9Syscall invokes E9Patch to replace all syscall instructions with a call to a trampoline that invokes the hook function. Since the interception does not use ptrace or signal handlers, it is very fast.

Related Tools

A few different system call interception libraries and tools have been developed, including:

Library/Tool ptrace? SIGTRAP?
syscall_intercept
SaBRe
libsystrap
ptrace_do
fssb

Some tools use ptrace or signal handlers, however this is generally slow since it involves context switching. E9Syscall calls the hook function directly without one (or more) context switches.

Like E9Syscall, both syscall_intercept and SaBRe also use binary rewriting. However, these tools use a different rewriting methodology, including:

  1. replacing multiple instructions with jumps; and/or
  2. replacing NOP-padding with jumps.

This assumes that both 1. and 2. do not affect jump targets, which is not sound in the general case. However, for limited applications such as system call interception, it is probably OK in practice.

E9Syscall uses E9Patch to safely rewrite syscall instructions without modifying jump targets. Please see here for more information.

License

GPLv3

e9syscall's People

Contributors

gjduck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  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.