Skip to content

Commit 5bcbcd8

Browse files
author
Elijah Wilson
committed
support multiple word lists
1 parent 35b7059 commit 5bcbcd8

File tree

2 files changed

+57
-34
lines changed

2 files changed

+57
-34
lines changed

VHostScan.py

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from argparse import ArgumentParser
66
from lib.core.virtual_host_scanner import *
77
from lib.helpers.output_helper import *
8+
from lib.helpers.file_helper import get_combined_word_lists
89
from lib.core.__version__ import __version__
910

1011

@@ -18,7 +19,7 @@ def main():
1819
print_banner()
1920
parser = ArgumentParser()
2021
parser.add_argument("-t", dest="target_hosts", required=True, help="Set a target range of addresses to target. Ex 10.11.1.1-255" )
21-
parser.add_argument("-w", dest="wordlist", required=False, type=str, help="Set the wordlist to use (default ./wordlists/virtual-host-scanning.txt)", default=False)
22+
parser.add_argument("-w", dest="wordlists", required=False, type=str, help="Set the wordlists to use (default ./wordlists/virtual-host-scanning.txt)", default=False)
2223
parser.add_argument("-b", dest="base_host", required=False, help="Set host to be used during substitution in wordlist (default to TARGET).", default=False)
2324
parser.add_argument("-p", dest="port", required=False, help="Set the port to use (default 80).", default=80)
2425
parser.add_argument("-r", dest="real_port", required=False, help="The real port of the webserver to use in headers when not 80 (see RFC2616 14.23), useful when pivoting through ssh/nc etc (default to PORT).", default=False)
@@ -33,39 +34,32 @@ def main():
3334
parser.add_argument("-", dest="stdin", action="store_true", help="By passing a blank '-' you tell VHostScan to expect input from stdin (pipe).", default=False)
3435

3536
arguments = parser.parse_args()
36-
wordlist = list()
37-
38-
if(arguments.stdin and not arguments.wordlist):
37+
wordlist = []
38+
39+
word_list_types = []
40+
41+
default_wordlist = "./wordlists/virtual-host-scanning.txt" if not arguments.stdin else None
42+
43+
if arguments.stdin:
44+
word_list_types.append('stdin')
3945
wordlist.extend(list(line for line in sys.stdin.read().splitlines()))
40-
print("[+] Starting virtual host scan for %s using port %s and stdin data" % (arguments.target_hosts,
41-
str(arguments.port)))
42-
elif(arguments.stdin and arguments.wordlist):
43-
if not os.path.exists(arguments.wordlist):
44-
wordlist.extend(list(line for line in sys.stdin.read().splitlines()))
45-
print("[!] Wordlist %s doesn't exist and can't be appended to stdin." % arguments.wordlist)
46-
print("[+] Starting virtual host scan for %s using port %s and stdin data" % (arguments.target_hosts,
47-
str(arguments.port)))
48-
else:
49-
wordlist.extend(list(line for line in open(arguments.wordlist).read().splitlines()))
50-
print("[+] Starting virtual host scan for %s using port %s, stdin data, and wordlist %s" % (arguments.target_hosts,
51-
str(arguments.port),
52-
arguments.wordlist))
53-
else:
54-
if not arguments.wordlist:
55-
wordlist.extend(list(line for line in open("./wordlists/virtual-host-scanning.txt").read().splitlines()))
56-
print("[+] Starting virtual host scan for %s using port %s and wordlist %s" % ( arguments.target_hosts,
57-
str(arguments.port),
58-
"./wordlists/virtual-host-scanning.txt"))
59-
else:
60-
if not os.path.exists(arguments.wordlist):
61-
print("[!] Wordlist %s doesn't exist, unable to scan." % arguments.wordlist)
62-
sys.exit()
63-
else:
64-
wordlist.extend(list(line for line in open(arguments.wordlist).read().splitlines()))
65-
print("[+] Starting virtual host scan for %s using port %s and wordlist %s" % ( arguments.target_hosts,
66-
str(arguments.port),
67-
str(arguments.wordlist)))
68-
46+
47+
combined = get_combined_word_lists(arguments.wordlists or default_wordlist)
48+
word_list_types.append('wordlists: {}'.format(
49+
', '.join(combined['file_paths']),
50+
))
51+
wordlist.extend(combined['words'])
52+
53+
if len(wordlist) == 0:
54+
print("[!] No words found in provided wordlists, unable to scan.")
55+
sys.exit(1)
56+
57+
print("[+] Starting virtual host scan for {host} using port {port} and {inputs}".format(
58+
host=arguments.target_hosts,
59+
port=arguments.port,
60+
inputs=', '.join(word_list_types),
61+
))
62+
6963
if(arguments.ssl):
7064
print("[>] SSL flag set, sending all results over HTTPS")
7165

lib/helpers/file_helper.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,33 @@ def is_json(json_file):
2525

2626
def write_file(self, contents):
2727
with open(self.output_file, "w") as o:
28-
o.write(contents)
28+
o.write(contents)
29+
30+
31+
def parse_word_list_argument(argument):
32+
if not argument:
33+
return []
34+
35+
if ',' in argument:
36+
files = [arg.strip() for arg in argument.split(',')]
37+
else:
38+
files = [argument.strip()]
39+
40+
return [
41+
path for path in files
42+
if os.path.exists(path)
43+
]
44+
45+
46+
def get_combined_word_lists(argument):
47+
files = parse_word_list_argument(argument)
48+
words = []
49+
50+
for path in files:
51+
with open(path) as f:
52+
words.extend(f.read().splitlines())
53+
54+
return {
55+
'file_paths': files,
56+
'words': words,
57+
}

0 commit comments

Comments
 (0)