Skip to content

Commit 38ef1a1

Browse files
authored
Merge pull request #6 from LimerBoy/main
Detect any.run
2 parents 185be8e + 03d9df1 commit 38ef1a1

9 files changed

+326
-63
lines changed

AntiCrack-DotNet/AntiCrack-DotNet.csproj

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,10 @@
5454
</PropertyGroup>
5555
<ItemGroup>
5656
<Reference Include="System" />
57-
<Reference Include="System.Core" />
5857
<Reference Include="System.Management" />
59-
<Reference Include="System.Security" />
58+
<Reference Include="Microsoft.CSharp" />
6059
<Reference Include="System.ServiceProcess" />
6160
<Reference Include="System.Windows.Forms" />
62-
<Reference Include="System.Xml.Linq" />
63-
<Reference Include="System.Data.DataSetExtensions" />
64-
<Reference Include="Microsoft.CSharp" />
65-
<Reference Include="System.Data" />
66-
<Reference Include="System.Net.Http" />
67-
<Reference Include="System.Xml" />
6861
</ItemGroup>
6962
<ItemGroup>
7063
<Compile Include="AntiDebug.cs" />

AntiCrack-DotNet/AntiDebug.cs

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Runtime.InteropServices;
6-
using System.Diagnostics;
72
using System.IO;
3+
using System.Text;
84
using System.Threading;
9-
using System.Windows.Forms;
10-
using System.ServiceProcess;
11-
using System.Runtime.CompilerServices;
5+
using System.Diagnostics;
6+
using System.Runtime.InteropServices;
127

138
namespace AntiCrack_DotNet
149
{
15-
class AntiDebug
10+
internal sealed class AntiDebug
1611
{
12+
#region WinApi
13+
1714
[DllImport("kernelbase.dll", SetLastError = true)]
1815
private static extern bool SetHandleInformation(IntPtr hObject, uint dwMask, uint dwFlags);
1916

@@ -92,6 +89,12 @@ class AntiDebug
9289
[DllImport("kernelbase.dll", SetLastError = true)]
9390
private static extern bool VirtualFree(IntPtr lpAddress, uint dwSize, uint dwFreeType);
9491

92+
#endregion
93+
94+
/// <summary>
95+
/// Attempts to close an invalid handle to detect debugger presence.
96+
/// </summary>
97+
/// <returns>Returns true if an exception is caught, indicating no debugger, otherwise false.</returns>
9598
public static bool NtCloseAntiDebug_InvalidHandle()
9699
{
97100
try
@@ -105,6 +108,10 @@ public static bool NtCloseAntiDebug_InvalidHandle()
105108
}
106109
}
107110

111+
/// <summary>
112+
/// Attempts to close a protected handle to detect debugger presence.
113+
/// </summary>
114+
/// <returns>Returns true if an exception is caught, indicating no debugger, otherwise false.</returns>
108115
public static bool NtCloseAntiDebug_ProtectedHandle()
109116
{
110117
IntPtr hMutex = CreateMutexA(IntPtr.Zero, false, new Random().Next(0, 9999999).ToString());
@@ -125,18 +132,30 @@ public static bool NtCloseAntiDebug_ProtectedHandle()
125132
return Result;
126133
}
127134

135+
/// <summary>
136+
/// Checks if a debugger is attached to the process.
137+
/// </summary>
138+
/// <returns>Returns true if a debugger is attached, otherwise false.</returns>
128139
public static bool DebuggerIsAttached()
129140
{
130141
return Debugger.IsAttached;
131142
}
132143

144+
/// <summary>
145+
/// Checks if a debugger is present using the IsDebuggerPresent API.
146+
/// </summary>
147+
/// <returns>Returns true if a debugger is present, otherwise false.</returns>
133148
public static bool IsDebuggerPresentCheck()
134149
{
135150
if (IsDebuggerPresent())
136151
return true;
137152
return false;
138153
}
139154

155+
/// <summary>
156+
/// Checks if the process has debug flags set using NtQueryInformationProcess.
157+
/// </summary>
158+
/// <returns>Returns true if debug flags are set, otherwise false.</returns>
140159
public static bool NtQueryInformationProcessCheck_ProcessDebugFlags()
141160
{
142161
uint ProcessDebugFlags = 0;
@@ -146,6 +165,10 @@ public static bool NtQueryInformationProcessCheck_ProcessDebugFlags()
146165
return false;
147166
}
148167

168+
/// <summary>
169+
/// Checks if the process has a debug port using NtQueryInformationProcess.
170+
/// </summary>
171+
/// <returns>Returns true if a debug port is detected, otherwise false.</returns>
149172
public static bool NtQueryInformationProcessCheck_ProcessDebugPort()
150173
{
151174
uint DebuggerPresent = 0;
@@ -158,6 +181,10 @@ public static bool NtQueryInformationProcessCheck_ProcessDebugPort()
158181
return false;
159182
}
160183

184+
/// <summary>
185+
/// Checks if the process has a debug object handle using NtQueryInformationProcess.
186+
/// </summary>
187+
/// <returns>Returns true if a debug object handle is detected, otherwise false.</returns>
161188
public static bool NtQueryInformationProcessCheck_ProcessDebugObjectHandle()
162189
{
163190
IntPtr hDebugObject = IntPtr.Zero;
@@ -170,6 +197,10 @@ public static bool NtQueryInformationProcessCheck_ProcessDebugObjectHandle()
170197
return false;
171198
}
172199

200+
/// <summary>
201+
/// Patches the DbgUiRemoteBreakin and DbgBreakPoint functions to prevent debugger attachment.
202+
/// </summary>
203+
/// <returns>Returns "Success" if the patching was successful, otherwise "Failed".</returns>
173204
public static string AntiDebugAttach()
174205
{
175206
IntPtr NtdllModule = GetModuleHandle("ntdll.dll");
@@ -184,6 +215,10 @@ public static string AntiDebugAttach()
184215
return "Failed";
185216
}
186217

218+
/// <summary>
219+
/// Checks for the presence of known debugger windows.
220+
/// </summary>
221+
/// <returns>Returns true if a known debugger window is detected, otherwise false.</returns>
187222
public static bool FindWindowAntiDebug()
188223
{
189224
Process[] GetProcesses = Process.GetProcesses();
@@ -202,6 +237,10 @@ public static bool FindWindowAntiDebug()
202237
return false;
203238
}
204239

240+
/// <summary>
241+
/// Checks if the foreground window belongs to a known debugger.
242+
/// </summary>
243+
/// <returns>Returns true if a known debugger window is detected, otherwise false.</returns>
205244
public static bool GetForegroundWindowAntiDebug()
206245
{
207246
string[] BadWindowNames = { "x32dbg", "x64dbg", "windbg", "ollydbg", "dnspy", "immunity debugger", "hyperdbg", "debug", "debugger", "cheat engine", "cheatengine", "ida" };
@@ -225,6 +264,10 @@ public static bool GetForegroundWindowAntiDebug()
225264
return false;
226265
}
227266

267+
/// <summary>
268+
/// Hides threads from the debugger by setting the NtSetInformationThread.
269+
/// </summary>
270+
/// <returns>Returns "Success" if the threads were hidden successfully, otherwise "Failed".</returns>
228271
public static string HideThreadsAntiDebug()
229272
{
230273
try
@@ -252,12 +295,21 @@ public static string HideThreadsAntiDebug()
252295
}
253296
}
254297

