-
Notifications
You must be signed in to change notification settings - Fork 0
/
bard_VA.py
413 lines (393 loc) · 16 KB
/
bard_VA.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
import argparse
import json
import os
from typing import Any
from dotenv import load_dotenv
from rich import print
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from commands.dns_recon import dnsr
from commands.geo import geoip
from commands.port_scanner import p_scanner
from commands.subdomain import sub
console = Console()
load_dotenv()
bkey = os.getenv('BARD_API_KEY') # BardAPI KEY
gkey = os.getenv('GEOIP_API_KEY') # GeoIP API
# Create an argument parser to handle command-line arguments
parser = argparse.ArgumentParser(description='Python-Nmap and Bard integrated Vulnerability scanner')
parser.add_argument('--target', metavar='target', type=str, help='Target IP or hostname')
parser.add_argument('--profile', metavar='profile', type=int, default=1, help='Enter Profile of scan 1-5 (Default: 1)', required=False)
parser.add_argument('--scan', metavar='scan', type=str, help='Enter scan type nmap, dns or sub.', required=False)
parser.add_argument('--list', metavar='list', type=str, help='The path to the subdomain list file (txt).', default='lists/default.txt', required=False)
parser.add_argument('--r', metavar='r', type=str, help='Shows a more clean help menu using rich only argument-input is help', default=help, required=False)
parser.add_argument('--menu', metavar='menu', type=bool, help='Terminal Interactive Menu', required=False, default=False)
parser.add_argument('--ai', metavar='ai', type=str, help='Choose your AI of choice', required=False, default='bard')
# Store the values of command-line arguments
args = parser.parse_args()
target = args.target
profile = args.profile
scan = args.scan
choice = args.r
list_loc = args.list
ai = args.ai
menu = args.menu
# Define a function to clear the screen based on the operating system
def clearscr() -> None:
os.system("cls" if os.name == "nt" else "clear")
# Define a function to display the help menu
def help_menu() -> None:
table = Table(title="Help Menu for BVA")
table.add_column("Options", style="cyan")
table.add_column("Input Type", style="green")
table.add_column("Argument Input", style="green")
table.add_column("Discription", style="green")
table.add_column("Other internal options", style="green")
table.add_row("scan", "--scan", "TXT/STRING",
"The scan the user whants to run", "sub / dns / nmap / geo")
table.add_row("Target", "--target", "IP/HOSTNAME",
"The target of the user", "None")
table.add_row("Domain List", "--list", "Path to text file",
"subdomain dictionary list", "Path")
table.add_row("Profile", "--profile", "INT (1-5)",
"The type of Nmap Scan the user intends", "None")
table.add_row("AI", "--ai", "STRING",
"Choose your AI of choice", "bard")
table.add_row("menu", "--menu", "BOOL",
"Descriptive UI menu", "True / False (Default)")
table.add_row("Rich Help", "--r", "STRING",
"Pretty Help menu", "help")
console.print(table)
# Define a function for the terminal interactive menu
def menu_term() -> None:
try:
table = Table()
table.add_column("Options", style="cyan")
table.add_column("Utility", style="green")
table.add_row("1", "Nmap Enum")
table.add_row("2", "DNS Enum")
table.add_row("3", "Subdomain Enum")
table.add_row("4", "GEO-IP Enum")
table.add_row("q", "Quit")
console.print(table)
option = input("Enter your choice: ")
match option:
case "1":
clearscr()
nmap_menu()
case "2":
clearscr()
dns_menu()
case "3":
clearscr()
sub_menu()
case "4":
clearscr()
geo_menu()
case "q":
quit()
except KeyboardInterrupt:
print(Panel("Exiting Program"))
# Define a function to flatten nested JSON data
def flatten_json(data: Any, separator: Any = '.') -> Any:
flattened_data = {}
for key, value in data.items():
if isinstance(value, dict):
nested_data = flatten_json(value, separator)
for nested_key, nested_value in nested_data.items():
flattened_data[key + separator + nested_key] = nested_value
else:
flattened_data[key] = value
return flattened_data
# Define a function for the Nmap menu
def nmap_menu() -> None:
try:
global keyset
global t
global profile_num
global ai_set
global bkey_set
table = Table()
table.add_column("Options", style="cyan")
table.add_column("Utility", style="green")
table.add_row("1", "AI Options")
table.add_row("2", "Set Target")
table.add_row("3", "Set Profile")
table.add_row("4", "Show options")
table.add_row("5", "Run scan")
table.add_row("r", "Return")
console.print(table)
option = input("Enter your choice: ")
match option:
case "1":
clearscr()
table0 = Table()
table0.add_column("Options", style="cyan")
table0.add_column("AI Available", style="green")
table0.add_row("1", "Bard")
print(Panel(table0))
ai_set_choice = input("Enter AI of Choice: ")
if ai_set_choice == "1":
ai_set = "bard"
bkey_set = input("Enter Bard AI API: ")
print(Panel(f"API-Key Set: {bkey_set}"))
nmap_menu()
case "2":
clearscr()
print(Panel("Set Target Hostname or IP"))
t = input("Enter Target: ")
print(Panel(f"Target Set: {t}"))
nmap_menu()
case "3":
clearscr()
table1 = Table()
table1.add_column("Options", style="cyan")
table1.add_column("Nmap command", style="green")
table1.add_column("Description", style="green")
table1.add_row("1", "Effective Scan", "-Pn -sV -T4 -O -F")
table1.add_row("2", "Simple Scan","-Pn -T4 -A -v")
table1.add_row("3", "Low Power Sacn", "-Pn -sS -sU -T4 -A -v")
table1.add_row("4", "Partial Intense Scan", "-Pn -p- -T4 -A -v")
table1.add_row("5", "complete Intense Scan", "-Pn -sS -sU -T4 -A -PE -PP -PY -g 53 --script=vuln")
print(Panel(table1))
profile_num = input("Enter your Profile: ")
print(Panel(f"Profile Set {profile_num}"))
nmap_menu()
case "4":
clearscr()
table2 = Table()
table2.add_column("Options", style="cyan")
table2.add_column("Value", style="green")
table2.add_row("Bard AI API Key", str(bkey_set))
table2.add_row("Target", str(t))
table2.add_row("Profile", str(profile_num))
print(Panel(table2))
nmap_menu()
case "5":
clearscr()
pout: str = p_scanner(t, int(profile_num), bkey_set, bkey_set, ai_set)
print_output("Nmap", pout, ai_set)
case "r":
clearscr()
menu_term()
except KeyboardInterrupt:
print(Panel("Exiting Program"))
# Define a function for the DNS menu
def dns_menu() -> None:
try:
global keyset
global t
global profile_num
global ai_set
global bkey_set
table = Table()
table.add_column("Options", style="cyan")
table.add_column("Utility", style="green")
table.add_row("1", "AI Option")
table.add_row("2", "Set Target")
table.add_row("3", "Show options")
table.add_row("4", "Run scan")
table.add_row("r", "Return")
console.print(table)
option = input("Enter your choice: ")
match option:
case "1":
clearscr()
table0 = Table()
table0.add_column("Options", style="cyan")
table0.add_column("AI Available", style="green")
table0.add_row("1", "Bard")
print(Panel(table0))
ai_set_choice = input("Enter AI of Choice: ")
if ai_set_choice == "1":
ai_set = "bard"
bkey_set = input("Enter Bard AI API: ")
print(Panel(f"API-Key Set: {bkey_set}"))
dns_menu()
case "2":
clearscr()
print(Panel("Set Target Hostname or IP"))
t = input("Enter Target: ")
print(Panel(f"Target Set:{t}"))
dns_menu()
case "3":
clearscr()
table1 = Table()
table1.add_column("Options", style="cyan")
table1.add_column("Value", style="green")
table1.add_row("Bard AI API Key", str(bkey_set))
table1.add_row("Target", str(t))
print(Panel(table1))
dns_menu()
case "4":
clearscr()
dns_output: str = dnsr(t, '''akey_set''', bkey_set, ai_set)
print_output("DNS", dns_output, ai_set)
case "r":
clearscr()
menu_term()
except KeyboardInterrupt:
print(Panel("Exiting Program"))
# Define a function for the Subdomain menu
def sub_menu() -> None:
try:
global list_loc
global t
global profile_num
table = Table()
table.add_column("Options", style="cyan")
table.add_column("Utility", style="green")
table.add_row("1", "ADD Subdomain list")
table.add_row("2", "Set Target")
table.add_row("3", "Show options")
table.add_row("4", "Run scan")
table.add_row("r", "Return")
console.print(table)
option = input("Enter your choice: ")
match option:
case "1":
clearscr()
print(Panel("Set TXT subdomain file location"))
list_loc = input("Enter List Location: ")
print(Panel(f"Location Set: {list_loc}"))
sub_menu()
case "2":
clearscr()
print(Panel("Set Target Hostname or IP"))
t = input("Enter Target: ")
print(Panel(f"Target Set: {t}"))
sub_menu()
case "3":
clearscr()
table1 = Table()
table1.add_column("Options", style="cyan")
table1.add_column("Value", style="green")
table1.add_row("Location", str(list_loc))
table1.add_row("Target", str(t))
print(Panel(table1))
sub_menu()
case "4":
clearscr()
sub_output: str = sub(t, list_loc)
console.print(sub_output, style="bold underline")
case "r":
clearscr()
menu_term()
except KeyboardInterrupt:
print(Panel("Exiting Program"))
# Define a function for the GEO-IP menu
def geo_menu() -> None:
try:
global keyset
global t
global profile_num
table = Table()
table.add_column("Options", style="cyan")
table.add_column("Utility", style="green")
table.add_row("1", "ADD API Key")
table.add_row("2", "Set Target")
table.add_row("3", "Show options")
table.add_row("4", "Run scan")
table.add_row("r", "Return")
console.print(table)
option = input("Enter your choice: ")
match option:
case "1":
clearscr()
keyset = input("Enter GEO-IP API: ")
print(Panel(f"GEOIP API Key Set: {keyset}"))
geo_menu()
case "2":
clearscr()
print(Panel("Set Target Hostname or IP"))
t = input("Enter Target: ")
print(Panel(f"Target Set: {t}"))
geo_menu()
case "3":
clearscr()
table1 = Table()
table1.add_column("Options", style="cyan")
table1.add_column("Value", style="green")
table1.add_row("API Key", str(keyset))
table1.add_row("Target", str(t))
print(Panel(table1))
geo_menu()
case "4":
clearscr()
geo_output: str = geoip(keyset, t)
GEOIP_to_table(str(geo_output))
case "r":
clearscr()
menu_term()
except KeyboardInterrupt:
print(Panel("Exiting Program"))
# Define a function to display GEO-IP scan results in a table
def GEOIP_to_table(json_data: str) -> Any:
data = json.loads(json_data)
table = Table(title="BVA Report for GeoIP", show_header=True, header_style="bold magenta")
table.add_column("Identifiers", style="cyan")
table.add_column("Data", style="green")
flattened_data: dict = flatten_json(data, separator='.')
for key, value in flattened_data.items():
value_str = str(value)
table.add_row(key, value_str)
console = Console()
console.print(table)
# Define a function to print scan output
def print_output(scan_type: str, jdata: str, ai: str) -> Any:
if ai == 'bard':
data = json.loads(jdata)
table = Table(title=f"BVA Report for {scan_type}", show_header=True, header_style="bold magenta")
table.add_column("Variables", style="cyan")
table.add_column("Results", style="green")
for key, value in data.items():
table.add_row(key, value)
console.print(table)
else:
print(Panel(jdata))
# Define the main function
def main(target: Any) -> None:
print("BVA Usage in progress...")
if target is not None:
pass
else:
target = '127.0.0.1'
try:
if choice == "help":
help_menu()
elif menu is True:
menu_term()
else:
match scan:
case 'geo':
geo_output: str = geoip(gkey, target)
GEOIP_to_table(str(geo_output))
case 'nmap':
match profile:
case 1:
p1_out: str = p_scanner(target, 1, bkey, ai)
print_output("Nmap", p1_out, ai)
case 2:
p2_out: str = p_scanner(target, 2, bkey, ai)
print_output("Nmap", p2_out, ai)
case 3:
p3_out: str = p_scanner(target, 3, bkey, ai)
print_output("Nmap", p3_out, ai)
case 4:
p4_out: str = p_scanner(target, 4, bkey, ai)
print_output("Nmap", p4_out, ai)
case 5:
p5_out: str = p_scanner(target, 5, bkey, ai)
print_output("Nmap", p5_out, ai)
case 'dns':
dns_output: str = dnsr(target, bkey, ai)
print_output("DNS", dns_output, ai)
case 'sub':
sub_output: str = sub(target, list_loc)
console.print(sub_output, style="bold underline")
except KeyboardInterrupt:
console.print_exception("Bye")
quit()
if __name__ == "__main__":
main(target)