codingo / VHostScan

A virtual host scanner that performs reverse lookups, can be used with pivot tools, detect catch-all scenarios, work around wildcards, aliases and dynamic default pages.
GNU General Public License v3.0
1.2k stars 231 forks source link

Encapsulate the argument parsing logic in a class #64

Closed diogoosorio closed 7 years ago

diogoosorio commented 7 years ago

This PR refactors the way the CLI argument parsing is done. It contains the argument definition and parsing logic within the cli_argument_parser class.

The rationale for doing this is threefold:

  1. Have the logic isolated enough so that it can be tested.
  2. In the near future, centralize how the CLI argument should be translated into a "scan request"
  3. Give the first steps into decoupling the CLI logic from the core module (i.e. be able to have a web-based UI for the virtual_host_scanner).

I'm striving for an API something like the following:

# argument parsing
args = CliArgumentParser().parse(argv[1:])
args.scanner.wordlist # yields an iterable datastructure with all the words, the parser holds the logic for how this list is built
args.scanner.ignore_http_codes # yields a list with all the to be ignored http status code
...

# scanning logic
logger = CliLogger(level=logging.DEBUG) # outputs to stdout/stderr
scanner = VHostScanner(logger=logger)
result = scanner.scan(**request) # instance of ScannerResult

# scanning result serialization
serialized_result = result.serialize(format=args.serializer.format) # instance of a ResultJsonSerializer/ResultPlainSerializer
serialized_result.save(file=args.serializer.destination) # flush the serialized result into a file
str(serialized_result) # the json/text serialized string

This is definitely an opinionated PR and as such I'm obviously 100% open to discussion.

codingo commented 7 years ago

@diogoosorio I agree. I had to make a few very minor changes due to an earlier PR but everything is now merged. Can definitely see this keeping a more manageable code base as we bring more features into the project - and agree with the API approach, makes a lot of sense.