Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit ae378ad

Browse files
committed
Updated DLLirant to the v0.4 version
Visual Studio has been replaced by LLVM to increase the OPSEC (no more visual studio paths visible in the DLL after the build).
1 parent e1ca7a3 commit ae378ad

File tree

7 files changed

+23
-211
lines changed

7 files changed

+23
-211
lines changed

DLLirant.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def ascii():
4444
print('██▪ ██ ██• ██• ██ ▀▄ █·▐█ ▀█ •█▌▐█•██ ')
4545
print('▐█· ▐█▌██▪ ██▪ ▐█·▐▀▀▄ ▄█▀▀█ ▐█▐▐▌ ▐█.▪')
4646
print('██. ██ ▐█▌▐▌▐█▌▐▌▐█▌▐█•█▌▐█ ▪▐▌██▐█▌ ▐█▌·')
47-
print('▀▀▀▀▀• .▀▀▀ .▀▀▀ ▀▀▀.▀ ▀ ▀ ▀ ▀▀ █▪ ▀▀▀ v0.3')
47+
print('▀▀▀▀▀• .▀▀▀ .▀▀▀ ▀▀▀.▀ ▀ ▀ ▀ ▀▀ █▪ ▀▀▀ v0.4 - Sh0ck (@Sh0ckFR)')
4848

4949
def rreplace(s, old, new):
5050
return (s[::-1].replace(old[::-1],new[::-1], 1))[::-1]
@@ -98,8 +98,8 @@ def get_imports_functions(dll_name, imports):
9898

9999
def generate_test_dll(functions = None):
100100
exported_functions = []
101-
with open('DLLirantDLL\\dllmain-preset.c', 'r') as fin:
102-
with open('DLLirantDLL\\dllmain.c', 'w') as fout:
101+
with open('DLLirantDLL\\dllmain-preset.cpp', 'r') as fin:
102+
with open('DLLirantDLL\\dllmain.cpp', 'w') as fout:
103103
if functions is not None:
104104
for line in fin:
105105
if '##DLL_MAIN##' in line:
@@ -113,7 +113,7 @@ def generate_test_dll(functions = None):
113113
else:
114114
for func in functions:
115115
if len(func) > 0:
116-
exported_functions.append(f'__declspec(dllexport) void {func}()' + '{ Main(); }')
116+
exported_functions.append(f'extern "C" __declspec(dllexport) void {func}()' + '{ Main(); }')
117117
exported_functions = '\n'.join(exported_functions)
118118
fout.write(line.replace('##EXPORTED_FUNCTIONS##', exported_functions))
119119
else:
@@ -126,13 +126,17 @@ def generate_test_dll(functions = None):
126126
fout.write(line.replace('##EXPORTED_FUNCTIONS##', ''))
127127
else:
128128
fout.write(line)
129-
os.system('cd DLLirantDLL && msbuild DLLirantDLL.sln /t:Rebuild /p:Configuration=Release /p:Platform="x64"')
129+
os.system('cd DLLirantDLL && clang++ dllmain.cpp -o DLLirantDLL.dll -shared')
130+
delete_file('DLLirantDLL\\DLLirantDLL.exp')
131+
delete_file('DLLirantDLL\\DLLirantDLL.lib')
132+
delete_file('DLLirantDLL\\dllmain.cpp')
130133
return exported_functions
131134

132135
def check_dll_hijacking(binary_name, binary_original_directory, dll_name, exported_functions = 'DllMain'):
133-
if not os.path.exists(f'DLLirantDLL\\x64\\Release\\DLLirantDLL.dll'):
136+
if not os.path.exists('DLLirantDLL\\DLLirantDLL.dll'):
134137
return False
135-
os.system(f'copy DLLirantDLL\\x64\\Release\\DLLirantDLL.dll output\\{dll_name}')
138+
os.system(f'copy DLLirantDLL\\DLLirantDLL.dll output\\{dll_name}')
139+
delete_file('DLLirantDLL\\DLLirantDLL.dll')
136140
ascii()
137141
print('==================================================')
138142
print(f'[+] Testing {dll_name}')
@@ -177,8 +181,11 @@ def generate_proxy_dll():
177181
exported_functions.append(f'#pragma comment(linker,"/export:{func}={name_dll}.{func},@{entry.ordinal}")')
178182
exported_functions = '\n'.join(exported_functions)
179183

184+
ascii()
180185
generate_test_dll(exported_functions)
181-
print(f'\n\n[+] Rename the original dll file {name_dll}.dll and copy the compiled dll to the original directory as {original_name}')
186+
os.system(f'copy DLLirantDLL\\DLLirantDLL.dll output\\DLLirantProxy.dll')
187+
delete_file('DLLirantDLL\\DLLirantDLL.dll')
188+
print(f'\n\n[+] Rename the original dll file {name_dll}.dll and copy the compiled dll DLLirantProxy.dll to the original directory as {original_name}')
182189

183190
def main():
184191
if ARGS.proxydll:
@@ -191,6 +198,8 @@ def main():
191198
# Create or recreate the directory used by the DLLirant DLL specified in dllmain-preset.c file.
192199
delete_dir('C:\\DLLirant')
193200
create_dir('C:\\DLLirant')
201+
delete_dir('output')
202+
create_dir('output')
194203

195204
# Name of the binary specified and his directory.
196205
binary_name = os.path.basename(ARGS.file)

DLLirantDLL/DLLirantDLL.sln

Lines changed: 0 additions & 31 deletions
This file was deleted.

DLLirantDLL/DLLirantDLL.vcxproj

Lines changed: 0 additions & 163 deletions
This file was deleted.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include <windows.h>
22
#include <stdio.h>
3-
#include <stdlib.h>
3+
4+
#pragma comment (lib, "User32.lib")
45

56
int Main() {
67
FILE* fptr;
7-
fptr = fopen("C:\\DLLirant\\output.txt", "w");
8+
fopen_s(&fptr, "C:\\DLLirant\\output.txt", "w");
89
fprintf(fptr, "%s", "It works !\n");
910
fclose(fptr);
1011
MessageBoxW(0, L"DLL Hijack found!", L"DLL Hijack", 0);

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@ DLLirant is a tool to automatize the DLL Hijacking researches on a specified bin
99

1010
## How to install
1111

12-
You need to install Visual Studio Community Edition or superior.
13-
14-
Start `DLLirantDLL.sln` in the directory "DLLirantDLL" to update the Visual Studio version on the project, select "Release x64" in the Visual Studio top menu, select your build tools available in the project properties and close Visual Studio (just one time).
15-
16-
Install pefile from pip:
12+
* Install LLVM for Windows: https://llvm.org/builds/
13+
* Do not forget to check the "Add LLVM to the system PATH for current user" during the installation.
14+
* Install pefile from pip:
1715

1816
```
1917
pip3 install pefile
2018
```
2119

2220
## How to use
2321

24-
In a first time you need to start a command line with the tool `x64 Native Tools Command Prompt for VS` (search with the windows touch)
25-
2622
Use the `cd` command to your DLLirant directory and to test a binary:
2723

2824
```

live.gif

-621 KB
Loading

screenshot.png

-10.7 KB
Loading

0 commit comments

Comments
 (0)