def main(): parser = argparse.ArgumentParser( description='King Phisher Signing-Key Generation Utility', conflict_handler='resolve') utilities.argp_add_args(parser) subparsers = parser.add_subparsers(dest='subcommand') subparsers.required = True parser_display = subparsers.add_parser('display') parser_display.set_defaults(action=action_display) parser_display.add_argument('file', default=os.getenv('KING_PHISHER_DEV_KEY'), nargs='?', help='the key file to display') parser_generate = subparsers.add_parser('generate') parser_generate.set_defaults(action=action_generate) parser_generate.add_argument('id', help='this key\'s identifier') parser_generate.add_argument('file', type=argparse.FileType('w'), help='the destination to write the key to') arguments = parser.parse_args() find.init_data_path() arguments.action(arguments)
def ex_load_config(config_file, validate_schema=True): """ Load the server configuration from the specified file. This function is meant to be called early on during a scripts execution and if any error occurs, details will be printed and the process will exit. :param str config_file: The path to the configuration file to load. :param bool validate_schema: Whether or not to validate the schema of the configuration. :return: The loaded server configuration. :rtype: :py:class:`.Configuration` """ try: config = Configuration.from_file(config_file) except Exception as error: color.print_error( 'an error occurred while parsing the server configuration file') if isinstance(error, yaml.error.YAMLError): problem = getattr(error, 'problem', 'unknown yaml error') if hasattr(error, 'problem_mark'): prob_lineno = error.problem_mark.line + 1 color.print_error("{0} - {1}:{2} {3}".format( error.__class__.__name__, config_file, prob_lineno, problem)) lines = open(config_file, 'rU').readlines() for lineno, line in enumerate( lines[max(prob_lineno - 3, 0):(prob_lineno + 2)], max(prob_lineno - 3, 0) + 1): color.print_error(" {0} {1: <3}: {2}".format( ('=>' if lineno == prob_lineno else ' '), lineno, line.rstrip())) else: color.print_error("{0} - {1}: {2}".format( error.__class__.__name__, config_file, problem)) color.print_error( 'fix the errors in the configuration file and restart the server') sys.exit(os.EX_CONFIG) # check the configuration for missing and incompatible options if validate_schema: find.init_data_path('server') config_schema = find.data_file( os.path.join('schemas', 'json', 'king-phisher.server.config.json')) if not config_schema: color.print_error( 'could not load server configuration schema data') sys.exit(os.EX_NOINPUT) schema_errors = config.schema_errors(config_schema) if schema_errors: color.print_error( 'the server configuration validation encountered the following errors:' ) for schema_error in schema_errors: color.print_error(" - {0} error: {1} ({2})".format( schema_error.validator, '.'.join(map(str, schema_error.path)), schema_error.message)) sys.exit(os.EX_CONFIG) return config
def main(): parser = argparse.ArgumentParser(description='King Phisher Server', conflict_handler='resolve') utilities.argp_add_args(parser) startup.argp_add_server(parser) arguments = parser.parse_args() # basic runtime checks if sys.version_info < (3, 4): color.print_error('the Python version is too old (minimum required is 3.4)') return 0 console_log_handler = utilities.configure_stream_logger(arguments.logger, arguments.loglvl) del parser if os.getuid(): color.print_error('the server must be started as root, configure the') color.print_error('\'server.setuid_username\' option in the config file to drop privileges') return os.EX_NOPERM # configure environment variables and load the config find.init_data_path('server') config = configuration.ex_load_config(arguments.config_file) if arguments.verify_config: color.print_good('configuration verification passed') color.print_good('all required settings are present') return os.EX_OK if config.has_option('server.data_path'): find.data_path_append(config.get('server.data_path')) if arguments.update_geoip_db: color.print_status('downloading a new geoip database') try: size = geoip.download_geolite2_city_db(config.get('server.geoip.database')) except errors.KingPhisherResourceError as error: color.print_error(error.message) return os.EX_UNAVAILABLE color.print_good("download complete, file size: {0}".format(strutils.bytes2human(size))) return os.EX_OK # setup logging based on the configuration if config.has_section('logging'): log_file = _ex_config_logging(arguments, config, console_log_handler) logger.debug("king phisher version: {0} python version: {1}.{2}.{3}".format(version.version, sys.version_info[0], sys.version_info[1], sys.version_info[2])) # initialize the plugin manager try: plugin_manager = plugins.ServerPluginManager(config) except errors.KingPhisherError as error: if isinstance(error, errors.KingPhisherPluginError): color.print_error("plugin error: {0} ({1})".format(error.plugin_name, error.message)) else: color.print_error(error.message) return os.EX_SOFTWARE status_code = build_and_run(arguments, config, plugin_manager, log_file) plugin_manager.shutdown() logging.shutdown() return status_code
def test_json_schema_directories(self): find.init_data_path() directory = find.data_directory(os.path.join('schemas', 'json')) self.assertIsNotNone(directory) for schema_file in os.listdir(directory): self.assertTrue(schema_file.endswith('.json')) schema_file = os.path.join(directory, schema_file) with open(schema_file, 'r') as file_h: schema_data = json.load(file_h) self.assertIsInstance(schema_data, dict) self.assertEqual(schema_data.get('$schema'), 'http://json-schema.org/draft-04/schema#') self.assertEqual(schema_data.get('id'), os.path.basename(schema_file)[:-5])
def main(): parser = argparse.ArgumentParser(description='King Phisher Client GUI', conflict_handler='resolve') utilities.argp_add_args(parser, default_root='KingPhisher') startup.argp_add_client(parser) arguments = parser.parse_args() # basic runtime checks if sys.version_info < (3, 4): color.print_error('the Python version is too old (minimum required is 3.4)') return 0 if Gtk.check_version(3, 14, 0): color.print_error('the GTK+ version is too old (minimum required is 3.14)') return 0 if sys.platform.startswith('linux') and not os.environ.get('DISPLAY'): color.print_error('no display was detected, this must be run with an interactive X session') return 0 config_file = arguments.config_file use_plugins = arguments.use_plugins use_style = arguments.use_style del arguments, parser logger = logging.getLogger('KingPhisher.Client.CLI') if sys.platform.startswith('linux') and not os.getuid(): logger.warning('it is not necessary to run the king phisher client as root') find.init_data_path('client') if not gui_utilities.which_glade(): color.print_error('unable to locate the glade ui data file') return 0 logger.debug("king phisher version: {0} python version: {1}.{2}.{3}".format(version.version, sys.version_info[0], sys.version_info[1], sys.version_info[2])) logger.debug("client running in process: {0} main tid: 0x{1:x}".format(os.getpid(), threading.current_thread().ident)) start_time = time.time() logger.debug('using ui data from glade file: ' + gui_utilities.which_glade()) try: app = application.KingPhisherClientApplication(config_file=config_file, use_plugins=use_plugins, use_style=use_style) except Exception as error: logger.critical("initialization error: {0} ({1})".format(error.__class__.__name__, getattr(error, 'message', 'n/a'))) color.print_error('failed to initialize the King Phisher client') return 0 logger.debug("client loaded in {0:.2f} seconds".format(time.time() - start_time)) GObject.threads_init() return app.run([])
def main(): parser = argparse.ArgumentParser(description='King Phisher Signing-Key Generation Utility', conflict_handler='resolve') utilities.argp_add_args(parser) subparsers = parser.add_subparsers(dest='subcommand') subparsers.required = True parser_display = subparsers.add_parser('display') parser_display.set_defaults(action=action_display) parser_display.add_argument('file', default=os.getenv('KING_PHISHER_DEV_KEY'), nargs='?', help='the key file to display') parser_generate = subparsers.add_parser('generate') parser_generate.set_defaults(action=action_generate) parser_generate.add_argument('id', help='this key\'s identifier') parser_generate.add_argument('file', type=argparse.FileType('w'), help='the destination to write the key to') arguments = parser.parse_args() find.init_data_path() arguments.action(arguments)
def ex_load_config(config_file, validate_schema=True): """ Load the server configuration from the specified file. This function is meant to be called early on during a scripts execution and if any error occurs, details will be printed and the process will exit. :param str config_file: The path to the configuration file to load. :param bool validate_schema: Whether or not to validate the schema of the configuration. :return: The loaded server configuration. :rtype: :py:class:`.Configuration` """ try: config = Configuration.from_file(config_file) except Exception as error: color.print_error('an error occurred while parsing the server configuration file') if isinstance(error, yaml.error.YAMLError): problem = getattr(error, 'problem', 'unknown yaml error') if hasattr(error, 'problem_mark'): prob_lineno = error.problem_mark.line + 1 color.print_error("{0} - {1}:{2} {3}".format(error.__class__.__name__, config_file, prob_lineno, problem)) lines = open(config_file, 'rU').readlines() for lineno, line in enumerate(lines[max(prob_lineno - 3, 0):(prob_lineno + 2)], max(prob_lineno - 3, 0) + 1): color.print_error(" {0} {1: <3}: {2}".format(('=>' if lineno == prob_lineno else ' '), lineno, line.rstrip())) else: color.print_error("{0} - {1}: {2}".format(error.__class__.__name__, config_file, problem)) color.print_error('fix the errors in the configuration file and restart the server') sys.exit(os.EX_CONFIG) # check the configuration for missing and incompatible options if validate_schema: find.init_data_path('server') config_schema = find.data_file(os.path.join('schemas', 'json', 'king-phisher.server.config.json')) if not config_schema: color.print_error('could not load server configuration schema data') sys.exit(os.EX_NOINPUT) schema_errors = config.schema_errors(config_schema) if schema_errors: color.print_error('the server configuration validation encountered the following errors:') for schema_error in schema_errors: color.print_error(" - {0} error: {1} ({2})".format(schema_error.validator, '.'.join(map(str, schema_error.path)), schema_error.message)) sys.exit(os.EX_CONFIG) return config
def setUp(self): find.init_data_path()
def main(): parser = argparse.ArgumentParser(prog='KingPhisher', description='King Phisher Client GUI', conflict_handler='resolve') utilities.argp_add_args(parser, default_root='KingPhisher') startup.argp_add_client(parser) arguments = parser.parse_args() # basic runtime checks if sys.version_info < (3, 4): color.print_error( 'the Python version is too old (minimum required is 3.4)') return 0 if Gtk.check_version(3, 14, 0): color.print_error( 'the GTK+ version is too old (minimum required is 3.14)') return 0 if sys.platform.startswith('linux') and not os.environ.get('DISPLAY'): color.print_error( 'no display was detected, this must be run with an interactive X session' ) return 0 config_file = arguments.config_file use_plugins = arguments.use_plugins use_style = arguments.use_style del arguments, parser logger = logging.getLogger('KingPhisher.Client.CLI') if sys.platform.startswith('linux') and not os.getuid(): logger.warning( 'it is not necessary to run the king phisher client as root') find.init_data_path('client') if not gui_utilities.which_glade(): color.print_error('unable to locate the glade ui data file') return 0 logger.debug( "king phisher version: {0} python version: {1}.{2}.{3}".format( version.version, sys.version_info[0], sys.version_info[1], sys.version_info[2])) logger.debug("client running in process: {0} main tid: 0x{1:x}".format( os.getpid(), threading.current_thread().ident)) start_time = time.time() logger.debug('using ui data from glade file: ' + gui_utilities.which_glade()) try: app = application.KingPhisherClientApplication(config_file=config_file, use_plugins=use_plugins, use_style=use_style) except Exception as error: logger.critical("initialization error: {0} ({1})".format( error.__class__.__name__, getattr(error, 'message', 'n/a'))) color.print_error('failed to initialize the King Phisher client') return 0 logger.debug("client loaded in {0:.2f} seconds".format(time.time() - start_time)) GObject.threads_init() return app.run([])
def setUp(self): find.init_data_path('server')