-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyetihunter.py
178 lines (136 loc) · 5.6 KB
/
yetihunter.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import json
import os
from getpass import getpass
from core.Authentication.Authentication import Authentication
from core.Other.Arguments.ArgParse import parseArgs, CONFIGFILE
from core.Other.PrintOutput.PrintOutput import printOutput
from core.Other.Resources.OutputDump import dumpCSV
from core.QueryActivity.QueryActivities import Query
from core.Other.Resources.Queries import QUERIES
from core.Other.Arguments.Banner import printBanner
args = parseArgs()
printBanner()
if not os.path.exists("./configfiles"):
os.mkdir("./configfiles")
if not os.path.exists("./output"):
os.mkdir("./output")
if args.generate_config_file:
with open("./configfiles/config.conf", 'w') as configfile:
json.dump(CONFIGFILE, configfile, indent=4, default=str)
printOutput("Successfully created config file ./configfiles/config.conf", "success")
configfile.close()
exit()
if args.config_file_path is not None:
with open(args.config_file_path, 'r') as toolconfigfile:
configJson = json.load(toolconfigfile)
toolconfigfile.close()
check = 0
user = configJson['USER']
authentication_method = configJson['AUTHENTICATION_METHOD']
warehouse = configJson['WAREHOUSE']
account = configJson['ACCOUNT']
database = configJson['DATABASE']
outputdir = configJson['OUTPUTDIR']
schema = configJson['SCHEMA']
password = configJson['PASSWORD']
if user is None or user == "":
printOutput("User is a required option. Please provide a user on USER field of the config file", "failure")
check = 1
if authentication_method is None or authentication_method == "":
printOutput("Authentication method is a required option. Please provide an Authentication Method on AUTHENTICATION_METHOD field of the config file", "failure")
check = 1
if warehouse is None or warehouse == "":
printOutput("Warehouse is a required option. Please provide a warehouse on WAREHOUSE field of the config file", "failure")
check = 1
if account is None or account == "":
printOutput("Account is a required option. Please provide an account on ACCOUNT field of the config file", "failure")
check = 1
if database is None or database == "":
printOutput("Database is a required option. Please provide a database on DATABASE field of the config file", "failure")
check = 1
if outputdir is None or outputdir == "":
printOutput(f"Output directory is a required option. Put the output directory name on OUTPUTDIR field of the config file", "failure")
check = 1
if check != 0:
exit()
else:
user = args.user
authentication_method = args.authentication_method
warehouse = args.warehouse
account = args.account
database = args.database
schema = args.schema
outputdir = args.output_directory
password = args.password
check = 0
if user is None or user == "":
printOutput("User is a required option. Please provide a user using -u flag", "failure")
check = 1
if authentication_method is None or authentication_method == "":
printOutput("Authentication method is a required option. Please provide an Authentication Method using -am flag", "failure")
check = 1
if warehouse is None or warehouse == "":
printOutput("Warehouse is a required option. Please provide a warehouse using -w flag", "failure")
check = 1
if account is None or account == "":
printOutput("Account is a required option. Please provide an account using -a flag", "failure")
check = 1
if database is None or database == "":
printOutput("Database is a required option. Please provide a database using -d flag", "failure")
check = 1
if outputdir is None or outputdir == "":
printOutput(f"Output directory is a required option. Put the output directory name using -o flag", "failure")
check = 1
if check != 0:
exit()
if os.path.exists(f'./output/{outputdir}'):
printOutput(f"Output directory ./output/{outputdir} exists. put a new name", "failure")
exit()
else:
os.mkdir(f"./output/{outputdir}")
if authentication_method == "USERPASS":
if password is None:
password = getpass()
authenticationObj = Authentication(
warehouse=warehouse,
database=database,
user=user,
password=password,
account=account,
schema=schema
)
conn = authenticationObj.authToWarehouseUsingUserAndPass()
elif authentication_method == "SSO":
authenticationObj = Authentication(
warehouse=warehouse,
database=database,
user=user,
password=None,
account=account,
schema=schema
)
conn = authenticationObj.authToWarehouseBrowserSSO()
else:
authenticationObj = None
conn = None
if conn is None:
exit()
results = {}
printOutput(f"Loaded {str(len(QUERIES))} queries to check", "success")
for queryDict in QUERIES:
query = queryDict['query']
name = queryDict['name']
description = queryDict['description']
queryObj = Query(
conn=conn,
query=query,
name=name
)
results[name] = queryObj.executeQuery()
if results[name] is not None:
if len(results[name]) > 1:
csvinfo = results[name]
dumpCSV(csvinfo, outputdir, name)
printinfo = results[name]
queryObj.printQueryOutput(name, printinfo)
authenticationObj.closeConnectionToWareHouse()