-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsharpawareness.cs
386 lines (348 loc) · 13.8 KB
/
sharpawareness.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
using System;
using Microsoft.Win32;
using System.Security.Principal;
using System.Management;
using System.Diagnostics;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Net;
using System.IO;
using System.Windows;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.ComponentModel;
/*
SharpAwareness - A light and more OPSEC friendly way for red teamers to gain quick situational awareness of both the host and the user.
https://github.com/CodeXTF2/SharpAwareness
*/
namespace sad{
internal class Win32
{
public const int ErrorSuccess = 0;
[DllImport("Netapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern int NetGetJoinInformation(string server, out IntPtr domain, out NetJoinStatus status);
[DllImport("Netapi32.dll")]
public static extern int NetApiBufferFree(IntPtr Buffer);
public enum NetJoinStatus
{
NetSetupUnknownStatus = 0,
NetSetupUnjoined,
NetSetupWorkgroupName,
NetSetupDomainName
}
}
class Program{
public static bool IsInDomain()
{
Win32.NetJoinStatus status = Win32.NetJoinStatus.NetSetupUnknownStatus;
IntPtr pDomain = IntPtr.Zero;
int result = Win32.NetGetJoinInformation(null, out pDomain, out status);
if (pDomain != IntPtr.Zero)
{
Win32.NetApiBufferFree(pDomain);
}
if (result == Win32.ErrorSuccess)
{
return status == Win32.NetJoinStatus.NetSetupDomainName;
}
else
{
throw new Exception("Domain Info Get Failed", new Win32Exception());
}
}
public static string[] edrlist =
{
"activeconsole",
"amsi.dll",
"anti malware",
"anti-malware",
"antimalware",
"anti virus",
"anti-virus",
"antivirus",
"appsense",
"authtap",
"avast",
"avecto",
"canary",
"carbonblack",
"carbon black",
"cb.exe",
"ciscoamp",
"cisco amp",
"countercept",
"countertack",
"cramtray",
"crssvc",
"crowdstrike",
"csagent",
"csfalcon",
"csshell",
"cybereason",
"cyclorama",
"cylance",
"cyoptics",
"cyupdate",
"cyvera",
"cyserver",
"cytray",
"darktrace",
"defendpoint",
"defender",
"eectrl",
"elastic",
"endgame",
"f-secure",
"forcepoint",
"fireeye",
"groundling",
"GRRservic",
"inspector",
"ivanti",
"kaspersky",
"lacuna",
"logrhythm",
"malware",
"mandiant",
"mcafee",
"morphisec",
"msascuil",
"msmpeng",
"nissrv",
"omni",
"omniagent",
"osquery",
"Palo Alto Networks",
"pgeposervice",
"pgsystemtray",
"privilegeguard",
"procwall",
"protectorservic",
"qradar",
"redcloak",
"secureworks",
"securityhealthservice",
"semlaunchsv",
"sentinel",
"sepliveupdat",
"sisidsservice",
"sisipsservice",
"sisipsutil",
"smc.exe",
"smcgui",
"snac64",
"sophos",
"splunk",
"srtsp",
"symantec",
"symcorpu",
"symefasi",
"sysinternal",
"sysmon",
"tanium",
"tda.exe",
"tdawork",
"tpython",
"vectra",
"wincollect",
"windowssensor",
"wireshark",
"threat",
"xagt.exe",
"xagtnotif.exe"
};
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
public static void printBanner(){
Console.WriteLine("\nSharpAwareness - by CodeX");
}
public static string GetActiveWindowTitle()
{
const int nChars = 256;
StringBuilder Buff = new StringBuilder(nChars);
IntPtr handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
public static string GetVersionInfo()
{
string HKLMWinNTCurrent = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion";
string osName = Registry.GetValue(HKLMWinNTCurrent, "productName", "").ToString();
string osRelease = Registry.GetValue(HKLMWinNTCurrent, "ReleaseId", "").ToString();
string osVersion = Environment.OSVersion.Version.ToString();
string osType = Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit";
string osBuild = Registry.GetValue(HKLMWinNTCurrent, "CurrentBuildNumber", "").ToString();
string osUBR = Registry.GetValue(HKLMWinNTCurrent, "UBR", "").ToString();
string versionstring = osName + "|" + osRelease + "|" + osVersion + "|" + osType + "|" + osBuild + "|" + osUBR;
return versionstring;
}
public static void Main(string[] args){
string edrstrings = "";
try{
printBanner();
Console.WriteLine("\n[*] Starting host recon");
try{
//Get Windows Version
Console.WriteLine("\n[*] Windows Version:\n" + GetVersionInfo() + "\n");
}catch{
Console.WriteLine("\n[!] Failed to get Windows version");
}
try{
//Get users that have logged in to this box
var localusers = Directory.GetDirectories("C:\\Users");
Console.WriteLine("\n[*] Local user folders:");
for (int i = 0; i < localusers.Length; i++)
{
if(localusers[i] != "C:\\Users\\Public" && localusers[i] != "C:\\Users\\All Users"){
Console.WriteLine(localusers[i]);
}
}
}catch{
Console.WriteLine("\n[!] Failed to enumerate local user folders");
}
try{
//Installed programs
var programfiles = Directory.GetDirectories("C:\\Program Files");
Console.WriteLine("\n[*] Installed programs:");
for (int i = 0; i < programfiles.Length; i++)
{
edrstrings += programfiles[i];
Console.WriteLine(programfiles[i]);
}
var programfiles2 = Directory.GetDirectories("C:\\Program Files (x86)");
for (int i = 0; i < programfiles2.Length; i++)
{
edrstrings += programfiles[i];
Console.WriteLine(programfiles2[i]);
}
}catch{
Console.WriteLine("\n[!] Failed to enumerate installed programs");
}
try{
//Running processes
Console.WriteLine("\n[*] Running processes:");
Process[] processCollection = Process.GetProcesses();
foreach (Process p in processCollection)
{
try{
Console.WriteLine(p.Id + " " + p.ProcessName + " - " + p.MainModule.FileVersionInfo.FileDescription);
edrstrings += p.ProcessName;
edrstrings += p.MainModule.FileVersionInfo.FileDescription;
}catch{
Console.WriteLine(p.Id + " " + p.ProcessName);
edrstrings += p.ProcessName;
}
}
}catch{
Console.WriteLine("\n[!] Failed to enumerate running processes");
}
//Foreground window
try{
Console.WriteLine("\n[*] Open windows - What is our user doing?:");
Process[] processlist = Process.GetProcesses();
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
Console.WriteLine("Process: {0} ID: {1} Window title: {2}", process.ProcessName, process.Id, process.MainWindowTitle);
}
}
Console.WriteLine("\n[*] Foreground window");
Console.WriteLine(GetActiveWindowTitle());
}catch{
Console.WriteLine("\n[!] Failed to list open windows");
}
try{
//Drives
Console.WriteLine("\n[*] Logical drives");
string[] drives = System.IO.Directory.GetLogicalDrives();
foreach (string str in drives)
{
System.Console.WriteLine(str);
}
}catch{
Console.WriteLine("\n[!] Failed to enumerate logical drives");
}
//Proxy settings
try{
Console.WriteLine("\n[!] Enumerating IE proxy settings");
var uri = WebRequest.DefaultWebProxy.GetProxy(new Uri("http://www.google.com"));
if(uri.ToString() != "http://www.google.com/"){
Console.WriteLine("Proxy address: " + uri.ToString());
}else{
Console.WriteLine("No proxy configured");
}
}catch{
Console.WriteLine("\n[!] Failed to enumerate proxy settings");
}
//Take screenshot
try{
Console.WriteLine("\n[*] Taking screenshot");
Bitmap memoryImage;
memoryImage = new Bitmap(1920, 1080);
Size s = new Size(memoryImage.Width, memoryImage.Height);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);
//That's it! Save the image in the directory and this will work like charm.
string fileName = string.Format(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
@"\tmp" + "_" +
DateTime.Now.ToString("hhmmss") + ".tmp");
// save it
memoryImage.Save(fileName);
Console.WriteLine("- Screenshot saved as " + fileName);
}catch{
Console.WriteLine("\n[!] Failed to take screenshot");
}
//Logon times
Console.WriteLine("\n[*] Enumerating logon logoff times");
try{
DirectoryEntry dirs = new DirectoryEntry("WinNT://" + Environment.MachineName);
foreach (DirectoryEntry de in dirs.Children)
{
if (de.SchemaClassName == "User")
{
Console.WriteLine("Name: " + de.Name);
if (de.Properties["lastlogin"].Value != null)
{
Console.WriteLine("Last login: " + de.Properties["lastlogin"].Value.ToString());
}
if (de.Properties["lastlogoff"].Value != null)
{
Console.WriteLine("Last logoff: " + de.Properties["lastlogoff"].Value.ToString());
}
Console.WriteLine();
}
}
}catch{
Console.WriteLine("\n[!] Failed to enumerate last logon times");
}
//EDRs installed?
try{
Console.WriteLine("\n[*] Identifying security products");
foreach(string s in edrlist){
if (edrstrings.ToLower().Contains(s)){
Console.WriteLine("- " + s);
}
}
}catch{
Console.WriteLine("\n[!] Failed to locate EDR strings");
}
Console.WriteLine("\n[*] Checking for Active Directory");
if(IsInDomain()){
Console.WriteLine("Host IS domain joined.");
}else{
Console.WriteLine("Host is NOT domain joined.");
}
//RIP my code broke :(
}catch{
Console.WriteLine("\n[!] SharpAwareness crashed :(");
}
}
}
}