-
Notifications
You must be signed in to change notification settings - Fork 139
/
webhunter.cs
165 lines (142 loc) · 5.18 KB
/
webhunter.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
// Thanks to rvrsh3ll for the idea https://github.com/rvrsh3ll/Misc-Powershell-Scripts/blob/master/Find-Fruit.ps1
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Threading;
namespace ConnectTo
{
class Program
{
static bool verbose = false;
static string[] RangeToIPs(string range)
{
string[] info = range.Split('/');
long ip = ToInt(info[0]);
int mask = ~((1 << (32 - Int32.Parse(info[1]))) - 1);
List<string> ips = new List<string>();
long current = ip & mask;
while (current < ((ip & mask) | ~mask))
{
current++;
ips.Add(ToAddr(current));
}
return ips.ToArray();
}
static long ToInt(string addr)
{
return (long)(uint)IPAddress.NetworkToHostOrder((int)IPAddress.Parse(addr).Address);
}
static string ToAddr(long address)
{
return IPAddress.Parse(address.ToString()).ToString();
}
static void ScanHost(string host, string[] ports)
{
foreach (string port in ports)
{
foreach (string url in GetUrls())
{
Task t = Task.Run(() =>
{
string http = String.Format("http://{0}:{1}/{2}", host, port, url);
string https = String.Format("https://{0}:{1}/{2}", host, port, url);
int httpCode = 404;
int httpsCode = 404;
if (verbose)
{
Console.WriteLine("Querying {0}", http);
}
httpCode = SendRequest(http);
if (httpCode != -1)
{
Console.WriteLine("{0} returned {1}", http, httpCode);
}
if (verbose)
{
Console.WriteLine("Querying {0}", https);
}
httpsCode = SendRequest(https);
if (httpsCode != -1)
{
Console.WriteLine("{0} returned {1}", https, httpsCode);
}
// time out
if (httpCode == -1 && httpsCode == -1)
{
if (verbose)
{
Console.WriteLine("Skipping this port since it timed out.");
}
return;
}
});
}
}
}
static int SendRequest(string url)
{
int responseCode = 404;
try
{
Uri uri = new Uri(url);
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(uri);
wr.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0";
wr.Timeout = 1000;
HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
return Int32.Parse(response.StatusCode.ToString());
}
catch (Exception e)
{
if (e.Message.Contains("The operation has timed out"))
{
responseCode = -1;
}
if (verbose)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
return responseCode;
}
static string[] GetUrls()
{
List<string> urls = new List<string>();
urls.Add("jmx-console/");
urls.Add("web-console/ServerInfo.jsp");
urls.Add("invoker/JMXInvokerServlet");
urls.Add("system/console");
urls.Add("axis2/axis2-admin/");
urls.Add("manager/html/");
urls.Add("tomcat/manager/html/");
urls.Add("wp-admin/");
urls.Add("workorder/FileDownload.jsp");
urls.Add("ibm/console/logon.jsp?action=OK");
urls.Add("data/login");
urls.Add("script/");
urls.Add("opennms/");
urls.Add("RDWeb/Pages/en-US/Default.aspx");
urls.Add("eam/vib");
urls.Add("wps/portal/Home");
urls.Add("wps/myportal/");
return urls.ToArray();
}
static void Main(string[] args)
{
ThreadPool.SetMaxThreads(20, 20);
string[] ips = RangeToIPs(args[0]);
string[] ports = args[1].Split(',');
if (Array.Exists(args, match => match.ToLower() == "-verbose"))
{
verbose = true;
}
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
foreach (string ip in ips)
{
Console.WriteLine("Querying {0}", ip);
ScanHost(ip, ports);
}
}
}
}