Skip to content

Instantly share code, notes, and snippets.

@glennzw
Created October 11, 2016 19:48
Show Gist options
  • Save glennzw/39261d1d8817016df585865bd46bb628 to your computer and use it in GitHub Desktop.
Save glennzw/39261d1d8817016df585865bd46bb628 to your computer and use it in GitHub Desktop.
Check if a host has Outlook Web Access (OWA).
#!/usr/bin/python
# Check if a host has OWA
import requests
import dns.resolver
import csv
import sys
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
timeout = 3 #for web fetches
def checkSrv(_d):
try:
_ = dns.resolver.query("_autodiscover._tcp." + _d, "SRV")
except:
return False
else:
return True
def checkXML(_d):
m1, m2 = False, False
try:
r = requests.get("https://%s/autodiscover/autodiscover.xml" % _d, verify=False, timeout=timeout)
if r.status_code != 404:
m1 = True
except:
pass
try:
r = requests.get("https://autodiscover.%s/autodiscover/autodiscover.xml" % _d, verify=False, timeout=timeout)
if r.status_code == 404:
m2 = True
except:
pass
return (m1 or m2)
if __name__ == "__main__":
f = open(sys.argv[1], 'rt')
oF = open(sys.argv[1] + "_owa.csv", 'wt')
print "Writing output to " + sys.argv[1] + "_owa.csv"
writer = csv.writer(oF)
writer.writerow( ('domain', 'isOWA') )
reader = csv.reader(f)
for row in reader:
domain = row[0]
if checkSrv(domain) or checkXML(domain):
print "[+] %s: has OWA" % domain
writer.writerow((domain, 1))
else:
print "[-] %s: no OWA" % domain
writer.writerow((domain, 0))
oF.flush()
oF.close()
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment