-
Notifications
You must be signed in to change notification settings - Fork 4
/
Program.cs
746 lines (688 loc) · 28.7 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
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using Fiddler;
using System.Text;
//using System.Windows.Forms.TextBox;
//using BasicFormats;
public class FileDumper : ISessionExporter, IDisposable
{
private string _MakeSafeFilename(string sFilename)
{
char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
if (sFilename.IndexOfAny(invalidFileNameChars) < 0)
{
return Utilities.TrimAfter(sFilename, 255);
}
StringBuilder stringBuilder = new StringBuilder(sFilename);
for (int i = 0; i < stringBuilder.Length; i++)
{
if (Array.IndexOf<char>(invalidFileNameChars, sFilename[i]) > -1 && sFilename[i] != Path.DirectorySeparatorChar)
{
stringBuilder[i] = '-';
}
}
return Utilities.TrimAfter(stringBuilder.ToString(), 160);
}
public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary<string, object> dictOptions, EventHandler<ProgressCallbackEventArgs> evtProgressNotifications)
{
if (sFormat != "Raw Files")
{
return false;
}
string text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
bool flag = true;
bool flag2 = true;
bool flag3 = true;
bool flag4 = false;
if (dictOptions != null)
{
if (dictOptions.ContainsKey("Folder"))
{
text = (dictOptions["Folder"] as string);
flag4 = true;
}
if (dictOptions.ContainsKey("RecreateStructure"))
{
flag = string.Equals("True", dictOptions["RecreateStructure"] as string, StringComparison.OrdinalIgnoreCase);
flag4 = true;
}
if (dictOptions.ContainsKey("OpenFolder"))
{
flag2 = string.Equals("True", dictOptions["OpenFolder"] as string, StringComparison.OrdinalIgnoreCase);
flag4 = true;
}
if (dictOptions.ContainsKey("SkipNon200"))
{
flag3 = string.Equals("True", dictOptions["SkipNon200"] as string, StringComparison.OrdinalIgnoreCase);
flag4 = true;
}
}
/*if (!flag4)
{
UIFileExport uIFileExport = new UIFileExport();
uIFileExport.txtLocation.Text = text;
uIFileExport.cbRecreateFolderStructure.Checked = FiddlerApplication.get_Prefs().GetBoolPref("fiddler.exporters.RawFiles.RecreateStructure", true);
uIFileExport.cbOpenFolder.Checked = FiddlerApplication.get_Prefs().GetBoolPref("fiddler.exporters.RawFiles.OpenFolder", true);
uIFileExport.cbHTTP200Only.Checked = FiddlerApplication.get_Prefs().GetBoolPref("fiddler.exporters.RawFiles.SkipNon200", true);
this.SetDefaultPath(uIFileExport.txtLocation, "fiddler.exporters.RawFiles.DefaultPath", text);
DialogResult dialogResult = uIFileExport.ShowDialog();
if (dialogResult != DialogResult.OK)
{
return false;
}
flag = uIFileExport.cbRecreateFolderStructure.Checked;
flag2 = uIFileExport.cbOpenFolder.Checked;
flag3 = uIFileExport.cbHTTP200Only.Checked;
text = uIFileExport.txtLocation.Text;
text = Utilities.EnsurePathIsAbsolute(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), text).Trim();
FiddlerApplication.get_Prefs().SetBoolPref("fiddler.exporters.RawFiles.RecreateStructure", flag);
FiddlerApplication.get_Prefs().SetBoolPref("fiddler.exporters.RawFiles.OpenFolder", flag2);
FiddlerApplication.get_Prefs().SetBoolPref("fiddler.exporters.RawFiles.SkipNon200", flag3);
FiddlerApplication.get_Prefs().SetStringPref("fiddler.exporters.RawFiles.DefaultPath", text);
uIFileExport.Dispose();
text = string.Concat(new object[]
{
text,
Path.DirectorySeparatorChar,
"Dump-",
DateTime.Now.ToString("MMdd-HH-mm-ss"),
Path.DirectorySeparatorChar
});
}*/
try
{
Directory.CreateDirectory(text);
}
catch (Exception ex)
{
FiddlerApplication.ReportException(ex, "Export Failed");
bool result = false;
return result;
}
int num = 0;
for (int i = 0; i < oSessions.Length; i++)
{
Session session = oSessions[i];
try
{
//int responseCode= session.responseCode;
if (!flag3 || session.responseCode == 200)
{
if (session.HTTPMethodIs("CONNECT"))
{
num++;
}
else
{
if (session.responseBodyBytes != null && session.responseBodyBytes.Length > 0)
{
string text3;
if (flag)
{
string text2 = Utilities.TrimAfter(session.url, '?');
text3 = text2.Replace('/', Path.DirectorySeparatorChar);
if (text3.EndsWith(string.Empty + Path.DirectorySeparatorChar))
{
text3 += session.SuggestedFilename;
}
if (text3.Length > 0 && text3.Length < 260)
{
text3 = text + this._MakeSafeFilename(text3);
}
else
{
text3 = text + session.SuggestedFilename;
}
}
else
{
text3 = text + session.SuggestedFilename;
}
text3 = text3 + "_";
text3 = Utilities.EnsureUniqueFilename(text3);
byte[] array = session.responseBodyBytes;
if (session.oResponse.headers.Exists("Content-Encoding") || session.oResponse.headers.Exists("Transfer-Encoding"))
{
array = (byte[])array.Clone();
Utilities.utilDecodeHTTPBody(session.oResponse.headers, ref array);
}
Console.Write(String.Format("Writing #{0} to {1}\n", session.id.ToString(), text3));
Utilities.WriteArrayToFile(text3, array);
}
num++;
/*if (evtProgressNotifications != null)
{
ProgressCallbackEventArgs progressCallbackEventArgs = new ProgressCallbackEventArgs((float)num / (float)oSessions.Length, "Dumped " + num.ToString() + " files to disk.");
evtProgressNotifications(null, progressCallbackEventArgs);
if (progressCallbackEventArgs.get_Cancel())
{
bool result = false;
return result;
}
}*/
}
}
}
catch (Exception ex2)
{
FiddlerApplication.ReportException(ex2, "Failed to generate response file.");
}
}
/*if (flag2)
{
try
{
string fileName = string.Format("\"{0}\"", text);
using (Process.Start(new ProcessStartInfo(fileName)
{
Verb = "explore"
}))
{
}
}
catch (Exception ex3)
{
FiddlerApplication.ReportException(ex3, "Cannot open folder");
}
}*/
return true;
}
/*private void SetDefaultPath(TextBox txtUI, string sPrefName, string sDefaultPath)
{
string text = FiddlerApplication.get_Prefs().GetStringPref(sPrefName, sDefaultPath).Trim();
try
{
if (!Directory.Exists(text))
{
text = sDefaultPath;
}
}
catch
{
text = sDefaultPath;
}
txtUI.Text = text;
}*/
public void Dispose()
{
}
}
namespace AnalyzePcapFile
{
class Program
{
public static void WriteCommandResponse(string s)
{
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(s);
Console.ForegroundColor = oldColor;
}
public static void DoQuit()
{
WriteCommandResponse("Shutting down...");
Fiddler.FiddlerApplication.Shutdown();
Thread.Sleep(500);
}
private static string Ellipsize(string s, int iLen)
{
if (s.Length <= iLen) return s;
return s.Substring(0, iLen - 3) + "...";
}
private static void ReadSessions(List<Fiddler.Session> oAllSessions)
{
Session[] oLoaded = Utilities.ReadSessionArchive(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
+ Path.DirectorySeparatorChar + "ToLoad.saz", false);
if ((oLoaded != null) && (oLoaded.Length > 0))
{
oAllSessions.AddRange(oLoaded);
WriteCommandResponse("Loaded: " + oLoaded.Length + " sessions.");
}
}
private static void SaveSessionsToFile(List<Fiddler.Session> oAllSessions)
{
bool bSuccess = false;
string sFilename = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
+ Path.DirectorySeparatorChar + DateTime.Now.ToString("hh-mm-ss") + ".saz";
try
{
try
{
Monitor.Enter(oAllSessions);
string sPassword = null;
Console.WriteLine("Password Protect this Archive (Y/N)?");
ConsoleKeyInfo oCKI = Console.ReadKey();
if ((oCKI.KeyChar == 'y') || (oCKI.KeyChar == 'Y'))
{
Console.WriteLine("\nEnter the password:");
sPassword = Console.ReadLine();
Console.WriteLine(String.Format("\nEncrypting with Password: '{0}'", sPassword));
}
Console.WriteLine();
bSuccess = Utilities.WriteSessionArchive(sFilename, oAllSessions.ToArray(), sPassword, false);
}
finally
{
Monitor.Exit(oAllSessions);
}
WriteCommandResponse( bSuccess ? ("Wrote: " + sFilename) : ("Failed to save: " + sFilename) );
}
catch (Exception eX)
{
Console.WriteLine("Save failed: " + eX.Message);
}
}
private static void WriteSessionList(List<Fiddler.Session> oAllSessions)
{
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Session list contains...");
try
{
Monitor.Enter(oAllSessions);
foreach (Session oS in oAllSessions)
{
Console.Write(String.Format("{0} {1} {2}\n{3} {4}\n\n", oS.id, oS.oRequest.headers.HTTPMethod, Ellipsize(oS.fullUrl, 60), oS.responseCode, oS.oResponse.MIMEType));
}
}
finally
{
Monitor.Exit(oAllSessions);
}
Console.WriteLine();
Console.ForegroundColor = oldColor;
}
private static void WriteSessionList(Fiddler.Session[] oAllSessions)
{
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Full Session list details...");
//string referer = "";
try
{
Monitor.Enter(oAllSessions);
foreach (Session oS in oAllSessions)
{
//Console.Write(String.Format("{0} {1} {2}\n{3} {4}\n\n", oS.id, oS.oRequest.headers.HTTPMethod, Ellipsize(oS.fullUrl, 256), oS.responseCode, oS.oResponse.MIMEType));
if (oS.oRequest.headers == null)
continue;
IEnumerator<HTTPHeaderItem> hdr1 = oS.oRequest.headers.GetEnumerator();
hdr1.Reset();
//referer = "";
#if false
while (hdr1.MoveNext())
{
if(hdr1.Current.Name.Equals("Referer", StringComparison.OrdinalIgnoreCase)){
//Console.WriteLine("Session list contains...");
referer = hdr1.Current.Value;
break;
}
}
if(referer != "")
Console.Write(String.Format("{0}\n\t{1}\n\n", oS.fullUrl, referer));
else
Console.Write(String.Format("{0}\n", oS.fullUrl));
#endif
Console.Write(String.Format("{0}\r\n", oS.fullUrl));
/*while (hdr1.MoveNext())
{
Console.Write(String.Format("{0}\n", hdr1.ToString()));
}*/
Console.Write(String.Format("{0}", oS.oRequest.headers.ToString()));
Console.WriteLine();
Console.WriteLine();
}
}
finally
{
Monitor.Exit(oAllSessions);
}
Console.WriteLine();
Console.ForegroundColor = oldColor;
}
public static bool DoExport(string sExportFormat, Session[] oSessions, Dictionary<string, object> dictOptions, EventHandler<ProgressCallbackEventArgs> ehPCEA)
{
bool result = false;
try
{
ISessionExporter sessionExporter = new FileDumper();
result = sessionExporter.ExportSessions(sExportFormat, oSessions, dictOptions, ehPCEA);
sessionExporter.Dispose();
}
catch (Exception eX)
{
//FiddlerApplication.LogAddonException(eX, "Exporter for " + sExportFormat + " failed.");
Console.Write(String.Format("Exporter for {0} failed.", sExportFormat));
result = false;
}
//FiddlerApplication.UI.UseWaitCursor = false;
return result;
}
public static bool WriteSessionArchive(string sFilename, Session[] arrSessions, string sPassword, bool bVerboseDialogs)
{
if (arrSessions == null || arrSessions.Length < 1)
{
if (bVerboseDialogs)
{
FiddlerApplication.DoNotifyUser("No sessions were provided to save to the archive.", "WriteSessionArchive - No Input");
}
return false;
}
if (FiddlerApplication.oSAZProvider == null)
{
throw new NotSupportedException("This application was compiled without .SAZ support.");
}
//FiddlerApplication.DoBeforeSaveSAZ(sFilename, arrSessions);
bool result;
try
{
if (File.Exists(sFilename))
{
File.Delete(sFilename);
}
ISAZWriter iSAZWriter = FiddlerApplication.oSAZProvider.CreateSAZ(sFilename);
if (!string.IsNullOrEmpty(sPassword))
{
iSAZWriter.SetPassword(sPassword);
}
iSAZWriter.Comment = "Fiddler Session Archive. See http://fiddler2.com";
int num = 1;
string sFileNumberFormat = "D" + arrSessions.Length.ToString().Length;
for (int i = 0; i < arrSessions.Length; i++)
{
Session oSession = arrSessions[i];
WriteSessionToSAZ(oSession, iSAZWriter, num, sFileNumberFormat, null, bVerboseDialogs);
num++;
}
iSAZWriter.CompleteArchive();
result = true;
}
catch (Exception ex)
{
if (bVerboseDialogs)
{
FiddlerApplication.DoNotifyUser("Failed to save Session Archive.\n\n" + ex.Message, "Save Failed");
}
result = false;
}
return result;
}
internal static void WriteSessionToSAZ(Session oSession, ISAZWriter oISW, int iFileNumber, string sFileNumberFormat, StringBuilder sbHTML, bool bVerboseDialogs)
{
string text = "raw\\" + iFileNumber.ToString(sFileNumberFormat);
string text2 = text + "_c.txt";
string text3 = text + "_s.txt";
string text4 = text + "_m.xml";
bool shouldicreatexmlfile = true;
try
{
oISW.AddFile(text2, delegate(Stream oS)
{
oSession.WriteRequestToStream(false, true, oS);
});
}
catch (Exception eX)
{
if (bVerboseDialogs)
{
//FiddlerApplication.DoNotifyUser( + Utilities.DescribeExceptionWithStack(eX), "Archive Failure");
Console.Write(String.Format("Unable to add " + text2 + "\n\n"));
}
}
try
{
oISW.AddFile(text3, delegate(Stream oS)
{
oSession.WriteResponseToStream(oS, false);
});
}
catch (Exception eX2)
{
if (bVerboseDialogs)
{
//FiddlerApplication.DoNotifyUser("Unable to add " + text3 + "\n\n" + Utilities.DescribeExceptionWithStack(eX2), "Archive Failure");
Console.Write(String.Format("Unable to add " + text3 + "\n\n"));
}
}
if (shouldicreatexmlfile)
{
try
{
oISW.AddFile(text4, delegate(Stream oS)
{
oSession.WriteMetadataToStream(oS);
});
}
catch (Exception eX3)
{
if (bVerboseDialogs)
{
//FiddlerApplication.DoNotifyUser("Unable to add " + text4 + "\n\n" + Utilities.DescribeExceptionWithStack(eX3), "Archive Failure");
Console.Write(String.Format("Unable to add " + text4 + "\n\n"));
}
}
}
if (oSession.bHasWebSocketMessages)
{
Console.Write(String.Format("[INTERESTING]Skipping websocket sessions.\n\n"));
/*string text5 = text + "_w.txt";
try
{
oISW.AddFile(text5, delegate(Stream oS)
{
oSession.WriteWebSocketMessagesToStream(oS);
});
}
catch (Exception eX4)
{
if (bVerboseDialogs)
{
FiddlerApplication.DoNotifyUser("Unable to add " + text5 + "\n\n" + Utilities.DescribeExceptionWithStack(eX4), "Archive Failure");
}
}*/
}
}
private static void addittothetree(ref List<TreeNode> rootNodeList, string parenturl, string childurl)
{
bool added = false;
// childurl is always NOT NULL
if (parenturl != "")
{
//there is a referer URL
foreach (TreeNode RootNode in rootNodeList)
{
added = RootNode.AddtoTree(parenturl, childurl);
if (added)
break;
}
if (!added)
{
//add it to root
rootNodeList.Add(new TreeNode(parenturl));
addittothetree(ref rootNodeList, parenturl, childurl);
return;
}
} else {
foreach (TreeNode RootNode in rootNodeList)
{
if (RootNode.url.ToLower() == childurl.ToLower())
return;
}
//add it to root
rootNodeList.Add(new TreeNode(childurl));
}
}
private static void CreateAndOutputURLTraversalTree(Fiddler.Session[] oAllSessions)
{
ConsoleColor oldColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Session list contains...");
string referer = "";
var rootNodesList = new List<TreeNode>();
try
{
Monitor.Enter(oAllSessions);
foreach (Session oS in oAllSessions)
{
//Console.Write(String.Format("{0} {1} {2}\n{3} {4}\n\n", oS.id, oS.oRequest.headers.HTTPMethod, Ellipsize(oS.fullUrl, 256), oS.responseCode, oS.oResponse.MIMEType));
if (oS.oRequest.headers == null)
continue;
IEnumerator<HTTPHeaderItem> hdr1 = oS.oRequest.headers.GetEnumerator();
hdr1.Reset();
referer = "";
while (hdr1.MoveNext())
{
if (hdr1.Current.Name.Equals("Referer", StringComparison.OrdinalIgnoreCase))
{
referer = hdr1.Current.Value;
break;
}
}
//Console.Write(String.Format("{0}\n\t{1}\n\n", oS.fullUrl, referer));
addittothetree(ref rootNodesList, referer, oS.fullUrl);
}
}
finally
{
Monitor.Exit(oAllSessions);
}
foreach (TreeNode RootNode in rootNodesList)
{
RootNode.PrintTree();
}
Console.WriteLine();
Console.ForegroundColor = oldColor;
}
private static void fileteroutInterestingStreamSessions(Fiddler.Session[] oAllSessions, out Fiddler.Session[] octetStreamSessions, out Fiddler.Session[] NoUserAgentSessions)
{
List<Session> octetStreams = new List<Session>();
List<Session> NoUAStreams = new List<Session>();
bool foundBinary = false;
bool seenanuseragent = false;
try
{
Monitor.Enter(oAllSessions);
foreach (Session oS in oAllSessions)
{
//Console.Write(String.Format("{0} {1} {2}\n{3} {4}\n\n", oS.id, oS.oRequest.headers.HTTPMethod, Ellipsize(oS.fullUrl, 256), oS.responseCode, oS.oResponse.MIMEType));
if (oS.oResponse.headers == null)
continue;
IEnumerator<HTTPHeaderItem> hdr1 = oS.oResponse.headers.GetEnumerator();
hdr1.Reset();
foundBinary = false;
while (hdr1.MoveNext())
{
if (hdr1.Current.Name.IndexOf("content-type", StringComparison.OrdinalIgnoreCase) >= 0)
{
if (hdr1.Current.Value.IndexOf("octet-stream", StringComparison.OrdinalIgnoreCase) >= 0 ||
hdr1.Current.Value.IndexOf("msdownload", StringComparison.OrdinalIgnoreCase) >= 0)
{
Console.Write(String.Format("Exe file= {0}\n", hdr1.Current.Value));
foundBinary = true;
break;
}
}
}
if (foundBinary == true)
octetStreams.Add(oS);
}
}
finally
{
Monitor.Exit(oAllSessions);
}
try
{
Monitor.Enter(oAllSessions);
foreach (Session oS in oAllSessions)
{
//Console.Write(String.Format("{0} {1} {2}\n{3} {4}\n\n", oS.id, oS.oRequest.headers.HTTPMethod, Ellipsize(oS.fullUrl, 256), oS.responseCode, oS.oResponse.MIMEType));
if (oS.oRequest.headers == null)
continue;
IEnumerator<HTTPHeaderItem> hdr1 = oS.oRequest.headers.GetEnumerator();
hdr1.Reset();
seenanuseragent = false;
while (hdr1.MoveNext())
{
//Console.Write(String.Format("{0}\n", hdr1.Current.Name));
if (hdr1.Current.Name.IndexOf("user-agent", StringComparison.OrdinalIgnoreCase) >= 0)
{
//Console.Write(String.Format("Matched {0}\n", hdr1.Current.Name));
seenanuseragent = true;
break;
}
}
if (seenanuseragent == false)
{
NoUAStreams.Add(oS);
//Console.Write("[hidd3ncod3s]Added a session\n");
}
}
}
finally
{
Monitor.Exit(oAllSessions);
}
octetStreamSessions= octetStreams.ToArray();
NoUserAgentSessions = NoUAStreams.ToArray();
}
static void Main(string[] args)
{
ArgumentParser.InputArguments arguments = new ArgumentParser.InputArguments(args);
if (args.Length < 1 )
{
//"%s <fullpathofpcap>\n\n"
Console.Write(String.Format("{0} <fullpathofpcap>\n", System.AppDomain.CurrentDomain.FriendlyName));
return;
}
int iProcCount = Environment.ProcessorCount;
int iMinWorkerThreads = Math.Max(16, 6 * iProcCount);
int iMinIOThreads = iProcCount;
ThreadPool.SetMinThreads(iMinWorkerThreads, iMinIOThreads);
List<Fiddler.Session> oAllSessions = new List<Fiddler.Session>();
// <-- Personalize for your Application, 64 chars or fewer
//Fiddler.FiddlerApplication.SetAppDisplayName("AnalyzePcapFile");
Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
DNZSAZProvider.fnObtainPwd = () =>
{
Console.WriteLine("Enter the password (or just hit Enter to cancel):");
string sResult = Console.ReadLine();
Console.WriteLine();
return sResult;
};
FiddlerApplication.oSAZProvider = new DNZSAZProvider();
FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true);
Dictionary<string, object> dictOptions = new Dictionary<string, object>();
dictOptions.Add("Filename", args[0]);
dictOptions.Add("Quiet", "True");
BasicFormats.PacketCaptureImport pcapreader = new BasicFormats.PacketCaptureImport();
Session[] pcapSessions= pcapreader.ImportSessions("Packet Capture", dictOptions, null);
Session[] octetStreamSessions;
Session[] NoUserAgentSessions;
if (pcapSessions != null && pcapSessions.Length > 0)
{
Console.WriteLine("Successfully parsed PCAP File " + args[0]);
CreateAndOutputURLTraversalTree(pcapSessions);
Console.WriteLine("=============================================================");
//WriteSessionList(pcapSessions);
WriteSessionArchive(args[0] + ".saz", pcapSessions, "", true);
}
else
{
Console.WriteLine("ERROR parsing PCAP file " + args[0]);
}
}
/// <summary>
/// When the user hits CTRL+C, this event fires. We use this to shut down and unregister our FiddlerCore.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
DoQuit();
}
}
}