298+
/// <summary>
299+
/// Uses GetTickCount to detect debugger presence.
300+
/// </summary>
301+
/// <returns>Returns true if debugger presence is detected, otherwise false.</returns>
255302
public static bool GetTickCountAntiDebug()
256303
{
257304
uint Start = GetTickCount();
258305
Thread.Sleep(0x10);
259306
return (GetTickCount() - Start) > 0x10;
260307
}
308+
309+
/// <summary>
310+
/// Uses OutputDebugString to detect debugger presence.
311+
/// </summary>
312+
/// <returns>Returns true if debugger presence is detected, otherwise false.</returns>
261313
public static bool OutputDebugStringAntiDebug()
262314
{
263315
Debugger.Log(0, null, "just testing some stuff...");
@@ -266,11 +318,18 @@ public static bool OutputDebugStringAntiDebug()
266318
return false;
267319
}
268320

321+
/// <summary>
322+
/// Exploits a format string vulnerability in OllyDbg.
323+
/// </summary>
269324
public static void OllyDbgFormatStringExploit()
270325
{
271326
Debugger.Log(0, null, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s");
272327
}
273328

329+
/// <summary>
330+
/// Triggers a debug break to detect debugger presence.
331+
/// </summary>
332+
/// <returns>Returns true if an exception is caught, indicating no debugger, otherwise false.</returns>
274333
public static bool DebugBreakAntiDebug()
275334
{
276335
try
@@ -286,6 +345,10 @@ public static bool DebugBreakAntiDebug()
286345

287346
private static long CONTEXT_DEBUG_REGISTERS = 0x00010000L | 0x00000010L;
288347

348+
/// <summary>
349+
/// Detects hardware breakpoints by checking debug registers.
350+
/// </summary>
351+
/// <returns>Returns true if hardware breakpoints are detected, otherwise false.</returns>
289352
public static bool HardwareRegistersBreakpointsDetection()
290353
{
291354
Structs.CONTEXT Context = new Structs.CONTEXT();
@@ -302,6 +365,12 @@ public static bool HardwareRegistersBreakpointsDetection()
302365
NtClose(CurrentThread);
303366
return false;
304367
}
368+
369+
/// <summary>
370+
/// Cleans the specified path by removing null characters.
371+
/// </summary>
372+
/// <param name="Path">The path to clean.</param>
373+
/// <returns>The cleaned path.</returns>
305374
private static string CleanPath(string Path)
306375
{
307376
string CleanedPath = null;
@@ -315,6 +384,10 @@ private static string CleanPath(string Path)
315384
return CleanedPath;
316385
}
317386

387+
/// <summary>
388+
/// Checks if the parent process is a debugger by querying process information.
389+
/// </summary>
390+
/// <returns>Returns true if the parent process is a debugger, otherwise false.</returns>
318391
public static bool ParentProcessAntiDebug()
319392
{
320393
try
@@ -348,6 +421,10 @@ public static bool ParentProcessAntiDebug()
348421
return false;
349422
}
350423

424+
/// <summary>
425+
/// Uses NtSetDebugFilterState to prevent debugging.
426+
/// </summary>
427+
/// <returns>Returns true if the filter state was set successfully, otherwise false.</returns>
351428
public static bool NtSetDebugFilterStateAntiDebug()
352429
{
353430
if (NtSetDebugFilterState(0, 0, true) != 0)
@@ -356,6 +433,11 @@ public static bool NtSetDebugFilterStateAntiDebug()
356433
}
357434

358435
delegate int ExecutionDelegate();
436+
437+
/// <summary>
438+
/// Uses page guard to detect debugger presence by executing a function pointer.
439+
/// </summary>
440+
/// <returns>Returns true if debugger presence is detected, otherwise false.</returns>
359441
public static bool PageGuardAntiDebug()
360442
{
361443
Structs.SYSTEM_INFO SysInfo = new Structs.SYSTEM_INFO();
@@ -389,4 +471,5 @@ public static bool PageGuardAntiDebug()
389471
return false;
390472
}
391473
}
392-
}
474+
475+
}

