forked from RedSiege/EyeWitness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search.py
executable file
·62 lines (56 loc) · 1.95 KB
/
Search.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
#!/usr/bin/env python
import glob
import os
import sys
import webbrowser
from distutils.util import strtobool
from modules.db_manager import DB_Manager
from modules.reporting import search_report
def open_file_input(cli_parsed):
files = glob.glob(os.path.join(cli_parsed.d, 'search.html'))
if len(files) > 0:
print 'Would you like to open the report now? [Y/n]',
while True:
try:
response = raw_input().lower()
if response is "":
return True
else:
return strtobool(response)
except ValueError:
print "Please respond with y or n",
else:
print '[*] No report files found to open, perhaps no hosts were successful'
return False
if __name__ == "__main__":
if len(sys.argv) < 3:
print 'Search a previously completed EyeWitness scan (HTTP page title/source)\n'
print '[*] Usage: python Search.py <dbpath> <searchterm>'
print 'DBPath should point to the ew.db file in your EyeWitness output folder'
sys.exit()
db_path = sys.argv[1]
if not os.path.isfile(db_path):
print '[*] No valid db path provided'
sys.exit()
search_term = sys.argv[2]
dbm = DB_Manager(db_path)
dbm.open_connection()
results = dbm.search_for_term(search_term)
if len(results) == 0:
print 'No results found!'
sys.exit()
else:
print 'Found {0} Results!'.format(str(len(results)))
cli_parsed = dbm.get_options()
cli_parsed.results = 25
cli_parsed.d = os.path.dirname(db_path)
oldfiles = glob.glob(os.path.join(cli_parsed.d, "*search*.html"))
for f in oldfiles:
os.remove(f)
search_report(cli_parsed, results, search_term)
newfiles = glob.glob(os.path.join(cli_parsed.d, "search.html"))
if open_file_input(cli_parsed):
for f in newfiles:
webbrowser.open(f)
sys.exit()
sys.exit()