LoadLibrary for offensive operations

Overview

DarkLoadLibrary

LoadLibrary for offensive operations.

How does is work?

https://www.mdsec.co.uk/2021/06/bypassing-image-load-kernel-callbacks/

Usage

DARKMODULE DarkModule = DarkLoadLibrary(
    LOAD_LOCAL_FILE, // control flags
    L"TestDLL.dll", // local dll path, if loading from disk
    NULL, // DLL Buffer to load from if loading from memory
    0, // dll size if loading from memory
    NULL // dll name if loaded from memory
);

Control Flags:

  • LOAD_LOCAL_FILE - Load a DLL from the file system.
  • LOAD_MEMORY - Load a DLL from a buffer.
  • NO_LINK - Don't link this module to the PEB, just execute it.

DLL Path:

This can be any path that CreateFileW will open.

DLL Buffer:

This argument is only needed when LOAD_MEMORY is set. In that case this argument should be the buffer containing the DLL.

DLL Size:

This argument is only needed when LOAD_MEMORY is set. In that case this argument should be the size of the buffer containing the DLL.

DLL Name:

This argument is only needed when LOAD_MEMORY is set. In that case this argument should be the name which the DLL should be set in the PEB under.

Considerations

The windows loader is very complex and can handle all the edge case's and intricacies of loading DLLs. There are going to be edge case's which I have not had the time to discover, reverse engineer and implement. So there's going to be DLLs that this loader simply will not work with.

That being said I plan on making this loader as complete as possible, so please open issue's for DLLs that are not correctly loaded.

