Git Product home page Git Product logo

linux-kernel-so-injector's Introduction

linux-kernel-so-injector

TL;DR

Linux kernel mode to user mode so injection

Tested on linux kernel version: 4.19.91. Current version depends on libc, but it's easy to change it.

Inject shared library to target process from the kernel

How it works

The injection process is divided into several stages:

  1. Send SIGSTOP to target process
  2. Find free space for our shellcode (any R^X pages) using /proc/PID/maps
  3. Find libc address using /proc/PID/maps
  4. Parse libc elf at runtime to find __libc_dlopen_mode
  5. Get the target process rip register
  6. Build our shellcode (get_shellcode function) with the correct address of:
    • So file path
    • Previous rip register address (in order to reconsturct the running of the process after loading the so from our shellcode)
    • __libc_dlopen_mode address (using this function in libc, we will load our so)
  7. Write to target process memory the so file path
  8. Write the shellcode to target process memory
  9. Set target process rip register to the shellcode address
  10. Send SIGCONT to target process

The whole process described above happens at the kernel module. The only things that the kernel module needs are: target pid, so file path.

Limitations

  • Currently there is no support for syscalls from the type that need EINTR or restart_syscall when stopped by signal.
  • Currently implemented only for x86_64.
  • This code isn't robust or fully tested. Therefore, you should expect bugs to occur under certain conditions when process getting non-stop signals or other edge cases.
  • The shellcode and so path won't cleaned because I didn't have enough time to implement it from different kernel thread, but there is a commit which all the cleanup code available. However, the kernel thread isn't and without the creation of new kernel thread it will stick the injection.
  • The reconstruction isn't fully (r15 isn't restored).

All of the limitations which mentioned above could be solved.

linux-kernel-so-injector's People

Contributors

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