forked from cs4p/infosecAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·64 lines (53 loc) · 2.38 KB
/
main.py
File metadata and controls
executable file
·64 lines (53 loc) · 2.38 KB
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
#!/usr/bin/env python3
import argparse
import getpass
import sys
import logging
from infosecAPI import learners
def main():
example = "Usage: %(prog)s -k key.txt -f Scheduled_CSV.csv -p 'http:http://proxy:8080, https:http://proxy:8080'"
options = argparse.ArgumentParser(epilog=example)
options.add_argument('-d', '--debug', help='Print debug messages', action='store_true')
options.add_argument('-q', '--quiet', help="Don't print status messages", action='store_true')
options.add_argument('-H', '--host', help='Base URL for the api. e.g. https://securityiq.infosecinstitute.com/api/v2/', default="https://securityiq.infosecinstitute.com/api/v2/")
options.add_argument('-k', '--passfile', help='File containing your api key (Default is to prompt)', required=True)
options.add_argument('-f', '--user_file', help="CSV file containing AD users", required=True)
options.add_argument('-p', '--proxies', help='Proxy server address in the form of "http=http://proxy:8080, https=http://proxy:8080"')
args = options.parse_args()
log_level = logging.INFO
if args.debug:
log_level = logging.DEBUG
if args.quiet:
log_level = logging.WARNING
logging.basicConfig(
level=log_level,
format='%(levelname)s: %(asctime)s: %(filename)s: %(funcName)s: %(lineno)d: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p',
handlers=[
logging.FileHandler('infosecAPI.log'),
logging.StreamHandler()]
)
if args.passfile:
with open(args.passfile) as f:
api_key = f.readline().strip()
else:
api_key = getpass.getpass()
base_url = args.host
user_file = args.user_file
# check for proxies
if args.proxies:
logging.debug("proxies: %s" % args.proxies)
proxies = {}
proxy_list = args.proxies.split(',')
for proxy in proxy_list:
proxy_parts = proxy.split('=')
if len(proxy_parts) == 2:
proxies[proxy_parts[0]] = proxy_parts[1]
else:
logging.error("Invalid proxy specification.")
sys.exit("Error: Invalid proxy specification.")
else:
proxies = None
sync_job = learners.LearnerQuery(base_url=base_url, api_key=api_key, proxies=proxies)
sync_job.sync_ad_with_learners(user_file=user_file)
if __name__ == '__main__':
sys.exit(main())