예제 #1
0
 def setUp(self):
     find.data_path_append('data/server')
     web_root = os.path.join(os.getcwd(), 'data', 'server', 'king_phisher')
     config = smoke_zephyr.configuration.Configuration(
         find.find_data_file('server_config.yml'))
     config.set('server.address.host', '127.0.0.1')
     config.set('server.address.port', 0)
     config.set('server.addresses', [])
     config.set('server.database', 'sqlite://')
     config.set(
         'server.geoip.database',
         os.environ.get('KING_PHISHER_TEST_GEOIP_DB',
                        './GeoLite2-City.mmdb'))
     config.set('server.web_root', web_root)
     config.set('server.rest_api.enabled', True)
     config.set('server.rest_api.token', rest_api.generate_token())
     self.config = config
     self.plugin_manager = plugins.ServerPluginManager(config)
     self.server = build.server_from_config(
         config,
         handler_klass=KingPhisherRequestHandlerTest,
         plugin_manager=self.plugin_manager)
     config.set('server.address.port',
                self.server.sub_servers[0].server_port)
     self.assertIsInstance(self.server, server.KingPhisherServer)
     self.server_thread = threading.Thread(target=self.server.serve_forever)
     self.server_thread.daemon = True
     self.server_thread.start()
     self.assertTrue(self.server_thread.is_alive())
     self.shutdown_requested = False
     self.rpc = client_rpc.KingPhisherRPCClient(
         ('localhost', self.config.get('server.address.port')))
     self.rpc.login(username='******', password='******')
예제 #2
0
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