Skip to content

Commit 8978e84

Browse files
authored
Add files via upload
1 parent 4a3b93a commit 8978e84

12 files changed

+950
-244
lines changed

AntiCrack-DotNet/AntiCrack-DotNet.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<BootstrapperEnabled>true</BootstrapperEnabled>
3131
</PropertyGroup>
3232
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
33-
<PlatformTarget>x64</PlatformTarget>
33+
<PlatformTarget>x86</PlatformTarget>
3434
<DebugSymbols>true</DebugSymbols>
3535
<DebugType>full</DebugType>
3636
<Optimize>false</Optimize>
@@ -52,6 +52,14 @@
5252
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5353
<Prefer32Bit>false</Prefer32Bit>
5454
</PropertyGroup>
55+
<PropertyGroup>
56+
<TargetZone>LocalIntranet</TargetZone>
57+
</PropertyGroup>
58+
<PropertyGroup>
59+
<GenerateManifests>false</GenerateManifests>
60+
</PropertyGroup>
61+
<PropertyGroup />
62+
<PropertyGroup />
5563
<ItemGroup>
5664
<Reference Include="System" />
5765
<Reference Include="System.Management" />
@@ -68,6 +76,8 @@
6876
<Compile Include="Program.cs" />
6977
<Compile Include="Properties\AssemblyInfo.cs" />
7078
<Compile Include="Structs.cs" />
79+
<Compile Include="Syscalls.cs" />
80+
<Compile Include="Utils.cs" />
7181
</ItemGroup>
7282
<ItemGroup>
7383
<None Include="App.config" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
4+
<EnableUnmanagedDebugging>true</EnableUnmanagedDebugging>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<PublishUrlHistory>publish\</PublishUrlHistory>
8+
<InstallUrlHistory />
9+
<SupportUrlHistory />
10+
<UpdateUrlHistory />
11+
<BootstrapperUrlHistory />
12+
<ErrorReportUrlHistory />
13+
<FallbackCulture>en-US</FallbackCulture>
14+
<VerifyUploadedFiles>false</VerifyUploadedFiles>
15+
</PropertyGroup>
16+
</Project>

AntiCrack-DotNet/AntiDebug.cs

Lines changed: 84 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
using System.Threading;
55
using System.Diagnostics;
66
using System.Runtime.InteropServices;
7+
using System.Windows.Forms;
8+
using System.Net;
9+
using System.Security.Cryptography;
710

