Code Monkey home page Code Monkey logo

relocation-reconstructor's Introduction

Relocation Reconstruction

Reconstructing relocations and imports of a binary or shellcode mapped in memory can be very useful both in terms of being able to perform static analysis with a tool such like IDA Pro and have it function properly, and for breaking DRM by having the ability to load a binary for which you don't have PE headers/relocation/IAT information for.

Limitations and requirements

This library requires a C++17 compiler (or later).

It exclusively targets windows binaries, and the rebuilding of the .reloc section and import data is for the Windows PE format, but technically it should handle relocations for other types of executables too with some small changes.

Furthermore, it does require dumping more information than just the binary data for IAT fixing to work, since the program needs to know the addresses of imports at the time of dumping.

Usage

When ran, the program will prompt you to input a folder path for each dump to load. You need atleast 2 dumps from different sessions so the comparison heuristic works properly.

After inputting the dumps, the relocation will start. When this is done sucessfully, it will output a relocated.dll, which has a fixed IAT section and .reloc section appended to it, along with a file called reloc_info.txt, which contains various relocation, iat, and memory reference information which can be used to properly load the relocated dll.

An example of a run can look like the following: run

Input data and format

In the same directory as the executable, have a folder for each unique dump that you are going to compare, the folder which you input must contain 2 files, a file called mem.bin, and a file called exports.txt.

mem.bin is the raw binary data of the executable/shellcode you want to fix. exports.txt contains the addresses for all the functions exported by every dll loaded in the process at the time of dump. This looks something like the following, where the long number is the address of said function:

{
    "example_lib.dll": {
        "exported_fn": 140721494140440,
        "some_other_fn": 140721494140467,
        ...
    },
    "ntdll.dll": {
        "A_SHAFinal": 140721518593232,
        "A_SHAInit": 140721518593536,
        "A_SHAUpdate": 140721518593600,
        ...
    },
    ...
}

Static analysis

The output dll, which has the fixed IAT's and relocation section appended to it will still have an invalid PE header, so this needs to be manually fixed before it can be loaded into a dissasembler. Fixing the headers to be compatible with a dissasembler is quite trivial with a program like CFF Explorer, where you can easily modify the header. After this is done it should be like analyzing a binary which had its relocations and IAT's intact.

Loading a relocated binary

Please refer to the file load_example.cpp to see an example how the output of the reconstructor can be used to load and execute a relocated binary

relocation-reconstructor's People

Contributors

flawww avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

relocation-reconstructor's Issues

Error during compile - using MSVC C++17

I'm seeing this error during the compiling of your program (using Visual Studio Enterprise 2022);

'&' requires l-value

triggered within "module_relocation_information.cpp", line 112

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.