-
Notifications
You must be signed in to change notification settings - Fork 13
/
ETWNetMon3Log.cs
529 lines (452 loc) · 30.3 KB
/
ETWNetMon3Log.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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ETWNetMon3Log
{
}
class Program
{
public static class XMLDataTableClass
{
public static DataTable TCPIPTable2 = new DataTable("ETW_Tcpip_log2");
public static DataColumn TCPIPcolumn2;
public static DataRow TCPIProw2;
public static void TCPIP_settable2()
{
try
{
TCPIPTable2.Columns.Clear();
TCPIPTable2.Rows.Clear();
TCPIPcolumn2 = new DataColumn();
TCPIPcolumn2.DataType = System.Type.GetType("System.DateTime");
TCPIPcolumn2.ColumnName = "TIME";
TCPIPTable2.Columns.Add(TCPIPcolumn2);
// Create second column.
TCPIPcolumn2 = new DataColumn();
TCPIPcolumn2.DataType = Type.GetType("System.String");
TCPIPcolumn2.ColumnName = "events";
TCPIPTable2.Columns.Add(TCPIPcolumn2);
TCPIPcolumn2 = new DataColumn();
TCPIPcolumn2.DataType = System.Type.GetType("System.Int32");
TCPIPcolumn2.ColumnName = "PID";
TCPIPTable2.Columns.Add(TCPIPcolumn2);
TCPIPcolumn2 = new DataColumn();
TCPIPcolumn2.DataType = System.Type.GetType("System.String");
TCPIPcolumn2.ColumnName = "PName";
TCPIPTable2.Columns.Add(TCPIPcolumn2);
TCPIPcolumn2 = new DataColumn();
TCPIPcolumn2.DataType = System.Type.GetType("System.String");
TCPIPcolumn2.ColumnName = "lhost";
TCPIPTable2.Columns.Add(TCPIPcolumn2);
TCPIPcolumn2 = new DataColumn();
TCPIPcolumn2.DataType = System.Type.GetType("System.Int32");
TCPIPcolumn2.ColumnName = "lport";
TCPIPTable2.Columns.Add(TCPIPcolumn2);
TCPIPcolumn2 = new DataColumn();
TCPIPcolumn2.DataType = System.Type.GetType("System.String");
TCPIPcolumn2.ColumnName = "rhost";
TCPIPTable2.Columns.Add(TCPIPcolumn2);
TCPIPcolumn2 = new DataColumn();
TCPIPcolumn2.DataType = System.Type.GetType("System.Int32");
TCPIPcolumn2.ColumnName = "rport";
TCPIPTable2.Columns.Add(TCPIPcolumn2);
TCPIPcolumn2 = new DataColumn();
TCPIPcolumn2.DataType = Type.GetType("System.String");
TCPIPcolumn2.ColumnName = "state";
TCPIPTable2.Columns.Add(TCPIPcolumn2);
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine(err.Message);
}
}
public static void GetRowsTODataTable(DateTime Time, string ETW_eventlog_Text, Int32 PID, string pname
, string lhost, Int32 lport, string rhost, Int32 rport, string state)
{
System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;
try
{
TCPIProw2 = TCPIPTable2.NewRow();
TCPIProw2["TIME"] = Time;
TCPIProw2["events"] = ETW_eventlog_Text;
TCPIProw2["PID"] = PID;
TCPIProw2["pname"] = pname;
TCPIProw2["lhost"] = lhost;
TCPIProw2["lport"] = lport;
TCPIProw2["rhost"] = rhost;
TCPIProw2["rport"] = rport;
TCPIProw2["state"] = state;
TCPIPTable2.Rows.Add(TCPIProw2);
}
catch (Exception err)
{
}
}
}
public delegate void MyDelegate_LogFileReader_Method();
public delegate void MyDelegate_showdatagrid();
public static string tmp = "";
public static string ResultText = "";
public static string ResultText2 = "";
public static string Logfile = "EtwNetMonv3logs.txt";
public static int line = 1;
public static bool init = true;
public static string _findstr(string s1, string str)
{
int index1 = str.LastIndexOf(s1);
if (index1 == -1)
{
return " ";
}
else
{
return str.Substring(index1 + s1.Length, str.Length - index1 - s1.Length);
}
}
public static string _findstr(string str)
{
if (str.ToUpper().Contains("ESTABLISHED") || str.ToUpper().Contains("CONNECT COMPLETED")) return "ESTABLISHED";
if (str.ToUpper().Contains("SYNSENT") || str.ToUpper().Contains("REQUESTED TO CONNECT")) return "SYNSENT";
if (str.ToUpper().Contains("CLOSEWAIT")) return "CLOSEWAIT";
return "";
}
public static void logfilewrite(string filename, string text)
{
using (StreamWriter _file = new StreamWriter(filename))
{
_file.WriteLine(text);
};
}
public static void help()
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("ETWNetMonv3Log Tool , Published by Damon Mohammadbagher , May 2021");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("ETWNetMonv3Log cmd tool is simple ETW log Reader & (XML/HTML) Report Maker for ETW logs, which made by ETWNetMonv3Agent");
Console.WriteLine();
Console.WriteLine("syntax 1: switch XML, All ETW records from text [EtwNetMonv3logs.txt] will save to xml file (convert all records to xml)");
Console.WriteLine("example 1: ETWNetMonv3Log.exe xml filename.xml ");
Console.WriteLine("syntax 2: switch HTML , simple Filter for ETW Records and Save report to HTML format with simple table");
Console.WriteLine("syntax 2-1: switch HTML2 , integrating ETWProcessMon Logs with ETW Network Log + simple Filter to HTML format with simple table");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"your query\" ");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"rport >=80 OR events LIKE '*Established*' AND events LIKE '*connect complete*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"events LIKE '*requested to connect*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"state NOT LIKE '*synsent*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"events LIKE '*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"rhost LIKE '192.168*' or lhost LIKE '192.168.1*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"rport <=80 OR lport >=50000\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"pname LIKE '*.exe*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"events LIKE '*C:\\*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"PID = 1452\"");
Console.WriteLine("syntax 2-1: ETWNetMonv3Log.exe html2 [MODE 0=SYNSENT , 1=ESTABLISHED] [Query]");
Console.WriteLine("example 2-1: ETWNetMonv3Log.exe html2 1 \"PID = 1452\"");
Console.WriteLine("example 2-1: ETWNetMonv3Log.exe html2 0 \"PID = 1452\"");
Console.WriteLine("example 2-1: ETWNetMonv3Log.exe html2 1 \"rport >= 80\"");
Console.WriteLine("example 2-1: ETWNetMonv3Log.exe html2 1 \"events LIKE '*192.168*'\"");
Console.WriteLine("Note: for (syntax 2-1) EtwNetMonv3logs.txt & ETWProcessMonlog.txt should be in current folder");
Console.WriteLine();
}
static void Main(string[] args)
{
try
{
Console.WriteLine();
if (args.Length <= 1 && args[0].ToUpper() == "HELP")
{
help();
}
else
{
try
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("ETWNetMonv3Log Tool , Published by Damon Mohammadbagher , May 2021");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("ETWNetMonv3Log cmd tool is simple ETW log Reader & (XML/HTML) Report Maker for ETW logs, which made by ETWNetMonv3Agent");
Console.WriteLine();
Console.WriteLine("syntax 1: switch XML, All ETW records from text [EtwNetMonv3logs.txt] will save to xml file (convert all records to xml)");
Console.WriteLine("example 1: ETWNetMonv3Log.exe xml filename.xml ");
Console.WriteLine("syntax 2: switch HTML , simple Filter for ETW Records and Save report to HTML format with simple table");
Console.WriteLine("syntax 2-1: switch HTML2 , integrating ETWProcessMon Logs with ETW Network Log + simple Filter to HTML format with simple table");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"your query\" ");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"rport >=80 OR events LIKE '*Established*' AND events LIKE '*connect complete*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"events LIKE '*requested to connect*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"state NOT LIKE '*synsent*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"events LIKE '*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"rhost LIKE '192.168*' or lhost LIKE '192.168.1*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"rport <=80 OR lport >=50000\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"pname LIKE '*.exe*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"events LIKE '*C:\\*'\"");
Console.WriteLine("example 2: ETWNetMonv3Log.exe html \"PID = 1452\"");
Console.WriteLine("syntax 2-1: ETWNetMonv3Log.exe html2 [MODE 0=SYNSENT , 1=ESTABLISHED] [Query]");
Console.WriteLine("example 2-1: ETWNetMonv3Log.exe html2 1 \"PID = 1452\"");
Console.WriteLine("example 2-1: ETWNetMonv3Log.exe html2 0 \"PID = 1452\"");
Console.WriteLine("example 2-1: ETWNetMonv3Log.exe html2 1 \"rport >= 80\"");
Console.WriteLine("example 2-1: ETWNetMonv3Log.exe html2 1 \"events LIKE '*192.168*'\"");
Console.WriteLine("Note: for (syntax 2-1) EtwNetMonv3logs.txt & ETWProcessMonlog.txt should be in current folder");
Console.WriteLine();
Thread.CurrentThread.Priority = ThreadPriority.Highest;
XMLDataTableClass.TCPIP_settable2();
string[] ETW_TCPIP_data = new string[8];
try
{
byte[] b;
string s;
Thread.CurrentThread.Priority = ThreadPriority.Highest;
using (FileStream myfile = new FileStream(Logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
b = new byte[myfile.Length];
myfile.Read(b, 0, b.Length);
};
ResultText = Encoding.ASCII.GetString(b);
}
catch (Exception)
{
}
string[] textitems = null;
textitems = ResultText.Split('\r');
foreach (string item in textitems)
{
if (item != " " && (!item.Contains("\n ")))
{
line++;
try
{
if ((!item.Contains("exists. State = ")) && (!item.Contains("::ffff:")))
{
XMLDataTableClass.GetRowsTODataTable(DateTime.Now, item,
Convert.ToInt32(item.Split(')')[1].Split(']', ':')[1])
, _findstr("ProcessPath:", item),
_findstr("local=", item).Split(':')[0],
Convert.ToInt32(_findstr("local=", item).Split(':', ' ')[1])
, _findstr("remote=", item).Split(':')[0],
Convert.ToInt32(_findstr("remote=", item).Split(':', ')')[1]),
_findstr(item));
}
}
catch (Exception)
{
}
}
}
GC.GetTotalMemory(true);
Console.WriteLine("[>] ETW records loaded from file: \"" + "EtwNetMonv3logs.txt" + "\"");
if (args[0].ToUpper() == "XML")
{
XMLDataTableClass.TCPIPTable2.WriteXml(args[1].ToString());
XMLDataTableClass.TCPIPTable2.WriteXmlSchema("xml_schema.xml", true);
Console.WriteLine("[>] Full ETW log records saved to xml file: \"" + args[1].ToString() + "\"");
Console.WriteLine("[>] Xml schema saved to file: \"" + "xml_schema.xml" + "\".");
GC.GetTotalMemory(true);
}
else if (args[0].ToUpper() == "HTML2")
{
byte[] bb2;
string s2;
List<string> listx = new List<string>();
try
{
string[] textitems2 = null;
Thread.CurrentThread.Priority = ThreadPriority.Highest;
if (!File.Exists("ETWProcessMonlog.txt")) { Console.WriteLine("[>] Error => ETWProcessMon log file: \"" + "ETWProcessMonlog.txt" + "\" not found!"); }
using (FileStream myfile = new FileStream("ETWProcessMonlog.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
bb2 = new byte[myfile.Length];
myfile.Read(bb2, 0, bb2.Length);
ResultText2 = Encoding.ASCII.GetString(bb2);
};
textitems2 = ResultText2.Split('\r');
foreach (string item in textitems2)
{
listx.Add(item);
}
Console.WriteLine("[>] ETWProcessMon records loaded from file: \"" + "ETWProcessMonlog.txt" + "\"");
}
catch (Exception eeee)
{
Console.WriteLine(eeee.Message);
}
int counter = 1;
string html = "";
string query = args[2].ToString().Replace('"', ' ');
string style = "<html> <style>ul, #myUL {list-style-type: none; }# myUL { margin: 0; padding: 0; }" +
".caret { font:10pt Tahoma; cursor: pointer;" + " -webkit-user-select: none; /* Safari 3.1+ */ -moz-user-select: none; /* Firefox 2+ */ -ms-user-select: none; /* IE 10+ */" +
" user-select: none;}.caret::before { content: \"\\25B6\"; color: black; display: inline-block; margin-right: 0px;}" +
".caret-down::before { -ms-transform: rotate(90deg); /* IE 9 */ -webkit-transform: rotate(90deg); /* Safari */' transform: rotate(90deg); }" +
".nested { display: none;}.active { display: block;}</style>";
string htmstring1 = style + "<H2>Search Result for ETW logs " + "<H3> Query (" + query + ")</H3></H2><table border=\"1\"><tr style =\"background-color:#a0a0ff;font:10pt Tahoma;font-weight:bold;\" align = \"left\" > ";
string htmstring2 = "<td>id</td><td>localtime</td><td>events</td><td>PID</td><td>PName/ProcessPath</td><td>lhost</td><td>lport</td><td>rhost</td><td>rport</td><td>state</td>";
string htmstring3 = " ";
string tmp1 = "";
string htmstring4 = "";
DataRow[] dt = XMLDataTableClass.TCPIPTable2.Select(args[2].ToString());
bool clr = false;
foreach (DataRow Rowitem in dt)
{
if (clr) { htmstring4 += "<tr style=\"background-color:#9b9b9b;font:10pt Tahoma;\">"; clr = false; }
else if (!clr) { htmstring4 += "<tr style=\"background-color:#00c0f0;font:10pt Tahoma;\">"; clr = true; }
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + counter.ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[0].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[1].ToString().Replace('\n', ' ') + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[2].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[3].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[4].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[5].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[6].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[7].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[8].ToString() + "</td>" + "</tr>";
if (args[1].ToUpper() == "0")
{
if (Rowitem[8].ToString().ToUpper() == "SYNSENT")
{
try
{
foreach (string item in listx.FindAll(z => z.Contains("(" + Rowitem[2].ToString() + ")")))
{
htmstring4 += "<div\"><tr style=\"background-color:#19c0f0;\"><td align = \"left\"><span style=\"height: 0px; overflow - y:hidden\">";
htmstring4 += "<td align = \"left\"><span style=\"height: 0px; overflow - y:hidden\">";
htmstring4 += "<td align = \"left\"><span style=\"height: 0px; overflow - y:hidden\">";
htmstring4 += "<ul id=\"myUL\">";
if (item.Contains("[VirtualMemAlloc]"))
{
htmstring4 += "<li><span class=\"caret\">VirtualMemAlloc</span><ul class=\"nested\"><li style=\"font:10pt Tahoma;\">" + item + "</li></ul></li>";
}
else if (item.Contains("[Injected"))
{
tmp1 = "";
try
{
tmp1 = item.Split(')', ':')[5];
if (!(Int32.Parse(tmp1) >= 0)) { tmp1 = "-1"; }
}
catch (Exception) { tmp1 = "x"; }
htmstring4 += "<li><span class=\"caret\">Thread-Injection [TID:" + tmp1 + "]</span><ul class=\"nested\"><li style=\"color:darkred; font:11pt Tahoma;\">" + item + "</li></ul></li>";
}
/// old code
//htmstring4 += "<div><tr style=\"background-color:#00c0f0;\"><td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">";
//htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">";
//htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + item + "</td></tr></div>";
htmstring4 += "</ul>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">";
htmstring4 += "<td align = \"left\"><span style=\"font:10pt Tahoma; height: 0px; overflow - y:hidden\">" + Rowitem[3].ToString();
htmstring4 += "</td></tr></div>";
}
}
catch (Exception)
{
}
}
}
else if (args[1].ToUpper() == "1")
{
if (Rowitem[8].ToString().ToUpper() == "ESTABLISHED")
{
try
{
foreach (string item in listx.FindAll(z => z.Contains("(" + Rowitem[2].ToString() + ")")))
{
htmstring4 += "<div\"><tr style=\"background-color:#19c0f0;\"><td align = \"left\"><span style=\"height: 0px; overflow - y:hidden\">";
htmstring4 += "<td align = \"left\"><span style=\"height: 0px; overflow - y:hidden\">";
htmstring4 += "<td align = \"left\"><span style=\"height: 0px; overflow - y:hidden\">";
htmstring4 += "<ul id=\"myUL\">";
if (item.Contains("[VirtualMemAlloc]"))
{
htmstring4 += "<li><span class=\"caret\">VirtualMemAlloc</span><ul class=\"nested\"><li style=\"font:10pt Tahoma;\">" + item + "</li></ul></li>";
}
else if (item.Contains("[Injected"))
{
tmp1 = "";
try
{
tmp1 = item.Split(')', ':')[5];
if (!(Int32.Parse(tmp1) >= 0)) { tmp1 = "-1"; }
}
catch (Exception) { tmp1 = "x"; }
htmstring4 += "<li><span class=\"caret\">Thread-Injection [TID:" + tmp1 + "]</span><ul class=\"nested\"><li style=\"color:darkred; font:11pt Tahoma;\">" + item + "</li></ul></li>";
}
/// old code
//htmstring4 += "<div><tr style=\"background-color:#00c0f0;\"><td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">";
//htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">";
//htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + item + "</td></tr></div>";
htmstring4 += "</ul>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">";
htmstring4 += "<td align = \"left\"><span style=\"font:10pt Tahoma; height: 0px; overflow - y:hidden\">" + Rowitem[3].ToString();
htmstring4 += "</td></tr></div>";
}
}
catch (Exception)
{
}
}
}
counter++;
}
htmstring4 += "</tr></table></html>";
html = htmstring1 + htmstring2 + htmstring3 + htmstring4;
logfilewrite("QueryReport2.html", html);
Console.WriteLine("[!] Your query => \"" + query + "\"");
Console.WriteLine("[!] Query Result2 [" + dt.Length.ToString() + " Records]");
Console.WriteLine("[>] Query Result2 for ETW records saved to file: \"" + "QueryReport2.html" + "\"");
GC.GetTotalMemory(true);
}
else if (args[0].ToUpper() == "HTML")
{
byte[] bb2;
string s2;
List<string> listx = new List<string>();
int counter = 1;
string html = "";
string query = args[1].ToString().Replace('"', ' ');
string htmstring1 = "<html><H2>Search Result for ETW logs " + "<H3> Query (" + query + ")</H3></H2><table border=\"1\"><tr style =\"background-color:#a0a0ff;font:10pt Tahoma;font-weight:bold;\" align = \"left\" > ";
string htmstring2 = "<td>id</td><td>localtime</td><td>events</td><td>PID</td><td>PName/ProcessPath</td><td>lhost</td><td>lport</td><td>rhost</td><td>rport</td><td>state</td>";
string htmstring3 = " ";
string tmp1 = "";
string htmstring4 = "";
DataRow[] dt = XMLDataTableClass.TCPIPTable2.Select(args[1].ToString());
bool clr = false;
foreach (DataRow Rowitem in dt)
{
if (clr) { htmstring4 += "<tr style=\"background-color:#9b9b9b;font:10pt Tahoma;\">"; clr = false; }
else if (!clr) { htmstring4 += "<tr style=\"background-color:#00c0f0;font:10pt Tahoma;\">"; clr = true; }
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + counter.ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[0].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[1].ToString().Replace('\n', ' ') + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[2].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[3].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[4].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[5].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[6].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[7].ToString() + "</td>";
htmstring4 += "<td align = \"left\"><span style=\"height: 1px; overflow - y:hidden\">" + Rowitem[8].ToString() + "</td>" + "</tr>";
counter++;
}
htmstring4 += "</tr></table></html>";
html = htmstring1 + htmstring2 + htmstring3 + htmstring4;
logfilewrite("QueryReport.html", html);
Console.WriteLine("[!] Your query => \"" + query + "\"");
Console.WriteLine("[!] Query Result2 [" + dt.Length.ToString() + " Records]");
Console.WriteLine("[>] Query Result2 for ETW records saved to file: \"" + "QueryReport.html" + "\"");
GC.GetTotalMemory(true);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
help();
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
help();
}
}
}