def main(): # Get the command line parser. parser = cmdline_parser() # Parse the command line options. try: args = sys.argv[1:] envcfg = getenv("GOLISMERO_SETTINGS") if envcfg: args = parser.convert_arg_line_to_args(envcfg) + args P = parser.parse_args(args) command = P.command.upper() if command in COMMANDS: P.command = command else: P.targets.insert(0, P.command) P.command = "SCAN" # Load the Orchestrator options. cmdParams = OrchestratorConfig() cmdParams.command = P.command if P.config: cmdParams.config_file = path.abspath(P.config) if not path.isfile(cmdParams.config_file): raise ValueError("File not found: %r" % cmdParams.config_file) if cmdParams.config_file: cmdParams.from_config_file(cmdParams.config_file, allow_profile = True) if P.profile: cmdParams.profile = P.profile cmdParams.profile_file = get_profile(cmdParams.profile) if cmdParams.profile_file: cmdParams.from_config_file(cmdParams.profile_file) cmdParams.from_object(P) cmdParams.plugin_load_overrides = P.plugin_load_overrides # Enable console colors if requested. Console.use_colors = cmdParams.color # Show the program banner. parser.must_show_banner = False if cmdParams.verbose: show_banner() # Load the target audit options. auditParams = AuditConfig() auditParams.profile = cmdParams.profile auditParams.profile_file = cmdParams.profile_file auditParams.config_file = cmdParams.config_file if auditParams.config_file: auditParams.from_config_file(auditParams.config_file) if auditParams.profile_file: auditParams.from_config_file(auditParams.profile_file) auditParams.from_object(P) auditParams.plugin_load_overrides = P.plugin_load_overrides # If importing is turned off, remove the list of imports. if P.disable_importing: auditParams.imports = [] # If reports are turned off, remove the list of reports. # Otherwise, if no reports are specified, default to screen report. if P.disable_reporting: auditParams.reports = [] elif not auditParams.reports and P.command in ("SCAN", "REPORT"): auditParams.reports = ["-"] if auditParams.only_vulns is None: auditParams.only_vulns = True # Show exceptions as command line parsing errors. except Exception, e: ##raise # XXX DEBUG parser.error(str(e))
def build_config_from_cmdline(): # Get the command line parser. parser = cmdline_parser() # Parse the command line options. try: args = sys.argv[1:] envcfg = getenv("GOLISMERO_SETTINGS") if envcfg: args = parser.convert_arg_line_to_args(envcfg) + args P, V = parser.parse_known_args(args) if P.targets: P.targets += V else: P.targets = V P.plugin_args = {} command = P.command.upper() if command in COMMANDS: P.command = command if command == "RESCAN": P.command = "SCAN" P.redo = True else: P.redo = False else: P.targets.insert(0, P.command) P.command = "SCAN" # Load the Orchestrator options. cmdParams = OrchestratorConfig() cmdParams.command = P.command if P.config: cmdParams.config_file = path.abspath(P.config) if not path.isfile(cmdParams.config_file): raise ValueError("File not found: %s" % cmdParams.config_file) if cmdParams.config_file: cmdParams.from_config_file(cmdParams.config_file, allow_profile=True) if P.user_config: cmdParams.user_config_file = path.abspath(P.user_config) if not path.isfile(cmdParams.user_config_file): raise ValueError("File not found: %s" % cmdParams.user_config_file) if cmdParams.user_config_file: cmdParams.from_config_file(cmdParams.user_config_file, allow_profile=True) if P.profile: cmdParams.profile = P.profile cmdParams.profile_file = get_profile(cmdParams.profile) if cmdParams.profile_file: cmdParams.from_config_file(cmdParams.profile_file) cmdParams.from_object(P) cmdParams.plugin_load_overrides = P.plugin_load_overrides # Enable console colors if requested. Console.use_colors = cmdParams.color # Show the program banner. parser.must_show_banner = False if cmdParams.verbose: show_banner() # Load the target audit options. auditParams = AuditConfig() auditParams.profile = cmdParams.profile auditParams.profile_file = cmdParams.profile_file auditParams.config_file = cmdParams.config_file auditParams.user_config_file = cmdParams.user_config_file if auditParams.config_file: auditParams.from_config_file(auditParams.config_file) if auditParams.user_config_file: auditParams.from_config_file(auditParams.user_config_file) if auditParams.profile_file: auditParams.from_config_file(auditParams.profile_file) auditParams.from_object(P) auditParams.plugin_load_overrides = P.plugin_load_overrides # If importing is turned off, remove the list of imports. # FIXME this should be done by argparse in argument order! if P.disable_importing: auditParams.imports = [] # If reports are turned off, remove the list of reports. # Otherwise, if no reports are specified, default to screen report. # FIXME this should be done by argparse in argument order! if P.disable_reporting: auditParams.reports = [] elif (not auditParams.reports and (P.command != "REPORT" or not auditParams.targets)): auditParams.reports = ["-"] if auditParams.only_vulns is None: auditParams.only_vulns = True # Show exceptions as command line parsing errors. except Exception, e: ##raise # XXX DEBUG parser.error("arguments error: %s" % str(e))
def main(): # Show the program banner. show_banner() # Get the command line parser. parser = cmdline_parser() # Parse the command line options. try: args = sys.argv[1:] envcfg = getenv("GOLISMERO_SETTINGS") if envcfg: args = parser.convert_arg_line_to_args(envcfg) + args P = parser.parse_args(args) # Load the Orchestrator options. cmdParams = OrchestratorConfig() if P.config: cmdParams.config_file = path.abspath(P.config) if not path.isfile(cmdParams.config_file): raise ValueError("File not found: %r" % cmdParams.config_file) if cmdParams.config_file: cmdParams.from_config_file(cmdParams.config_file, allow_profile = True) if P.profile: cmdParams.profile = P.profile cmdParams.profile_file = get_profile(cmdParams.profile) if cmdParams.profile_file: cmdParams.from_config_file(cmdParams.profile_file) cmdParams.from_object(P) cmdParams.plugin_load_overrides = P.plugin_load_overrides # Load the target audit options. auditParams = AuditConfig() auditParams.profile = cmdParams.profile auditParams.profile_file = cmdParams.profile_file auditParams.config_file = cmdParams.config_file if auditParams.config_file: auditParams.from_config_file(auditParams.config_file) if auditParams.profile_file: auditParams.from_config_file(auditParams.profile_file) auditParams.from_object(P) auditParams.plugin_load_overrides = P.plugin_load_overrides # If importing is turned off, remove the list of imports. if P.disable_importing: auditParams.imports = [] # If reports are turned off, remove the list of reports. # Otherwise, if no reports are specified, default to screen report. if P.disable_reporting: auditParams.reports = [] elif not auditParams.reports: auditParams.reports = ["-"] # If there are no targets but there's a database, # get the targets (scope) from the database. if not auditParams.targets and auditParams.audit_db: try: cfg = AuditDB.get_config_from_closed_database( auditParams.audit_db, auditParams.audit_name) if cfg: auditParams.targets = cfg.targets auditParams.include_subdomains = cfg.include_subdomains if cmdParams.verbose > 1: if auditParams.targets: print "Found the following targets in the database:" for t in auditParams.targets: print "--> " + t print except Exception: pass ##raise # XXX DEBUG # Show exceptions as command line parsing errors. except Exception, e: ##raise # XXX DEBUG parser.error(str(e))