811
namespace AntiCrack_DotNet
912
{
@@ -62,8 +65,8 @@ internal sealed class AntiDebug
6265
[DllImport("kernelbase.dll", SetLastError = true)]
6366
private static extern int QueryFullProcessImageNameA(SafeHandle hProcess, uint Flags, byte[] lpExeName, Int32[] lpdwSize);
6467

65-
[DllImport("user32.dll", SetLastError = true)]
66-
private static extern IntPtr GetForegroundWindow();
68+
[DllImport("win32u.dll", SetLastError = true)]
69+
private static extern IntPtr NtUserGetForegroundWindow();
6770

6871
[DllImport("user32.dll", SetLastError = true)]
6972
private static extern int GetWindowTextLengthA(IntPtr HWND);
@@ -93,13 +96,19 @@ internal sealed class AntiDebug
9396

9497
/// <summary>
9598
/// Attempts to close an invalid handle to detect debugger presence.
99+
/// <param name="Syscall">specifies if we should use syscall to call the WinAPI functions.</param>
96100
/// </summary>
97101
/// <returns>Returns true if an exception is caught, indicating no debugger, otherwise false.</returns>
98-
public static bool NtCloseAntiDebug_InvalidHandle()
102+
public static bool NtCloseAntiDebug_InvalidHandle(bool Syscall)
99103
{
100104
try
101105
{
102-
NtClose((IntPtr)0x1231222L);
106+
int RandomInt = new Random().Next(int.MinValue, int.MaxValue);
107+
IntPtr RandomIntPtr = new IntPtr(RandomInt);
108+
if (Syscall)
109+
Syscalls.SyscallNtClose(RandomIntPtr);
110+
else
111+
NtClose(RandomIntPtr);
103112
return false;
104113
}
105114
catch
@@ -110,17 +119,22 @@ public static bool NtCloseAntiDebug_InvalidHandle()
110119

111120
/// <summary>
112121
/// Attempts to close a protected handle to detect debugger presence.
122+
/// <param name="Syscall">specifies if we should use syscall to call the WinAPI functions.</param>
113123
/// </summary>
114124
/// <returns>Returns true if an exception is caught, indicating no debugger, otherwise false.</returns>
115-
public static bool NtCloseAntiDebug_ProtectedHandle()
125+
public static bool NtCloseAntiDebug_ProtectedHandle(bool Syscall)
116126
{
117-
IntPtr hMutex = CreateMutexA(IntPtr.Zero, false, new Random().Next(0, 9999999).ToString());
127+
string RandomMutexName = new Random().Next(int.MinValue, int.MaxValue).ToString();
128+
IntPtr hMutex = CreateMutexA(IntPtr.Zero, false, RandomMutexName);
118129
uint HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002;
119130
SetHandleInformation(hMutex, HANDLE_FLAG_PROTECT_FROM_CLOSE, HANDLE_FLAG_PROTECT_FROM_CLOSE);
120131
bool Result = false;
121132
try
122133
{
123-
NtClose(hMutex);
134+
if (Syscall)
135+
Syscalls.SyscallNtClose(hMutex);
136+
else
137+
NtClose(hMutex);
124138
Result = false;
125139
}
126140
catch
@@ -153,45 +167,62 @@ public static bool IsDebuggerPresentCheck()
153167
}
154168

155169
/// <summary>
156-
/// Checks if the process has debug flags set using NtQueryInformationProcess.
170+
/// Checks if the process has debug flags set using NtQueryInformationProcess
171+
/// <param name="Syscall">specifies if we should use syscall to call the WinAPI functions.</param>
157172
/// </summary>
158173
/// <returns>Returns true if debug flags are set, otherwise false.</returns>
159-
public static bool NtQueryInformationProcessCheck_ProcessDebugFlags()
174+
public static bool NtQueryInformationProcessCheck_ProcessDebugFlags(bool Syscall)
160175
{
161176
uint ProcessDebugFlags = 0;
162-
NtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, 0x1F, out ProcessDebugFlags, sizeof(uint), 0);
177+
uint Class = 0x1F;
178+
uint Size = sizeof(uint);
179+
uint Result = 0;
180+
if (Syscall)
181+
Syscalls.SyscallNtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, Class, out ProcessDebugFlags, Size, out Result);
182+
else
183+
NtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, 0x1F, out ProcessDebugFlags, sizeof(uint), 0);
163184
if (ProcessDebugFlags == 0)
164185
return true;
165186
return false;
166187
}
167188

168189
/// <summary>
169190
/// Checks if the process has a debug port using NtQueryInformationProcess.
191+
/// <param name="Syscall">specifies if we should use syscalls to call the WinAPI functions.</param>.
170192
/// </summary>
171193
/// <returns>Returns true if a debug port is detected, otherwise false.</returns>
172-
public static bool NtQueryInformationProcessCheck_ProcessDebugPort()
194+
public static bool NtQueryInformationProcessCheck_ProcessDebugPort(bool Syscall)
173195
{
174196
uint DebuggerPresent = 0;
175197
uint Size = sizeof(uint);
176198
if (Environment.Is64BitProcess)
177199
Size = sizeof(uint) * 2;
178-
NtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, 7, out DebuggerPresent, Size, 0);
200+
uint Result = 0;
201+
if(Syscall)
202+
Syscalls.SyscallNtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, 7, out DebuggerPresent, Size, out Result);
203+
else
204+
NtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, 7, out DebuggerPresent, Size, 0);
179205
if (DebuggerPresent != 0)
180206
return true;
181207
return false;
182208
}
183209