Comments
  • Find DLL exports

    Find DLL exports

    Hello again 😄

    With this PR, we find the export address of all DLL functions ourselves, so we no longer rely on GetProcAddress and LdrGetProcedureAddress. The idea is to stay away from Kernel32 and NTDLL as much as possible. Resolving several functions might lead to detection

    I have tried to resolve all exports of Kernel32, NTDLL, User32. vcruntime40 and stdlib and it worked very well, so I am confident the implementation is solid.

    One interesting thing I found while developing this: For some weird reason, Kernel32 (and a few others) exports some functions that aren't really defined in Kernel32, but in other libraries (maybe everybody knew this but me?) When you try to resolve those functions, you get a pointer to a string that describes where that function is truly defined. For example, AcquireSRWLockExclusive is a function exported by Kernel32, that resolves to an address that has this string: NTDLL.RtlAcquireSRWLockExclusive, meaning the function is defined in ntdll as RtlAcquireSRWLockExclusive. So that is why the function is recursive, it needs to handle those cases. (luckily your test DLL loads one of these "fake" exports, so I was able to find this behavior)

    Anyway, hope you find it useful

    Edit: I have also found that in some weird cases, libraries such as Kernel32 does this thing where a function "points" to another library and function name, but the library is like deprecated and the function is in truth implemented in Kernel32. That is why if the resolve fails, it tries with Kernel32 and KernelBase. You can try to resolve all exports of the DLL you like and compare the result with what LdrGetProcedureAddress says it is and confirm that it works for all cases. Let me know if this is unclear and you want to clarify something.

    opened by physics-sec 3
  • find all import addresses dinamically

    find all import addresses dinamically

    Hey there! The main idea of this PR is not only to have less static-imports to make the final binary less interesting to static analysis, but to start to make DarkLoadLibrary able to be injected as shellcode directly on memory. My final goal would be to integrate it with Cobalt Strike as a User Defined Reflective Loader, this is just one step on that direction.

    Hope you find it useful!

    opened by physics-sec 2
  • add NtAllocateVirtualMemory and NtProtectVirtualMemory syscalls

    add NtAllocateVirtualMemory and NtProtectVirtualMemory syscalls

    Hello @bats3c 😄 I'm a big fan of this project, I'm very impressed by your work.

    This is of course to bypass userland hooks. VirtualProtect is likely to get denied by an EDR when making memory pages executable. VirtualAlloc isn't as risky but I just replaced it to hide big allocations to stay under the radar.

    I used SysWhispers2 so it should work for all versions of Windows, I tested it on a Windows 10 21H1 and it works very nicely.

    opened by physics-sec 2
  • Add .gitignore for Visual Studio files, fix Visual Studio Debug configuration.

    Add .gitignore for Visual Studio files, fix Visual Studio Debug configuration.

    Hey,

    Added a .gitignore file, so stupid directories like .vs don't get into the git. Also modified the debug configuration.

    1. ntdll.lib wasn't being linked
    2. weird "Address Sanatizer" option
    3. Include directory was set for your build chain, not using macros
    opened by hypervis0r 2
  • Hello, doesn't DarkLoadLibrary support x86?

    Hello, doesn't DarkLoadLibrary support x86?

    I use vs2019's x64 to compile normally, but it fails to compile on X86.

    1>Assembling src\syscallsstubs.asm...
    1>src\syscallsstubs.asm(1): error A2013: .MODEL must precede this directive
    1>src\syscallsstubs.asm(5): error A2034: must be in segment block : NtProtectVirtualMemory
    1>src\syscallsstubs.asm(6): error A2034: must be in segment block
    1>src\syscallsstubs.asm(7): error A2034: must be in segment block
    1>src\syscallsstubs.asm(8): error A2034: must be in segment block
    1>src\syscallsstubs.asm(9): error A2034: must be in segment block
    1>src\syscallsstubs.asm(10): error A2034: must be in segment block
    1>src\syscallsstubs.asm(11): error A2034: must be in segment block
    1>src\syscallsstubs.asm(12): error A2034: must be in segment block
    1>src\syscallsstubs.asm(13): error A2034: must be in segment block
    1>src\syscallsstubs.asm(14): error A2034: must be in segment block
    1>src\syscallsstubs.asm(15): error A2034: must be in segment block
    1>src\syscallsstubs.asm(16): error A2034: must be in segment block
    1>src\syscallsstubs.asm(17): error A2034: must be in segment block
    1>src\syscallsstubs.asm(18): error A2034: must be in segment block
    1>src\syscallsstubs.asm(19): error A2034: must be in segment block
    1>src\syscallsstubs.asm(20): error A2034: must be in segment block
    1>src\syscallsstubs.asm(21): fatal error A1010: unmatched block nesting : NtProtectVirtualMemory
    
    opened by maxbad 3
  • [Feature Request] DarkLoadLibrary for DLL Imports

    [Feature Request] DarkLoadLibrary for DLL Imports

    Hey, great tool. Are there any near-term plans to add DarkLoadLibrary loading for a DLL's dependencies/imports? They're current just using LoadLibrary, and I can see you added a note to say support would (hopefully) be added in future (in ldrutils.c).

    opened by williamknows 5
  • Various different memory leaks

    Various different memory leaks

    yeah very few HeapAlloc calls actually get freed. I would fix this myself but that seems more fitting of a punishment for the creator of said leaks.

    ahem @bats3c

    opened by hypervis0r 0
  • Minor refactor for mingw, data type tweaks, and warning removal.

    Minor refactor for mingw, data type tweaks, and warning removal.

    I made a few minor tweaks to better support mingw and to reduce compiler warnings:

    • Added function signatures to corresponding header files to remove no previous declaration for warnings.
    • A new header darkmodule.h was created to contain the _DARKMODULE struct definition. This is so that darkloadlibrary.h can include each of the other headers with their new function signatures.
    • A couple variables were PCHARs instead of PWCHARs.
    opened by SolomonSklash 0
A LoadLibrary injector for CS:GO that automatically bypasses Trusted Mode by disabling various Win32 function hooks.

TrustedInjector This is a LoadLibrary injector for Counter-Strike: Global Offensive. Information It automatically bypasses trusted mode by removing ho

Brandon 19 Jan 6, 2023
TiEtwAgent - PoC memory injection detection agent based on ETW, for offensive and defensive research purposes

TiEtwAgent - ETW-based process injection detection This project was created to research, build and test different memory injection detection use cases

Filip Olszak 187 Dec 20, 2022
Bobby Cooke 328 Dec 25, 2022
Grand Programs for every Data Structure including all their operations

Grand-Programs-UE20CS203 Grand Programs for every Data Structure including all their operations Some idioms that I use, so you won't get confused I pr