AntiCrack-DotNet/AntiDllInjection.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Runtime.InteropServices;
62
using System.Diagnostics;
7-
using System.IO;
8-
using System.Windows.Forms;
9-
using static AntiCrack_DotNet.Structs;
3+
using System.Runtime.InteropServices;
104

115
namespace AntiCrack_DotNet
126
{
13-
class AntiDllInjection
7+
internal sealed class AntiDllInjection
148
{
9+
10+
#region WinApi
11+
1512
[DllImport("kernelbase.dll", SetLastError = true)]
1613
private static extern IntPtr GetModuleHandle(string lib);
1714

@@ -24,6 +21,13 @@ class AntiDllInjection
2421
[DllImport("kernelbase.dll", SetLastError = true)]
2522
public static extern bool SetProcessMitigationPolicy(int policy, ref Structs.PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY lpBuffer, int size);
2623

24+
#endregion
25+
26+
27+
/// <summary>
28+
/// Patches the LoadLibraryA function to prevent DLL injection.
29+
/// </summary>
30+
/// <returns>Returns "Success" if the patching was successful, otherwise "Failed".</returns>
2731
public static string PatchLoadLibraryA()
2832
{
2933
IntPtr KernelModule = GetModuleHandle("kernelbase.dll");
@@ -35,6 +39,10 @@ public static string PatchLoadLibraryA()
3539
return "Failed";
3640
}
3741

42+
/// <summary>
43+
/// Patches the LoadLibraryW function to prevent DLL injection.
44+
/// </summary>
45+
/// <returns>Returns "Success" if the patching was successful, otherwise "Failed".</returns>
3846
public static string PatchLoadLibraryW()
3947
{
4048
IntPtr KernelModule = GetModuleHandle("kernelbase.dll");
@@ -46,6 +54,10 @@ public static string PatchLoadLibraryW()
4654
return "Failed";
4755
}
4856

57+
/// <summary>
58+
/// Enables the binary image signature mitigation policy to only allow Microsoft-signed binaries.
59+
/// </summary>
60+
/// <returns>Returns "Success" if the policy was set successfully, otherwise "Failed".</returns>
4961
public static string BinaryImageSignatureMitigationAntiDllInjection()
5062
{
5163
Structs.PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY OnlyMicrosoftBinaries = new Structs.PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY();
@@ -55,6 +67,10 @@ public static string BinaryImageSignatureMitigationAntiDllInjection()
5567
return "Failed";
5668
}
5769

70+
/// <summary>
71+
/// Checks if there are any injected libraries in the current process.
72+
/// </summary>
73+
/// <returns>Returns true if an injected library is detected, otherwise false.</returns>
5874
public static bool IsInjectedLibrary()
5975
{
6076
bool IsMalicious = false;
@@ -71,6 +87,11 @@ public static bool IsInjectedLibrary()
7187
}
7288
return IsMalicious;
7389
}
90+
91+
/// <summary>
92+
/// Sets the DLL load policy to only allow Microsoft-signed DLLs to be loaded.
93+
/// </summary>
94+
/// <returns>Returns "Success" if the policy was set successfully, otherwise "Failed".</returns>
7495
public static string SetDllLoadPolicy()
7596
{
7697
Structs.PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY policy = new Structs.PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY

0 commit comments

Comments
 (0)