-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscanner.php
executable file
·182 lines (164 loc) · 5.35 KB
/
scanner.php
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
<?php
$url="https://".$argv[1]."/owa";
$file="out.txt";
error_reporting(1);
function check_version($url)
{
//search version of Exchange
$file="out.txt";
$fn = fopen($file,"r");
while(! feof($fn))
{
$result = fgets($fn);
if(preg_match('/<link rel=\"shortcut icon\" href\=\"\/owa/' ,$result))
{
echo "Checking $url\n";
$vv=explode("\"", $result);
$v=explode('/', $vv[3]);
if (preg_match('/14\./', $result))
{
$version=$v[2];
}
else
{
$version=$v[3];
}
if (preg_match('/15\.0/', $version))
{
if (preg_match('/15\.0\.1497/', $version))
{
echo "OK This Exchange 2013 ($url) is patched to $version\n\n";
}
else
{
echo "ERROR: This Exchange 2013 ($url) should have Version 15.0.1497.006 but has $version\n\n";
}
}
elseif (preg_match('/15\.1/', $version))
{
if (preg_match('/15\.1\.1913/', $version) || preg_match('/15\.1\.1847/', $version) || preg_match('/15\.1\.1979/', $version) || preg_match('/15\.1\.2044/', $version) || preg_match('/15\.1\.2106/', $version) || preg_match('/15\.1\.2176/', $version) || preg_match('/15\.1\.2242/', $version) || preg_match('/15\.1\.2308/', $version))
{
echo "OK This Exchange 2016 ($url) is patched to $version\n\n";
}
else
{
echo "ERROR: This Exchange 2016 ($url) should have Version 15.1.1847.007 or 15.1.1913.007 but has $version\n\n";
}
}
elseif (preg_match('/15\.02/', $version))
{
if (preg_match('/15\.2\.0464/', $version) || preg_match('/15\.2\.0529/', $version) || preg_match('/15\.2\.0595/', $version) || preg_match('/15\.2\.0659/', $version) || preg_match('/15\.2\.0721/', $version) || preg_match('/15\.2\.0792/', $version) || preg_match('/15\.2\.0858/', $version) || preg_match('/15\.2\.0922/', $version))
{
echo "OK This Exchange 2019 ($url) is patched to $version\n\n";
}
else
{
echo "ERROR: This Exchange 2019 ($url) should have Version 15.2.0529.008 or 15.2.0464.011 but has $version\n\n";
}
}
elseif (preg_match('/14\./', $version))
{
if (preg_match('/14\.3\.496/', $version))
{
echo "OK This Exchange 2010 ($url) is patched to $version\n\n";
}
else
{
echo "ERROR: This Exchange 2010 ($url) should have Version 14.3.0496.000 but has $version\n\n";
}
}
elseif (preg_match('/8\./', $version))
{
echo "ERROR: This Exchange 2007 ($url) has no supported patch UPGRADE!!\n\n";
}
elseif (preg_match('/6\.5/', $version))
{
echo "ERROR: This Exchange 2000 ($url) has no supported patch UPGRADE!!\n\n";
}
}
}
fclose($fn);
}
function cidrl($cidr, &$error_code = 0, $callback = null)
{
$error_code = 0;
sscanf($cidr, "%[^/]/%u", $network, $bits);
$addr = ip2long($network);
if ($addr === false)
{
$error_code = 2;
return false;
}
if ($bits == 32)
{
if (is_callable($callback))
{
$callback(long2ip($addr));
return array();
}
return array(long2ip($addr));
}
if ($bits > 32)
{
$error_code = 3;
return false;
}
$mask = ~(0xFFFFFFFF >> $bits);
$addr_start = $addr & $mask;
$addr_end = ($addr & $mask) | ~$mask;
$addresses = array();
for ($i = $addr_start; $i <= $addr_end; $i++)
{
if (is_callable($callback)) $callback(long2ip($i));
else $addresses[] = long2ip($i);
}
return $addresses;
}
function Get_Content($server)
{
// Get Redirect URL
$ch = curl_init($server);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$html = curl_exec($ch);
$redirectURL = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL );
curl_close($ch);
// Get content and save in file
$ch = curl_init($redirectURL);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$html = curl_exec($ch);
curl_close($ch);
$file="out.txt";
file_put_contents($file, $html);
}
if (preg_match('/\//', $argv[1]))
{
$arr=cidrl($argv[1]);
foreach ($arr as $ip)
{
$url="https://$ip/owa";
echo "checking $ip\n";
Get_Content($url);
check_version($url);
}
}
else
{
Get_Content($url);
check_version($url);
}