Aditya Rao 0 Jul 28, 2022
Finite Field Operations on GPGPU

ff-gpu Finite Field Operations on GPGPU Background In recent times, I've been interested in Finite Field operations, so I decided to implement few fie

Anjan Roy 5 Nov 7, 2022
Tests to check the determinism of the basic floating point arithmetic operations on different devices, using Unity and Rust.

This repo contains tests to check the determinism (consistency) of the basic floating point arithmetic operations (add, subtract, multiply, divide) on

Erik Roystan 9 Dec 20, 2022
This is a very short tool that predicts the number of cycles and execution time in Fulcrum when the operands and operations are known.

fulcrum-analytical-tool This is a very short tool that predicts the number of cycles and execution time in Fulcrum when the operands and operations ar

null 2 Feb 6, 2022
Python module for geometric Line operations

FastLine Python module for geometric Line operations implmented in C++ then binded to python, and it is optimized for speed. I created this module to

null 13 Dec 23, 2022
An HTTPS beaconing Windows implant and multi-layered proxy C2 network designed for covert APT emulation focused offensive operations

WARFOX is a software-based HTTPS beaconing Windows implant that uses a multi-layered proxy network for C2 communications. This kit was designed to emulate covert APT offensive operations. This kit includes WARFOX (Windows implant), HIGHTOWER (Listening Post), and other tools to build configs and set up a proxy network.

null 85 Nov 25, 2022
A loadlibrary injector for the game Splitgate that fully bypasses their EQU8 anti-cheat implementation.

splitgate-load-library-injector A loadlibrary injector for the game Splitgate that fully bypasses their EQU8 anti-cheat implementation. Information Th

Hinnie 8 Oct 3, 2022
A LoadLibrary injector for CS:GO that automatically bypasses Trusted Mode by disabling various Win32 function hooks.

TrustedInjector This is a LoadLibrary injector for Counter-Strike: Global Offensive. Information It automatically bypasses trusted mode by removing ho

Brandon 19 Jan 6, 2023
PoC memory injection detection agent based on ETW, for offensive and defensive research purposes

TiEtwAgent - ETW-based process injection detection This project was created to research, build and test different memory injection detection use cases

Filip Olszak 188 Dec 26, 2022
Counter-Strike: Global Offensive Cheat base written in and with C++20 concepts.

Helveta Counter-Strike: Global Offensive Cheat base written in and with C++20 concepts. Features ImDrawList based self contained drawing manager which

cristei 43 Dec 18, 2022
TiEtwAgent - PoC memory injection detection agent based on ETW, for offensive and defensive research purposes

TiEtwAgent - ETW-based process injection detection This project was created to research, build and test different memory injection detection use cases

Filip Olszak 187 Dec 20, 2022
Intel:registered: Homomorphic Encryption Acceleration Library accelerates modular arithmetic operations used in homomorphic encryption

Intel Homomorphic Encryption Acceleration Library (HEXL) Intel ®️ HEXL is an open-source library which provides efficient implementations of integer a

Intel Corporation 166 Dec 30, 2022
Libraries and tools to perform fully homomorphic encryption operations on an encrypted data set.

Fully Homomorphic Encryption (FHE) This repository contains open-source libraries and tools to perform fully homomorphic encryption (FHE) operations o

Google 2.9k Jan 7, 2023
Bolt is an algorithm for compressing vectors of real-valued data and running mathematical operations directly on the compressed representations.

Bolt is an algorithm for compressing vectors of real-valued data and running mathematical operations directly on the compressed representations.

null 2.3k Dec 30, 2022
Bobby Cooke 328 Dec 25, 2022
heaptrace is a ptrace-based debugger for tracking glibc heap operations in ELF64 (x86_64) binaries

heaptrace is a ptrace-based debugger for tracking glibc heap operations in ELF64 (x86_64) binaries. Its purpose is to help visualize heap operations when debugging binaries or doing heap pwn.

Aaron Esau 252 Dec 21, 2022
Grand Programs for every Data Structure including all their operations

Grand-Programs-UE20CS203 Grand Programs for every Data Structure including all their operations Some idioms that I use, so you won't get confused I pr

Aditya Rao 0 Jul 28, 2022