()
| 68 | |
| 69 | |
| 70 | def main(): |
| 71 | first_run_setup(nxc_logger) |
| 72 | args, version_info = gen_cli_args() |
| 73 | |
| 74 | # if these are the same, it might double log to file (two FileHandlers will be added) |
| 75 | # but this should never happen by accident |
| 76 | if config_log: |
| 77 | nxc_logger.add_file_log() |
| 78 | if hasattr(args, "log") and args.log: |
| 79 | nxc_logger.add_file_log(args.log) |
| 80 | |
| 81 | CODENAME, VERSION, COMMIT, DISTANCE = version_info |
| 82 | nxc_logger.debug(f"NXC VERSION: {VERSION} - {CODENAME} - {COMMIT} - {DISTANCE}") |
| 83 | nxc_logger.debug(f"PYTHON VERSION: {sys.version}") |
| 84 | nxc_logger.debug(f"RUNNING ON: {platform.system()} Release: {platform.release()}") |
| 85 | nxc_logger.debug(f"Passed args: {args}") |
| 86 | |
| 87 | # FROM HERE ON A PROTOCOL IS REQUIRED |
| 88 | if not args.protocol: |
| 89 | exit(1) |
| 90 | |
| 91 | if args.protocol == "ssh" and args.key_file and not args.password: |
| 92 | nxc_logger.fail("Password is required, even if a key file is used - if no passphrase for key, use `-p ''`") |
| 93 | exit(1) |
| 94 | |
| 95 | if args.use_kcache and not os.environ.get("KRB5CCNAME"): |
| 96 | nxc_logger.error("KRB5CCNAME environment variable is not set") |
| 97 | exit(1) |
| 98 | |
| 99 | targets = [] |
| 100 | |
| 101 | if hasattr(args, "cred_id") and args.cred_id: |
| 102 | for cred_id in args.cred_id: |
| 103 | if "-" in str(cred_id): |
| 104 | start_id, end_id = cred_id.split("-") |
| 105 | try: |
| 106 | for n in range(int(start_id), int(end_id) + 1): |
| 107 | args.cred_id.append(n) # noqa: B909 |
| 108 | args.cred_id.remove(cred_id) # noqa: B909 |
| 109 | except Exception as e: |
| 110 | nxc_logger.error(f"Error parsing database credential id: {e}") |
| 111 | exit(1) |
| 112 | |
| 113 | if hasattr(args, "target") and args.target: |
| 114 | for target in args.target: |
| 115 | try: |
| 116 | if exists(target) and os.path.isfile(target): |
| 117 | target_file_type = identify_target_file(target) |
| 118 | if target_file_type == "nmap": |
| 119 | targets.extend(parse_nmap_xml(target, args.protocol)) |
| 120 | elif target_file_type == "nessus": |
| 121 | targets.extend(parse_nessus_file(target, args.protocol)) |
| 122 | else: |
| 123 | with open(target) as target_file: |
| 124 | for target_entry in target_file: |
| 125 | targets.extend(parse_targets(target_entry.strip())) |
| 126 | else: |
| 127 | targets.extend(parse_targets(target)) |
no test coverage detected