184210
/// <summary>
185211
/// Checks if the process has a debug object handle using NtQueryInformationProcess.
212+
/// <param name="Syscall">specifies if we should use syscall to call the WinAPI functions.</param>
186213
/// </summary>
187214
/// <returns>Returns true if a debug object handle is detected, otherwise false.</returns>
188-
public static bool NtQueryInformationProcessCheck_ProcessDebugObjectHandle()
215+
public static bool NtQueryInformationProcessCheck_ProcessDebugObjectHandle(bool Syscall)
189216
{
190217
IntPtr hDebugObject = IntPtr.Zero;
191218
uint Size = sizeof(uint);
192219
if (Environment.Is64BitProcess)
193220
Size = sizeof(uint) * 2;
194-
NtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, 0x1E, out hDebugObject, Size, 0);
221+
222+
if (Syscall)
223+
Syscalls.SyscallNtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, 0x1E, out hDebugObject, Size, 0);
224+
else
225+
NtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, 0x1E, out hDebugObject, Size, 0);
195226
if (hDebugObject != IntPtr.Zero)
196227
return true;
197228
return false;
@@ -221,18 +252,31 @@ public static string AntiDebugAttach()
221252
/// <returns>Returns true if a known debugger window is detected, otherwise false.</returns>
222253
public static bool FindWindowAntiDebug()
223254
{
255+
string[] BadWindowNames = { "x32dbg", "x64dbg", "windbg", "ollydbg", "dnspy", "immunity debugger", "hyperdbg", "cheat engine", "cheatengine", "ida" };
224256
Process[] GetProcesses = Process.GetProcesses();
225257
foreach (Process GetWindow in GetProcesses)
226258
{
227-
string[] BadWindowNames = { "x32dbg", "x64dbg", "windbg", "ollydbg", "dnspy", "immunity debugger", "hyperdbg", "cheat engine", "cheatengine", "ida" };
228-
foreach (string BadWindows in BadWindowNames)
259+
try
229260
{
230-
if (GetWindow.MainWindowTitle.ToLower().Contains(BadWindows))
261+
if (GetWindow.MainWindowHandle != IntPtr.Zero)
231262
{
232-
GetWindow.Close();
233-
return true;
263+
string title = GetWindow.MainWindowTitle;
264+
if (string.IsNullOrEmpty(title)) continue;
265+
266+
foreach (string BadWindows in BadWindowNames)
267+
{
268+
if (title.IndexOf(BadWindows, StringComparison.OrdinalIgnoreCase) >= 0)
269+
{
270+
GetWindow.Close();
271+
return true;
272+
}
273+
}
234274
}
235275
}
276+
catch
277+
{
278+
continue;
279+
}
236280
}
237281
return false;
238282
}
@@ -241,10 +285,10 @@ public static bool FindWindowAntiDebug()
241285
/// Checks if the foreground window belongs to a known debugger.
242286
/// </summary>
243287
/// <returns>Returns true if a known debugger window is detected, otherwise false.</returns>
244-
public static bool GetForegroundWindowAntiDebug()
288+
public static bool NtUserGetForegroundWindowAntiDebug()
245289
{
246290
string[] BadWindowNames = { "x32dbg", "x64dbg", "windbg", "ollydbg", "dnspy", "immunity debugger", "hyperdbg", "debug", "debugger", "cheat engine", "cheatengine", "ida" };
247-
IntPtr HWND = GetForegroundWindow();
291+
IntPtr HWND = NtUserGetForegroundWindow();
248292
if (HWND != IntPtr.Zero)
249293
{
250294
int WindowLength = GetWindowTextLengthA(HWND);
@@ -254,7 +298,7 @@ public static bool GetForegroundWindowAntiDebug()
254298
GetWindowTextA(HWND, WindowName, WindowLength + 1);
255299
foreach (string BadWindows in BadWindowNames)
256300
{
257-
if (WindowName.ToString().ToLower().Contains(BadWindows))
301+
if (Utils.Contains(WindowName.ToString().ToLower(), BadWindows))
258302
{
259303
return true;
260304
}
@@ -353,16 +397,21 @@ public static bool HardwareRegistersBreakpointsDetection()
353397
{
354398
Structs.CONTEXT Context = new Structs.CONTEXT();
355399
Context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
356-
IntPtr CurrentThread = GetCurrentThread();
357-
if (GetThreadContext(CurrentThread, ref Context))
400+
foreach (ProcessThread Threads in Process.GetCurrentProcess().Threads)
358401
{
359-
if ((Context.Dr1 != 0x00 || Context.Dr2 != 0x00 || Context.Dr3 != 0x00 || Context.Dr4 != 0x00 || Context.Dr5 != 0x00 || Context.Dr6 != 0x00 || Context.Dr7 != 0x00))
402+
uint THREAD_GET_CONTEXT = 0x0008;
403+
uint THREAD_QUERY_INFORMATION = 0x0040;
404+
IntPtr hThread = OpenThread(THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, false, Threads.Id);
405+
if (GetThreadContext(hThread, ref Context))
360406
{
361-
NtClose(CurrentThread);
362-
return true;
407+
if ((Context.Dr1 != 0x00 || Context.Dr2 != 0x00 || Context.Dr3 != 0x00 || Context.Dr6 != 0x00 || Context.Dr7 != 0x00))
408+
{
409+
NtClose(hThread);
410+
return true;
411+
}
363412
}
413+
NtClose(hThread);
364414
}
365-
NtClose(CurrentThread);
366415
return false;
367416
}
368417

@@ -386,15 +435,17 @@ private static string CleanPath(string Path)
386435

387436
/// <summary>
388437
/// Checks if the parent process is a debugger by querying process information.
438+
/// <param name="Syscall">specifies if we should use syscall to call the WinAPI functions.</param>
389439
/// </summary>
390440
/// <returns>Returns true if the parent process is a debugger, otherwise false.</returns>
391-
public static bool ParentProcessAntiDebug()
441+
public static bool ParentProcessAntiDebug(bool Syscall)
392442
{
393443
try
394444
{
395445
Structs.PROCESS_BASIC_INFORMATION PBI = new Structs.PROCESS_BASIC_INFORMATION();
396446
uint ProcessBasicInformation = 0;
397-
if (NtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, ProcessBasicInformation, ref PBI, (uint)Marshal.SizeOf(typeof(Structs.PROCESS_BASIC_INFORMATION)), 0) == 0)
447+
uint Result = Syscall ? Syscalls.SyscallNtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, ProcessBasicInformation, ref PBI, (uint)Marshal.SizeOf(typeof(Structs.PROCESS_BASIC_INFORMATION)), 0) : NtQueryInformationProcess(Process.GetCurrentProcess().SafeHandle, ProcessBasicInformation, ref PBI, (uint)Marshal.SizeOf(typeof(Structs.PROCESS_BASIC_INFORMATION)), 0);
448+
if (Result == 0)
398449
{
399450
int ParentPID = PBI.InheritedFromUniqueProcessId.ToInt32();
400451
if (ParentPID != 0)
@@ -432,7 +483,8 @@ public static bool NtSetDebugFilterStateAntiDebug()
432483
return true;
433484
}
434485

435-
delegate int ExecutionDelegate();
486+
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
487+
private delegate int ExecutionDelegate();
436488

437489
/// <summary>
438490
/// Uses page guard to detect debugger presence by executing a function pointer.
@@ -471,5 +523,4 @@ public static bool PageGuardAntiDebug()
471523
return false;
472524
}
473525
}
474-
475-
}
526+
}

