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

Commit cf65370

Browse files
committed
Added DLLirant 0.5 (new version in .NET)
1 parent 368e9d6 commit cf65370

23 files changed

+1412
-0
lines changed

DLLirant.NET.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32421.90
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DLLirant.NET", "DLLirant.NET\DLLirant.NET.csproj", "{AF730346-CEF0-4CC6-A1CA-7FC0F6BA4DF1}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{AF730346-CEF0-4CC6-A1CA-7FC0F6BA4DF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{AF730346-CEF0-4CC6-A1CA-7FC0F6BA4DF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{AF730346-CEF0-4CC6-A1CA-7FC0F6BA4DF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{AF730346-CEF0-4CC6-A1CA-7FC0F6BA4DF1}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {F41CD02F-8AF4-480E-9D6D-C85F33C686E9}
24+
EndGlobalSection
25+
EndGlobal

DLLirant.NET/App.config

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="ControlzEx" publicKeyToken="69f1c32f803d307e" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
11+
</dependentAssembly>
12+
<dependentAssembly>
13+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
14+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
15+
</dependentAssembly>
16+
<dependentAssembly>
17+
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
18+
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
19+
</dependentAssembly>
20+
<dependentAssembly>
21+
<assemblyIdentity name="System.Security.Cryptography.Pkcs" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
22+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="6.0.0.1" />
23+
</dependentAssembly>
24+
<dependentAssembly>
25+
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
26+
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
27+
</dependentAssembly>
28+
<dependentAssembly>
29+
<assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
30+
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
31+
</dependentAssembly>
32+
<dependentAssembly>
33+
<assemblyIdentity name="System.Diagnostics.Tracing" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
34+
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
35+
</dependentAssembly>
36+
</assemblyBinding>
37+
</runtime>
38+
</configuration>

DLLirant.NET/App.xaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Application x:Class="DLLirant.NET.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:DLLirant.NET"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
10+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
11+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
12+
<!-- Theme setting -->
13+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Green.xaml" />
14+
</ResourceDictionary.MergedDictionaries>
15+
</ResourceDictionary>
16+
</Application.Resources>
17+
</Application>

DLLirant.NET/App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace DLLirant.NET
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using System.Management;
6+
7+
namespace DLLirant.NET.Classes
8+
{
9+
internal class CodeGenerator
10+
{
11+
public void GenerateDLL(string dllmain, List<string> importedFunctions = null)
12+
{
13+
string code =
14+
"#include <windows.h>\r\n" +
15+
"#include <stdio.h>\r\n\r\n" +
16+
17+
"#pragma comment (lib, \"User32.lib\")\r\n\r\n" +
18+
"int Main() {\r\n" +
19+
"\tFILE* fptr;\r\n" +
20+
"\tfopen_s(&fptr, \"C:\\\\DLLirant\\\\output.txt\", \"w\");\r\n" +
21+
"\tfprintf(fptr, \"%s\", \"It works !\");\r\n" +
22+
"\tfclose(fptr);\r\n" +
23+
"\tMessageBoxW(0, L\"DLL Hijack found!\", L\"DLL Hijack\", 0);\r\n" +
24+
"\treturn 1;\r\n" +
25+
"}\r\n\r\n" +
26+
"BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)\r\n" +
27+
"{\r\n" +
28+
"\tswitch (ul_reason_for_call) {\r\n" +
29+
"\t\tcase DLL_PROCESS_ATTACH:\r\n" +
30+
"\t\t\t" + dllmain + "\r\n" +
31+
"\t\t\tbreak;\r\n" +
32+
"\t\tcase DLL_THREAD_ATTACH:\r\n" +
33+
"\t\tcase DLL_THREAD_DETACH:\r\n" +
34+
"\t\tcase DLL_PROCESS_DETACH:\r\n" +
35+
"\t\t\tbreak;\r\n" +
36+
"\t}\r\n"+
37+
"\treturn TRUE;\r\n"+
38+
"}\r\n\r\n";
39+
40+
if (importedFunctions != null) { code += string.Join("\n", importedFunctions.ToArray()); };
41+
42+
using (StreamWriter writer = new StreamWriter("output/dllmain.cpp"))
43+
{
44+
writer.WriteLine(code);
45+
}
46+
47+
ExecuteCommand("cmd.exe", "/C clang++.exe dllmain.cpp -o DLLirantDLL.dll -shared");
48+
}
49+
50+
public bool StartExecutable(string path)
51+
{
52+
ExecuteCommand(path);
53+
54+
if (File.Exists("C:\\DLLirant\\output.txt")) {
55+
return true;
56+
}
57+
return false;
58+
}
59+
60+
public void ExecuteCommand(string path, string arguments = null)
61+
{
62+
Process process = new Process();
63+
ProcessStartInfo startInfo = new ProcessStartInfo();
64+
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
65+
startInfo.FileName = path;
66+
if (arguments != null)
67+
{
68+
startInfo.Arguments = arguments;
69+
}
70+
startInfo.WorkingDirectory = $"{Directory.GetCurrentDirectory()}\\output";
71+
process.StartInfo = startInfo;
72+
process.Start();
73+
process.WaitForExit(10000);
74+
KillProcessAndChildrens(process.Id);
75+
}
76+
77+
private static void KillProcessAndChildrens(int pid)
78+
{
79+
ManagementObjectSearcher processSearcher = new ManagementObjectSearcher
80+
("Select * From Win32_Process Where ParentProcessID=" + pid);
81+
ManagementObjectCollection processCollection = processSearcher.Get();
82+
83+
// We must kill child processes first!
84+
if (processCollection != null)
85+
{
86+
foreach (ManagementObject mo in processCollection)
87+
{
88+
KillProcessAndChildrens(Convert.ToInt32(mo["ProcessID"]));
89+
}
90+
}
91+
92+
// Then kill parents.
93+
try
94+
{
95+
Process proc = Process.GetProcessById(pid);
96+
if (!proc.HasExited) proc.Kill();
97+
}
98+
catch (ArgumentException)
99+
{
100+
// Process already exited.
101+
}
102+
}
103+
}
104+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.IO;
3+
4+
namespace DLLirant.NET.Classes
5+
{
6+
internal class FileOperations
7+
{
8+
public void CreateDirectory(string path)
9+
{
10+
if (!Directory.Exists(path))
11+
Directory.CreateDirectory(path);
12+
}
13+
14+
public void DeleteDirectory(string path)
15+
{
16+
if (Directory.Exists(path))
17+
{
18+
try
19+
{
20+
Directory.Delete(path, true);
21+
} catch (UnauthorizedAccessException) { }
22+
}
23+
}
24+
25+
public void CopyFile(string file)
26+
{
27+
if (!File.Exists($"output/{Path.GetFileName(file)}"))
28+
{
29+
File.Copy(file, $"output/{Path.GetFileName(file)}");
30+
}
31+
}
32+
33+
public void RenameFile(string path, string newpath)
34+
{
35+
if (File.Exists(path))
36+
{
37+
File.Move(path, newpath);
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)