Created
February 9, 2023 18:13
-
-
Save JosephGregg/5d8adb4d2453a6713ab8d317118af205 to your computer and use it in GitHub Desktop.
azure_enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import csv | |
import base64 | |
import logging | |
import argparse | |
import traceback | |
import lxml.etree as etree | |
import sys | |
from io import StringIO | |
from urllib import request | |
from cryptography import x509 | |
from urllib.parse import urlparse | |
domain = sys.argv[1] | |
autodiscover_post_body = """<?xml version="1.0" encoding="utf-8"?> | |
<soap:Envelope xmlns:exm="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:ext="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |
<soap:Header> | |
<a:Action soap:mustUnderstand="1">http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetFederationInformation</a:Action> | |
<a:To soap:mustUnderstand="1">https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc</a:To> | |
<a:ReplyTo> | |
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> | |
</a:ReplyTo> | |
</soap:Header> | |
<soap:Body> | |
<GetFederationInformationRequestMessage xmlns="http://schemas.microsoft.com/exchange/2010/Autodiscover"> | |
<Request> | |
<Domain>"""+ domain +"""</Domain> | |
</Request> | |
</GetFederationInformationRequestMessage> | |
</soap:Body> | |
</soap:Envelope>""" | |
autodiscover_post_headers = { | |
"Content-Type" : "text/xml; charset=utf-8", | |
"SOAPAction" : '"http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetFederationInformation"', | |
"User-Agent" : "AutodiscoverClient" | |
} | |
autodiscover_post_url = 'https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc' | |
autodiscover_request = request.Request(autodiscover_post_url, | |
autodiscover_post_body.encode('utf-8'), | |
autodiscover_post_headers) | |
response_raw = request.urlopen(autodiscover_request) | |
response_xml = etree.fromstring(response_raw.read()) | |
for domain in response_xml.xpath("//*[local-name() = 'Domain']//text()"): | |
print(domain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment