• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    Python
  • Created about 4 years ago
  • Updated about 4 years ago

Reviews

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

Repository Details

Dll that can be used for side loading and other attack vector.

DLLsForHackers

Dlls that can be used for side loading and other attack vectors. This Dll will not cause deadlock since it only use functions that are DllMain safe as described below.

Why?

I've seen too many POC with code been executed in the DLL_PROCESS_ATTACH. In fact most of the time the malcious code will not work as stated by Microsoft (https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices).

You should never perform the following tasks from within DllMain:

  • Call LoadLibrary or LoadLibraryEx (either directly or indirectly). This can cause a deadlock or a crash.
  • Call GetStringTypeA, GetStringTypeEx, or GetStringTypeW (either directly or indirectly). This can cause a deadlock or a crash.
  • Synchronize with other threads. This can cause a deadlock.
  • Acquire a synchronization object that is owned by code that is waiting to acquire the loader lock. This can cause a deadlock.
  • Initialize COM threads by using CoInitializeEx. Under certain conditions, this function can call LoadLibraryEx.
  • Call the registry functions. These functions are implemented in Advapi32.dll. If Advapi32.dll is not initialized before your DLL, the DLL can access uninitialized memory and cause the process to crash.
  • Call CreateProcess. Creating a process can load another DLL.
  • Call ExitThread. Exiting a thread during DLL detach can cause the loader lock to be acquired again, causing a deadlock or a crash.
  • Call CreateThread. Creating a thread can work if you do not synchronize with other threads, but it is risky.
  • Create a named pipe or other named object (Windows 2000 only). In Windows 2000, named objects are provided by the Terminal Services DLL. If this DLL is not initialized, calls to the DLL can cause the process to crash.
  • Use the memory management function from the dynamic C Run-Time (CRT). If the CRT DLL is not initialized, calls to these functions can cause the process to crash.
  • Call functions in User32.dll or Gdi32.dll. Some functions load another DLL, which may not be initialized. Use managed code.

Only the following are considered safe

The following tasks are safe to perform within DllMain:

  • Initialize static data structures and members at compile time.
  • Create and initialize synchronization objects.
  • Allocate memory and initialize dynamic data structures (avoiding the functions listed above.)
  • Set up thread local storage (TLS).
  • Open, read from, and write to files.
  • Call functions in Kernel32.dll (except the functions that are listed above).
  • Set global pointers to NULL, putting off the initialization of dynamic members. In Microsoft Windows Vistaโ„ข, you can use the one-time initialization functions to ensure that a block of code is executed only once in a multithreaded environment.

Why using msvcrt!system

As stated by Microsoft calling CreateProcess should be avoided Creating a process can load another DLL.. However, for all my test system() call stack seems to be safe. For reference here is the system() call stack:

int __cdecl system(const char *Command)
    intptr_t __cdecl spawnvpe(int Mode, const char *Filename, const char *const *ArgList, const char *const *Env)
        intptr_t __cdecl spawnve(int Mode, const char *Filename, const char *const *ArgList, const char *const *Env)
            signed __int64 __fastcall comexecmd_0(unsigned int a1, __int64 a2, __int64 a3, __int64 a4)
                signed __int64 __fastcall dospawn(signed int a1, const CHAR *a2, __int64 a3, void *a4)
                    BOOL __stdcall CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)          

Usage

python3 GenDll.py --help
DLLsForHackers Mr.Un1k0d3r RingZer0 Team
----------------------------------------

usage: GenDll.py [-h] -t {exec,dropexec} [-com COMPILE] [-c CMD] [-fn FILENAME] [-fp FILEPATH] [-v {true,false}]

optional arguments:
  -h, --help            show this help message and exit
  -t {exec,dropexec}, --type {exec,dropexec}
                        Payload type (exec,dropexec)
  -com COMPILE, --compile COMPILE
                        Path to mingw32-g++.exe
  -c CMD, --cmd CMD     Command to run
  -fn FILENAME, --filename FILENAME
                        Dropped filename (optional)
  -fp FILEPATH, --filepath FILEPATH
                        File to drop on the remote host
  -v {true,false}, --verbose {true,false}
python3 GenDll.py -t dropexec --com "C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\x86_64-w64-mingw32-g++.exe" --payload binary.exe
DLLsForHackers Mr.Un1k0d3r RingZer0 Team
----------------------------------------

