-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathTeamsEnum.py
98 lines (75 loc) · 3.86 KB
/
TeamsEnum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python3
import argparse
import requests
import json
import os
import teamsenum.auth
import time
import threading
from teamsenum.auth import p_success, p_err, p_warn, p_normal, p_info
from teamsenum.enum import TeamsUserEnumerator
def banner(__version__):
print("""
_______ ______
|__ __| | ____|
| | ___ __ _ _ __ ___ ___| |__ _ __ _ _ _ __ ___
| |/ _ \/ _` | '_ ` _ \/ __| __| | '_ \| | | | '_ ` _ \
| | __/ (_| | | | | | \__ \ |____| | | | |_| | | | | | |
|_|\___|\__,_|_| |_| |_|___/______|_| |_|\__,_|_| |_| |_|
v%s developed by %s
%s
""" % (__version__, "@_bka_", "SSE | Secure Systems Engineering GmbH"))
def enumerate_user(enum, email, accounttype, presence, outfile):
enum.check_user(email.strip(), accounttype, presence=presence, outfile=outfile)
if __name__ == "__main__":
"""
Main entrypoint. Parses command line arguments and invokes login and enumeration sequence.
Args:
argv (str []): Command line arguments passed to this script
Returns:
None
"""
__version__ = "1.0.3"
banner(__version__)
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--authentication', dest='authentication', choices=['devicecode','password','token'], required=True, help='')
parser.add_argument('-u', '--username', dest='username', type=str, required=False, help='Username for authentication')
parser.add_argument('-p', '--password', dest='password', type=str, required=False, help='Password for authentication')
parser.add_argument('-o', '--outfile', dest='outfile', type=str, required=False, help='File to write the results to')
parser.add_argument('-d', '--devicecode', dest='devicecode', type=str, required=False, help='Use Device code authentication flow')
parser.add_argument('-s', '--skypetoken', dest='skypetoken', type=str, required=False, help='Skype specific token from X-Skypetoken header. Only required for personal accounts')
parser.add_argument('-t', '--accesstoken', dest='bearertoken', type=str, required=False, help='Bearer token from Authorization: Bearer header. Required by teams and live.com accounts')
parser.add_argument('--delay', dest='delay', type=int, required=False, default=0, help='Delay in [s] between each attempt. Default: 0')
parser_inputdata_group = parser.add_mutually_exclusive_group(required=True)
parser_inputdata_group.add_argument('-e', '--targetemail', dest='email', type=str, required=False, help='Single target email address')
parser_inputdata_group.add_argument('-f', '--file', dest='file', type=str, required=False, help='Input file containing a list of target email addresses')
parser.add_argument('-n', '--threads', dest='num_threads', type=int, required=False, default=10, help='Number of threads to use for enumeration. Default: 10')
args = parser.parse_args()
if args.outfile:
fd = teamsenum.utils.open_file(args.outfile)
else:
fd = None
accounttype, bearertoken, skypetoken, teams_enrolled, refresh_token, auth_app, auth_metadata = teamsenum.auth.do_logon(args)
enum = TeamsUserEnumerator(skypetoken, bearertoken, teams_enrolled, refresh_token, auth_app, auth_metadata)
if args.email:
emails = [args.email]
if args.file:
with open(args.file) as f:
emails = f.readlines()
p_info("Starting user enumeration\n")
threads = []
for email in emails:
time.sleep(args.delay)
thread = threading.Thread(target=enumerate_user, args=(enum, email, accounttype, True, fd))
threads.append(thread)
thread.start()
# Limit the number of active threads
if len(threads) >= args.num_threads:
for t in threads:
t.join()
threads = []
# Wait for the remaining threads to finish
for thread in threads:
thread.join()
if fd:
fd.close()