Skip to content

Instantly share code, notes, and snippets.

@milo2012
Created May 9, 2017 18:22
Show Gist options
  • Select an option

  • Save milo2012/885ecbd98f9407b2121884afee837eb5 to your computer and use it in GitHub Desktop.

Select an option

Save milo2012/885ecbd98f9407b2121884afee837eb5 to your computer and use it in GitHub Desktop.
Test Accounts on OWA (Outlook Web Access) Website.
import sys
from exchangelib import DELEGATE, IMPERSONATION, Account, Credentials, ServiceAccount, \
EWSDateTime, EWSTimeZone, Configuration, NTLM, CalendarItem, Message, \
Mailbox, Attendee, Q, ExtendedProperty, FileAttachment, ItemAttachment, \
HTMLBody, Build, Version
from exchangelib import DELEGATE, IMPERSONATION, Account, Credentials, \
EWSDateTime, EWSTimeZone, Configuration, NTLM, CalendarItem, Message, \
Mailbox, Attendee, Q
from termcolor import colored, cprint
import itertools
import multiprocessing
import argparse
import os
'''
Example
$ python testOWA.py -f /tmp/creds.txt -c , -s mail.exchangeserver.com -n 20
'''
numOfThreads=20
exchServer=''
def setColor(message, bold=False, color=None, onColor=None):
retVal = colored(message, color=color, on_color=onColor, attrs=("bold",))
return retVal
def testAccount(input):
email=input[0][0]
username=input[0][1]
password=input[0][2]
credentials = ServiceAccount(username=username, password=password, max_wait=5)
try:
config = Configuration(server=exchServer, credentials=credentials)
account = Account(primary_smtp_address=email, config=config,
autodiscover=False, access_type=DELEGATE)
account.inbox.get_folder_by_name('Inbox')
print (setColor("[+]", bold, color="green"))+" "+username+" [OK]"
#print account.inbox.total_count
#print account.inbox.unread_count
except Exception as e:
if "The specified object was not found in the store." in str(e):
print (setColor("[+]", bold, color="green"))+" "+username+" [OK]"+"\t"+str(e)
elif "No subfolders found with name Inbox" in str(e):
print (setColor("[+]", bold, color="green"))+" "+username+" [OK]"+"\t"+str(e)
elif "WrappedSocket' object has no attribute 'getsockname" in str(e):
print (setColor("[-]", bold, color="red"))+" "+username+" [INVALID CREDS]"
else:
print (setColor("[-]", bold, color="red"))+" "+username+" [FAILED]"+"\t"+str(e)
parser = argparse.ArgumentParser(
prog='PROG',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=('''\
+-- Test Exchange Domain Accounts on Outlook Web Access Site
'''))
parser.add_argument("-f", type=str, dest="credFileList", help="Credentials File List (CSV Format)")
parser.add_argument("-c", type=str, dest="commaSeparator", help="Separator in CSV file")
parser.add_argument("-s", type=str, dest="exchServer", help="Exchange Server DNS Name")
parser.add_argument("-n", type=str, dest="noOfThreads", help="Number of Threads")
bold=True
filename=''
commaSeparator=','
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
if os.path.exists(args.credFileList):
filename=args.credFileList
else:
sys.exit()
if args.commaSeparator:
commaSeparator=(args.commaSeparator).strip()
else:
commaSeparator=","
if args.exchServer:
exchServer=args.exchServer
else:
print "[-] Please enter the DNS name of the exchange server"
sys.exit()
lines=[]
tmpUserList=[]
with open(filename) as f:
lines = f.read().splitlines()
for x in lines:
if commaSeparator not in x:
print "[-] '"+commaSeparator+"' not found in line"
os._exit(0)
email= x.split(commaSeparator)[0]
username= x.split(commaSeparator)[1]
password= x.split(commaSeparator)[2]
tmpUserList.append([email,username,password])
if args.noOfThreads:
numOfThreads=int(args.noOfThreads)
else:
numOfThreads=20
p = multiprocessing.Pool(numOfThreads)
tmpResultList = p.map(testAccount,itertools.izip(tmpUserList))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment