• Stars
    star
    317
  • Rank 132,216 (Top 3 %)
  • Language
    C
  • License
    BSD 3-Clause "New...
  • Created almost 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An improvement of the original reflective DLL injection technique by Stephen Fewer of Harmony Security

This is an improvement of the original reflective DLL injection technique by Stephen Fewer of Harmony Security. It uses bootstrap shellcode (x86 or x64) to allow calling any export of the DLL from the reflective loader. See An Improved Reflective DLL Injection Technique for a detailed description.

About

Reflective DLL injection is a library injection technique in which the concept of reflective programming is employed to perform the loading of a library from memory into a host process. As such the library is responsible for loading itself by implementing a minimal Portable Executable (PE) file loader. It can then govern, with minimal interaction with the host system and process, how it will load and interact with the host.

Injection works from Windows NT4 up to and including Windows 8, running on x86 and x64.

Overview

The process of remotely injecting a library into a process is two fold. Firstly, the library you wish to inject must be written into the address space of the target process (Herein referred to as the host process). Secondly the library must be loaded into that host process in such a way that the library's run time expectations are met, such as resolving its imports or relocating it to a suitable location in memory.

Assuming we have code execution in the host process and the library we wish to inject has been written into an arbitrary location of memory in the host process, Reflective DLL Injection works as follows.

  • Execution is passed via a tiny bootstrap shellcode to the library's ReflectiveLoader function which is an exported function found in the library's export table.
  • As the library's image will currently exist in an arbitrary location in memory the ReflectiveLoader will first calculate its own image's current location in memory so as to be able to parse its own headers for use later on.
  • The ReflectiveLoader will then parse the host processes kernel32.dll export table in order to calculate the addresses of four functions required by the loader, namely LoadLibraryA, GetProcAddress, VirtualAlloc, and ExitThread.
  • The ReflectiveLoader will now allocate a continuous region of memory into which it will proceed to load its own image. The location is not important as the loader will correctly relocate the image later on.
  • The library's headers and sections are loaded into their new locations in memory.
  • The ReflectiveLoader will then process the newly loaded copy of its image's import table, loading any additional libraries and resolving their respective imported function addresses.
  • The ReflectiveLoader will then process the newly loaded copy of its image's relocation table.
  • The ReflectiveLoader will then call its newly loaded image's entry point function, DllMain with DLL_PROCESS_ATTACH. The library has now been successfully loaded into memory.
  • The ReflectiveLoader will then call a chosen exported function, passing a caller-specified pointer and DWORD as parameters.
  • Finally the ReflectiveLoader will terminate the thread by calling ExitThread or, if available, RtlExitUserThread.

Build

Open the 'rdi.sln' file in Visual Studio C++ and build the solution in Release mode to make inject.exe and reflective_dll.dll

Usage

To test, run inject.exe using an arbitrary test string and the PID of a process to inject into, e.g.:

inject.exe foobar 1234

License

Licensed under a 3 clause BSD license, please see LICENSE.txt for details.

More Repositories

1

linux-injector

Utility for injecting executable code into a running process on x86/x64 Linux
C
256
star
2

CaseHarvester

AWS-based application for scraping the Maryland Judiciary Case Search
Python
50
star
3

MediaGrid

MediaGrid is a takedown-resistant, distributed wireless infrastructure allowing citizens to communicate and share real-time photo and video documentation at public demonstrations, without the need for internet access.
JavaScript
32
star
4

onetimesecret-docker

Dockerized version of One-Time Secret
Shell
24
star
5

NOISE

NOISE creates "real-looking" text based upon a collection of reference texts, which can then be used in emails, tweets, web searches, IRC chats, or any other medium you can think of that makes it a bit too easy to profile an individual's communication habits.
Python
16
star
6

CaseExplorer

Web application and APIs for exploring MD court case data
Python
6
star
7

twitter-purge

Deletes your tweets and unfaves your favorites older than X days
Python
5
star
8

lunchbox

Physical drop box for penetration testing
Shell
3
star
9

squeeler

MSSQL enumeration and exploitation toolkit
Go
3
star
10

commotion-apps

Commotion luci application portal
Lua
2
star
11

Invoke-ReflectivePEInjection

PowerSploit script updated to work on Windows 10 1803+
PowerShell
2
star
12

case-search-forever

Bypass that goddamn CAPTCHA on the Maryland Judiciary Case Search
JavaScript
2
star
13

namecheap-dyndns

Dynamic DNS script for Namecheap
Python
1
star
14

commotion-splash

LuCI interface for configuring nodogsplash
Lua
1
star
15

CaseExplorerAPIPortal

API developer portal for Maryland court case data
JavaScript
1
star
16

skylight-scraper

Sync photos from a Skylight frame to a local directory
Python
1
star