Skip to content

Commit 828f44b

Browse files
authored
Merge pull request #63 from codingo/codingo-input-helper
Beginning of a proper input class
2 parents 09ae5b7 + 292aff2 commit 828f44b

File tree

4 files changed

+125
-25
lines changed

4 files changed

+125
-25
lines changed

lib/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
3+
pass
4+

lib/core/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
3+
pass
4+

lib/core/input.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
from argparse import ArgumentParser
2+
import os.path
3+
4+
class cli_helper(object):
5+
@staticmethod
6+
def readable_file(parser, arg):
7+
if not os.path.exists(arg):
8+
parser.error("The file %s does not exist!" % arg)
9+
else:
10+
return open(arg, 'r') # return an open file handle
11+
12+
13+
class cli_argument_parser(object):
14+
def __init__(self):
15+
self._parser = self.setup_parser()
16+
17+
def parse(self, argv):
18+
return self._parser.parse_args(argv)
19+
20+
@staticmethod
21+
def setup_parser():
22+
parser = ArgumentParser()
23+
24+
parser.add_argument("-t",
25+
dest="target_hosts",
26+
required=True,
27+
help="Set a target range of addresses to target. Ex 10.11.1.1-255")
28+
29+
parser.add_argument("-o",
30+
dest="output_directory",
31+
required=True,
32+
help="Set the output directory. Ex /root/Documents/labs/")
33+
34+
parser.add_argument("-w",
35+
dest="wordlist",
36+
required=False,
37+
help="Set the wordlist to use for generated commands. Ex /usr/share/wordlist.txt",
38+
default=False)
39+
40+
parser.add_argument("-p",
41+
dest="port",
42+
required=False,
43+
help="Set the port to use. Leave blank to use discovered ports. Useful to force virtual host scanning on non-standard webserver ports.",
44+
default=80)
45+
46+
parser.add_argument("--pingsweep",
47+
dest="ping_sweep",
48+
action="store_true",
49+
help="Write a new target.txt by performing a ping sweep and discovering live hosts.",
50+
default=False)
51+
52+
parser.add_argument("--dns","--dnssweep",
53+
dest="find_dns_servers",
54+
action="store_true",
55+
help="Find DNS servers from a list of targets.",
56+
default=False)
57+
58+
parser.add_argument("--services",
59+
dest="perform_service_scan",
60+
action="store_true",
61+
help="Perform service scan over targets.",
62+
default=False)
63+
64+
parser.add_argument("--hostnames",
65+
dest="hostname_scan",
66+
action="store_true",
67+
help="Attempt to discover target hostnames and write to 0-name.txt and hostnames.txt.",
68+
default=False)
69+
70+
parser.add_argument("--snmp",
71+
dest="perform_snmp_walk",
72+
action="store_true",
73+
help="Perform service scan over targets.",
74+
default=False)
75+
76+
parser.add_argument("--quick",
77+
dest="quick",
78+
action="store_true",
79+
required=False,
80+
help="Move to the next target after performing a quick scan and writing first-round recommendations.",
81+
default=False)
82+
83+
parser.add_argument("--virtualhosts",
84+
dest="virtualhosts",
85+
action="store_true",
86+
required=False,
87+
help="Attempt to discover virtual hosts using the specified wordlist.",
88+
default=False)
89+
90+
parser.add_argument('--ignore-http-codes',
91+
dest='ignore_http_codes',
92+
type=str,
93+
help='Comma separated list of http codes to ignore with virtual host scans.',
94+
default='404')
95+
96+
parser.add_argument('--ignore-content-length',
97+
dest='ignore_content_length',
98+
type=int,
99+
help='Ignore content lengths of specificed amount. This may become useful when a server returns a static page on every virtual host guess.',
100+
default=0)
101+
102+
parser.add_argument("--quiet",
103+
dest="quiet",
104+
action="store_true",
105+
help="Supress banner and headers to limit to comma dilimeted results only.",
106+
default=False)
107+
108+
parser.add_argument("--no-udp",
109+
dest="no_udp_service_scan",
110+
action="store_true",
111+
help="Disable UDP services scan over targets.",
112+
default=False)
113+
return parser
114+

reconnoitre.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from hostname_scan import hostname_scan
1010
from snmp_walk import snmp_walk
1111
from virtual_host_scanner import virtual_host_scanner
12+
from lib.core.input import cli_argument_parser, cli_helper
1213

1314

1415
def print_banner():
@@ -47,31 +48,8 @@ def util_checks(util = None):
4748
return "Found"
4849

4950
def main():
50-
parser = ArgumentParser()
51-
parser.add_argument("-t", dest="target_hosts", required=True, help="Set a target range of addresses to target. Ex 10.11.1.1-255" )
52-
parser.add_argument("-o", dest="output_directory", required=True, help="Set the output directory. Ex /root/Documents/labs/")
53-
parser.add_argument("-w", dest="wordlist", required=False, help="Set the wordlist to use for generated commands. Ex /usr/share/wordlist.txt", default=False)
54-
parser.add_argument("-p", dest="port", required=False, help="Set the port to use. Leave blank to use discovered ports. Useful to force virtual host scanning on non-standard webserver ports.", default=80)
55-
parser.add_argument("--pingsweep", dest="ping_sweep", action="store_true", help="Write a new target.txt by performing a ping sweep and discovering live hosts.", default=False)
56-
parser.add_argument("--dns","--dnssweep", dest="find_dns_servers", action="store_true", help="Find DNS servers from a list of targets.", default=False)
57-
parser.add_argument("--services", dest="perform_service_scan", action="store_true", help="Perform service scan over targets.", default=False)
58-
parser.add_argument("--hostnames", dest="hostname_scan", action="store_true", help="Attempt to discover target hostnames and write to 0-name.txt and hostnames.txt.", default=False)
59-
parser.add_argument("--snmp", dest="perform_snmp_walk", action="store_true", help="Perform service scan over targets.", default=False)
60-
parser.add_argument("--quick", dest="quick", action="store_true", required=False, help="Move to the next target after performing a quick scan and writing first-round recommendations.", default=False)
61-
62-
parser.add_argument("--virtualhosts", dest="virtualhosts", action="store_true", required=False, help="Attempt to discover virtual hosts using the specified wordlist.", default=False)
63-
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')
64-
parser.add_argument('--ignore-content-length', dest='ignore_content_length', type=int, help='Ignore content lengths of specificed amount. This may become useful when a server returns a static page on every virtual host guess.', default=0)
65-
66-
parser.add_argument("--quiet", dest="quiet", action="store_true", help="Supress banner and headers to limit to comma dilimeted results only.", default=False)
67-
parser.add_argument("--no-udp", dest="no_udp_service_scan", action="store_true", help="Disable UDP services scan over targets.", default=False)
68-
arguments = parser.parse_args()
69-
70-
if len(sys.argv) == 1:
71-
print_banner()
72-
parser.error("No arguments given.")
73-
parser.print_usage
74-
sys.exit()
51+
parser = cli_argument_parser()
52+
arguments = parser.parse(sys.argv[1:])
7553

7654
if arguments.output_directory.endswith('/' or '\\'):
7755
arguments.output_directory = arguments.output_directory[:-1]

0 commit comments

Comments
 (0)