AntiCrack-DotNet/AntiDllInjection.cs

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,6 @@ internal sealed class AntiDllInjection
2323

2424
#endregion
2525

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>
31-
public static string PatchLoadLibraryA()
32-
{
33-
IntPtr KernelModule = GetModuleHandle("kernelbase.dll");
34-
IntPtr LoadLibraryA = GetProcAddress(KernelModule, "LoadLibraryA");
35-
byte[] HookedCode = { 0xC2, 0x04, 0x00 };
36-
bool Status = WriteProcessMemory(Process.GetCurrentProcess().SafeHandle, LoadLibraryA, HookedCode, 3, 0);
37-
if (Status)
38-
return "Success";
39-
return "Failed";
40-
}
41-
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>
46-
public static string PatchLoadLibraryW()
47-
{
48-
IntPtr KernelModule = GetModuleHandle("kernelbase.dll");
49-
IntPtr LoadLibraryW = GetProcAddress(KernelModule, "LoadLibraryW");
50-
byte[] HookedCode = { 0xC2, 0x04, 0x00 };
51-
bool Status = WriteProcessMemory(Process.GetCurrentProcess().SafeHandle, LoadLibraryW, HookedCode, 3, 0);
52-
if (Status)
53-
return "Success";
54-
return "Failed";
55-
}
56-
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>
61-
public static string BinaryImageSignatureMitigationAntiDllInjection()
62-
{
63-
Structs.PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY OnlyMicrosoftBinaries = new Structs.PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY();
64-
OnlyMicrosoftBinaries.MicrosoftSignedOnly = 1;
65-
if (SetProcessMitigationPolicy(8, ref OnlyMicrosoftBinaries, Marshal.SizeOf(typeof(Structs.PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY))))
66-
return "Success";
67-
return "Failed";
68-
}
69-
7026
/// <summary>
7127
/// Checks if there are any injected libraries in the current process.
7228
/// </summary>
@@ -98,7 +54,7 @@ public static string SetDllLoadPolicy()
9854
{
9955
MicrosoftSignedOnly = 1
10056
};
101-
if (SetProcessMitigationPolicy(0x10, ref policy, Marshal.SizeOf(policy)))
57+
if (SetProcessMitigationPolicy(8, ref policy, Marshal.SizeOf(policy)))
10258
return "Success";
10359
return "Failed";
10460
}

0 commit comments

Comments
 (0)