-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathExchange_GetVersion_ParseFromWebsite.py
79 lines (70 loc) · 2.99 KB
/
Exchange_GetVersion_ParseFromWebsite.py
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
#!python3
import requests
import sys
import re
import urllib3
urllib3.disable_warnings()
from bs4 import BeautifulSoup
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
}
def FetchInformation():
url = "https://docs.microsoft.com/en-us/exchange/new-features/build-numbers-and-release-dates?view=exchserver-2019"
response = requests.get(url, verify=False, headers=headers)
soup = BeautifulSoup(response.text, features="html.parser")
print("[*] Try to access " + url)
print("[+] Article date: " + soup.find('time').text)
return soup
def ParseVersion(version, soup):
for tag in soup.find_all('tr'):
if version in tag.text:
print("[+] Exchange Information")
for versiondata in tag.stripped_strings:
if (len(versiondata)==5):
continue
print(" " + versiondata)
def GetVersion(host):
try:
print("[*] Trying to access EWS")
url1 = "https://" + host + "/ews"
req = requests.get(url1, headers = headers, verify=False)
if "X-FEServer" not in req.headers:
print("[!] Exchange 2010 or older")
print("[*] Trying to access OWA")
url2 = "https://" + host + "/owa"
req = requests.get(url2, headers = headers, verify=False)
pattern_version = re.compile(r"/owa/(.*?)/themes/resources/favicon.ico")
version = pattern_version.findall(req.text)[0]
print("[+] Version:" + version)
return version
else:
print("[+] X-FEServer:" + req.headers["X-FEServer"])
if "X-OWA-Version" in req.headers:
version = req.headers["X-OWA-Version"]
print("[+] X-OWA-Version:" + version)
return version
else:
print("[!] No X-OWA-Version")
print("[*] Trying to access OWA")
url2 = "https://" + host + "/owa"
req = requests.get(url2, headers = headers, verify=False)
pattern_version = re.compile(r"/owa/auth/(.*?)/themes/resources/favicon.ico")
version = pattern_version.findall(req.text)[0]
print("[+] Version:" + version)
return version
except Exception as e:
print("[!] "+str(e))
sys.exit(0)
if __name__ == '__main__':
if len(sys.argv)!=2:
print('Exchange_GetVersion_ParseFromWebsite.py')
print('Use to get the version of Exchange and parse the version from https://docs.microsoft.com/en-us/exchange/new-features/build-numbers-and-release-dates?view=exchserver-2019')
print('Usage:')
print('%s <path>'%(sys.argv[0]))
print('Eg.')
print('%s 192.168.1.1'%(sys.argv[0]))
sys.exit(0)
else:
version = GetVersion(sys.argv[1])
soup = FetchInformation()
ParseVersion(version, soup)