Skip to content

Commit f461aad

Browse files
authored
Merge pull request #12 from codingo/timk-base-host
Added -b and -r options to override host and port used in headers
2 parents 4e574fc + f2b4550 commit f461aad

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

VHostScan.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def print_banner():
10-
print("+-+-+-+-+-+-+-+-+-+ v. 0.1")
10+
print("+-+-+-+-+-+-+-+-+-+ v. 0.2")
1111
print("|V|H|o|s|t|S|c|a|n| Developed by @codingo_ & @__timk")
1212
print("+-+-+-+-+-+-+-+-+-+ https://github.com/codingo/VHostScan\n")
1313

@@ -16,8 +16,10 @@ def main():
1616
print_banner()
1717
parser = ArgumentParser()
1818
parser.add_argument("-t", dest="target_hosts", required=True, help="Set a target range of addresses to target. Ex 10.11.1.1-255" )
19+
parser.add_argument("-b", dest="base_host", required=False, help="Set host to be used during substitution in wordlist (default to TARGET).", default=False)
1920
parser.add_argument("-w", dest="wordlist", required=False, type=str, help="Set the wordlist to use for generated commands. Ex /usr/share/wordlist.txt", default="./wordlists/virtual-host-scanning.txt")
2021
parser.add_argument("-p", dest="port", required=False, help="Set the port to use (default 80).", default=80)
22+
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)
2123

2224
parser.add_argument('--ignore-http-codes', dest='ignore_http_codes', type=str, help='Comma separated list of http codes to ignore with virtual host scans (default 404).', default='404')
2325
parser.add_argument('--ignore-content-length', dest='ignore_content_length', type=int, help='Ignore content lengths of specificed amount.', default=0)
@@ -39,7 +41,7 @@ def main():
3941
if(arguments.ignore_content_length > 0):
4042
print("[>] Ignoring Content length: %s" % (arguments.ignore_content_length))
4143

42-
scanner = virtual_host_scanner(arguments.target_hosts, arguments.port, arguments.ssl, arguments.unique_depth,
44+
scanner = virtual_host_scanner(arguments.target_hosts, arguments.base_host, arguments.port, arguments.real_port, arguments.ssl, arguments.unique_depth,
4345
arguments.ignore_http_codes, arguments.ignore_content_length, arguments.wordlist)
4446

4547
scanner.scan()
@@ -48,4 +50,4 @@ def main():
4850
for p in scanner.likely_matches(): print(" [>] %s" % p)
4951

5052
if __name__ == "__main__":
51-
main()
53+
main()

lib/core/virtual_host_scanner.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ class virtual_host_scanner(object):
1717
output: folder to write output file to
1818
"""
1919

20-
def __init__(self, target, port=80, ssl=False, unique_depth=1, ignore_http_codes='404', ignore_content_length=0,
20+
def __init__(self, target, base_host, port=80, real_port=80, ssl=False, unique_depth=1, ignore_http_codes='404', ignore_content_length=0,
2121
wordlist="./wordlists/virtual-host-scanning.txt"):
2222
self.target = target
23-
self.port = port
23+
self.base_host = base_host
24+
self.port = int(port)
25+
self.real_port = int(real_port)
2426
self.ignore_http_codes = list(map(int, ignore_http_codes.replace(' ', '').split(',')))
2527
self.ignore_content_length = ignore_content_length
2628
self.wordlist = wordlist
@@ -34,11 +36,17 @@ def __init__(self, target, port=80, ssl=False, unique_depth=1, ignore_http_codes
3436
def scan(self):
3537
virtual_host_list = open(self.wordlist).read().splitlines()
3638

39+
if not self.base_host:
40+
self.base_host = self.target
41+
42+
if not self.real_port:
43+
self.real_port = self.port
44+
3745
for virtual_host in virtual_host_list:
38-
hostname = virtual_host.replace('%s', self.target)
46+
hostname = virtual_host.replace('%s', self.base_host)
3947

4048
headers = {
41-
'Host': hostname if self.port == 80 else '{}:{}'.format(hostname, self.port),
49+
'Host': hostname if self.real_port == 80 else '{}:{}'.format(hostname, self.real_port),
4250
'Accept': '*/*'
4351
}
4452

@@ -87,4 +95,4 @@ def likely_matches(self):
8795
segmented_data = dataframe.groupby("val_col").filter(lambda x: len(x) <= self.unique_depth)
8896
matches = ((segmented_data["key_col"].values).tolist())
8997

90-
return matches
98+
return matches

0 commit comments

Comments
 (0)