[+] Loading drop exec dll payload.
[+] Loading payload.exe.
[+] Dll source saved as 'output/dropexec-1600369623.c'.
[*] Compiling the Dll using 'C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\x86_64-w64-mingw32-g++.exe' as the gcc path.
[*] Compiling the Dll using the following command '"C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\x86_64-w64-mingw32-g++.exe" -Wall -DBUILD_DLL -O2 -c output/dropexec-1600369623.c -o output/dropexec-1600369623.c.o && "C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\x86_64-w64-mingw32-g++.exe" -shared -Wl,--dll output/dropexec-1600369623.c.o -o output/dropexec-1600369623.c.dll'.
[+] Compiled Dll saved as 'dlls/dropexec-1600369623.c.dll'.
[+] Process completed.

Compile it using GCC

  • Exec (exec.c)
mingw32-g++.exe -Wall -DBUILD_DLL -O2 -c exec.c -o exec.o
mingw32-g++.exe -shared -Wl,--dll exec.o -o exec.dll
  • Drop Exec (dropexec.c)
mingw32-g++.exe -Wall -DBUILD_DLL -O2 -c dropexec.c -o dropexec.o
mingw32-g++.exe -shared -Wl,--dll dropexec.o -o dropexec.dll

Credit

Mr.Un1k0d3r RingZer0 Team

More Repositories

1

EDRs

C
1,857
star
2

PowerLessShell

Run PowerShell command without invoking powershell.exe
Python
1,413
star
3

DKMC

DKMC - Dont kill my cat - Malicious payload evasion tool
Python
1,323
star
4

SCShell

Fileless lateral movement tool that relies on ChangeServiceConfigA to run command
C
1,268
star
5

RedTeamPowershellScripts

Various PowerShell scripts that may be useful during red team exercise
PowerShell
878
star
6

MaliciousMacroGenerator

Malicious Macro Generator
Visual Basic
811
star
7

ThunderShell

Python / C# Unmanaged PowerShell based RAT
Python
770
star
8

RedTeamCSharpScripts

C# Script used for Red Team
C#
706
star
9

RedTeamCCode

Red Team C code repo
C
464
star
10

CatMyPhish

Search for categorized domain
Python
418
star
11

PoisonHandler

lateral movement techniques that can be used during red team exercises
PowerShell
264
star
12

MaliciousClickOnceGenerator

Quick Malicious ClickOnceGenerator for Red Team
C#
234
star
13

ADHuntTool

official repo for the AdHuntTool (part of the old RedTeamCSharpScripts repo)
C#
229
star
14

Windows-SignedBinary

Python
224
star
15

.NetConfigLoader

.net config loader
223
star
16

Shellcoding

Shellcoding utilities
C
209
star
17

ATP-PowerShell-Scripts

Microsoft Signed PowerShell scripts
PowerShell
203
star
18

WindowsDllsExport

A list of all the DLLs export in C:\windows\system32\
C
199
star
19

AMSI-ETW-Patch

Patch AMSI and ETW
C#
196
star
20

MaliciousDLLGenerator

DLL Generator for side loading attack
C
163
star
21

SCT-obfuscator

Cobalt Strike SCT payload obfuscator
Python
142
star
22

RedTeamScripts

Repo with various Red Team scripts
Python
137
star
23

Elevate-System-Trusted-BOF

C
132
star
24

Cookie-Graber-BOF

C or BOF file to extract WebKit master key to decrypt user cookie
C
129
star
25

SPFAbuse

SPF are not as strong as you may think. Red Team tool to send email on behalf of your target corp
Python
128
star
26

RemoteProcessInjection

C# remote process injection utility for Cobalt Strike
C#
80
star
27

Base64-Obfuscator

Simple PowerShell Base64 encoder to avoid detection of your malicious payload
PowerShell
74
star
28

SearchIPOwner

Search public IP owner through ARIN
Python
51
star
29

RedTeamFSharp

Red Team Toolset written in F# (Experimental)
F#
26
star
30

SideChannelAttack

Side Channel script
Python
24
star
31

BOFCode

Bunch of BOF files
C
13
star
32

blog.mr.un1k0d3r.com

Mr.Un1k0d3r.com blog
HTML
9
star
33

MsGraphFunzy

Scripts to interact with Microsoft Graph APIs
Python
5
star