-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
156 lines (153 loc) · 7.82 KB
/
Main.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
/*
│ Emre Ekinci
│ yunusemrem@windowslive.com
│
│ TODO:
> Listeyi değişiklik olunca yenile
> listenin sadece değişikliklerini yenile
> API lere kalan zaman değeri ver
> response result ları bir class ta tut
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Outlook;
using OutlookApp = Microsoft.Office.Interop.Outlook.Application;
using Console = Colorful.Console;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Naga.Properties;
namespace Naga {
public class MainClass {
static public Api vtApi;
static public Config speconfig;
static string banner = Resources.banner;
static string hashFile = "hashes.txt";
static public List<string> md5List = new List<string>();
static string header = "[No ] " + "Hash".PadRight(37) + "Rate".PadRight(12) + "McGW Detected?".PadRight(18) + "McAffee Detected?".PadRight(16);
static void Main(string[] args) {
Console.OutputEncoding = Encoding.UTF8;
Console.WriteFormatted(banner, Color.LightGoldenrodYellow);
try { speconfig = JsonConvert.DeserializeObject<Config>(Resources.speconfig); }
catch (System.Exception ee) {
Console.WriteFormatted("\n Config file problem:\n\t" + ee.Message, Color.Red);
Console.ReadLine();
return;
}
vtApi = new Api();
vtApi.myProxySetting = Helpers.initializeProxyConfigs();
Task liveBoard = null;
try {
md5List = new List<string>(File.ReadAllLines(hashFile));
md5List = md5List.Select(s => String.Join("", s.Split(',', '\n', '\t'))).Distinct().ToList(); // clean dirty md5 list
liveBoard = new Task( () => LiveBoardAsync()); // run the liveboard to see results alive
liveBoard.Start();
//vtApi.checkHashes(md5List);
vtApi.checkHashesNEWAsync(md5List);
liveBoard.Wait();
vtApi.results = vtApi.results.OrderBy(ss => ss.resultMc).ToList();
}
catch (System.Exception e) {
Console.WriteLineFormatted("\n | Exception: " + e.Message, Color.Red);
}
LiveBoardAsync();//run again to show last results
//WriteToFile();
//WriteCsirtMail();
//WriteAtarMail();
Console.SetCursorPosition(0, banner.Split('\n').Count() + vtApi.results.Count + 4);
Console.WriteFormatted("\n__________________________________________ ALL DONE ".PadRight(100,'_'), Color.LightGoldenrodYellow);
Console.WriteFormatted("\n_".PadRight(100,'_'), Color.LightGoldenrodYellow);
Console.ReadLine();
Environment.Exit(0);
}
static void LiveBoardAsync() {
Console.Clear();
Console.SetCursorPosition(0, 0);
Console.WriteFormatted(banner, Color.LightGoldenrodYellow);
int dashBoardLen = banner.Split('\n').Count();
int finished = 0;
int cDots = 0;
do {
List<Result> tempResults = vtApi.results;
finished = vtApi.nFinished;
string waiting = "0";
try {
if (vtApi.timer.IsRunning)
waiting = ((vtApi.sessionTime - vtApi.timer.ElapsedMilliseconds / 1000)% vtApi.sessionTime).ToString();
Console.SetCursorPosition(0, dashBoardLen + 1);
Console.WriteFormatted("\tRequests Sent [{0}/{1}] DONE " + "".PadRight(cDots%5+1,'.').PadRight(6) + " new Requests in {2} seconds \n\n",
Color.Cyan, Color.LightGoldenrodYellow, finished, md5List.Count,waiting);
Console.WriteFormatted("\t " + header, Color.LightGoldenrodYellow);
ResultsToDash(tempResults);
}// end of try
catch (System.Exception e) {
Console.Write("\n\n X│ " + e.Message);
}
Console.SetCursorPosition(0, dashBoardLen + 1);
Thread.Sleep(1000);
cDots++;
} while (finished != md5List.Count);
}
static public void ResultsToDash(List<Result> tempResults)
{
int counter = 0;
Color backColor;
foreach (var oneResult in tempResults)
{
backColor = Color.Green;
if (oneResult.isCompleted == false || oneResult.resultMc == "NotParsed")
backColor = Color.Red;
Console.WriteFormatted("\n\t│ [{0}] " + oneResult.DashPrint(), Color.Cyan, backColor, (counter + 1).ToString().PadRight(3));
counter++;
}// end of for
}
static void WriteCsirtMail() {
string attachFile = Directory.GetCurrentDirectory() + "\\results.txt";
var resultStr = header + "<br/>" + String.Join("",vtApi.results.Select(ss => ss.ToString() + " <br/>"));
//File.ReadAllText(attachFile).Replace("\r\n", "<p></p>").Replace("\t", "	");
OutlookApp outlookApp = new OutlookApp();
MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem);
mailItem.Importance = OlImportance.olImportanceHigh;
mailItem.Subject = "Hash Engellenmesi Hk.";
// "pre" tag is standing for render as it is dont change anything, thats why we cannot tab on there
mailItem.HTMLBody =
"<pre " + "style=\"font-family:'consolas'\" >" +
@"Merhaba,<br/>
Aşağıdaki -McAffee Detected?- değeri False ve NotInDB olan <strong>MD5 HASH'lerin engellenmesi</strong> ATAR sistemi üzerinden yapılmıştır.<br/>
Syg.<br/>
" + resultStr + "</pre>";
mailItem.To = speconfig.csirtMail;
mailItem.CC = speconfig.ksdestekMail;
if (!File.Exists(attachFile))
Console.Write("\nAttached document " + attachFile + " does not exist", Color.Red);
else {
System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(attachFile);
mailItem.Attachments.Add(attachFile, OlAttachmentType.olByValue, Type.Missing, Type.Missing);
}
mailItem.Display();
}
static void WriteAtarMail() {
string attachFile = Directory.GetCurrentDirectory() + "\\results.txt";
string mailBody = String.Join("", vtApi.results.Where(ss =>
(ss.resultMc == "False" || ss.resultMc == "NotInDB") &&
Regex.IsMatch(ss.md5, "^[0-9a-fA-F]{32}$", RegexOptions.Compiled)).Select(news => news.md5 + "<br/>"));
OutlookApp outlookApp = new OutlookApp();
MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem);
mailItem.To = speconfig.atarMail;
mailItem.CC = speconfig.csirtMail;
mailItem.Subject = speconfig.atarTitle + Naga.Helpers.userName + "_" + DateTime.Now.ToString("ddMMMMyyyy");
mailItem.HTMLBody = "<p style=\"font-family:'consolas'\" >" + mailBody + "</p>";
mailItem.Importance = OlImportance.olImportanceHigh;
mailItem.Display();
}
static void WriteToFile() {
File.WriteAllText("results.txt", header + Environment.NewLine);
File.AppendAllLines("results.txt", vtApi.results.Select(ss => ss.ToString()).ToArray());
}
}
}// end of namespace