def argv_parser(): """ parse ARGVs using argparse Returns: parser, parsed ARGVs """ # create parser parser = argparse.ArgumentParser(prog="OWASP Honeypot", add_help=False) # create menu engineOpt = parser.add_argument_group(messages("en", "engine"), messages("en", "engine_input")) # add select module options + list of available modules engineOpt.add_argument("-m", "--select-module", action="store", dest="selected_modules", default=user_configuration()["default_selected_modules"], help=messages("en", "select_module").format(load_all_modules() + ["all"])) # by default all modules are selected, in case users can exclude one or some (separated with comma) engineOpt.add_argument("-x", "--exclude-module", action="store", dest="excluded_modules", default=user_configuration()["default_excluded_modules"], help=messages("en", "exclude_module").format(load_all_modules())) # limit the virtual machine storage to avoid related abuse engineOpt.add_argument("-s", "--vm-storage-limit", action="store", dest="virtual_machine_storage_limit", type=float, default=docker_configuration()["virtual_machine_storage_limit"], help=messages("en", "vm_storage_limit")) # reset the containers once in a time to prevent being continues botnet zombie engineOpt.add_argument("-r", "--vm-reset-factory-time", action="store", dest="virtual_machine_container_reset_factory_time_seconds", type=int, default=docker_configuration()["virtual_machine_container_reset_factory_time_seconds"], help=messages("en", "vm_reset_factory_time")) # start api engineOpt.add_argument("--start-api-server", action="store_true", dest="start_api_server", default=False, help="start API server") # enable verbose mode (debug mode) engineOpt.add_argument("--verbose", action="store_true", dest="verbose_mode", default=False, help="enable verbose mode") # disable color CLI engineOpt.add_argument("--disable-colors", action="store_true", dest="disable_colors", default=False, help="disable colors in CLI") # test CI/ETC engineOpt.add_argument("--test", action="store_true", dest="run_as_test", default=False, help="run a test and exit") # help menu engineOpt.add_argument("-h", "--help", action="store_true", default=False, dest="show_help_menu", help=messages("en", "show_help_menu")) return parser, parser.parse_args()
def __init__(self): self.default_messages = yaml.safe_load( open("lib/messages/en_US.yaml", encoding="utf-8")) self.languages_list = [ language.split('.yaml')[0] for language in os.listdir("lib/messages") if ".yaml" in language ] if "--language" in sys.argv and sys.argv[sys.argv.index('--language') + 1] in self.languages_list: self.language = sys.argv[sys.argv.index('--language') + 1] elif user_configuration()['language'] in self.languages_list: self.language = user_configuration()['language'] else: self.language = "en_US" self.message_contents = yaml.safe_load( open("lib/messages/{language}.yaml".format(language=self.language), encoding="utf-8")) for message in self.default_messages: if message not in self.message_contents: self.message_contents[message] = self.default_messages[message]
def start_api_server(): """ start API server Returns: True """ # Starting the API my_api_configuration = api_configuration() api_access_key = my_api_configuration["api_access_key"] api_access_without_key = my_api_configuration["api_access_without_key"] write_to_api_console(" * API access key: {0}\n".format( api_access_key if not api_access_without_key else "NOT REQUIRED!")) app.config["OWASP_HONEYPOT_CONFIG"] = { "api_access_key": api_access_key, "api_client_white_list": my_api_configuration["api_client_white_list"]["enabled"], "api_client_white_list_ips": my_api_configuration["api_client_white_list"]["ips"], "api_access_log": my_api_configuration["api_access_log"]["enabled"], "api_access_log_filename": my_api_configuration["api_access_log"]["filename"], "api_access_without_key": api_access_without_key, **user_configuration() } app.register_blueprint(documentation_settings) try: app.run(host=my_api_configuration["api_host"], port=my_api_configuration["api_port"], debug=my_api_configuration["api_debug_mode"], threaded=True) except Exception as e: exit_failure(str(e)) return True
def argv_parser(): """ parse ARGVs using argparse Returns: parser, parsed ARGVs """ # create parser parser = argparse.ArgumentParser(prog="OWASP Honeypot", add_help=False) # create menu docker_config = docker_configuration() user_config = user_configuration() engineOpt = parser.add_argument_group("OHP Engine", "OHP Engine input options") # add select module options + list of available modules engineOpt.add_argument( "-m", "--select-module", action="store", dest="selected_modules", default=user_config["default_selected_modules"], help="select module(s) {0}".format(load_all_modules() + ["all"])) # by default all modules are selected, in case users can exclude one or # some (separated with comma) engineOpt.add_argument("-x", "--exclude-module", action="store", dest="excluded_modules", default=user_config["default_excluded_modules"], help="select modules(s) to exclude {0}".format( load_all_modules())) # limit the virtual machine storage to avoid related abuse engineOpt.add_argument( "-s", "--vm-storage-limit", action="store", dest="virtual_machine_storage_limit", type=float, default=docker_config["virtual_machine_storage_limit"], help="virtual machine storage limit") # reset the containers once in a time to prevent being continues botnet # zombie engineOpt.add_argument( "-r", "--vm-reset-factory-time", action="store", dest="virtual_machine_container_reset_factory_time_seconds", type=int, default=docker_config[ "virtual_machine_container_reset_factory_time_seconds"], help="virtual machine reset factory time") # start API engineOpt.add_argument("--start-api-server", action="store_true", dest="start_api_server", default=False, help="start API server") # Store Network captured files engineOpt.add_argument("--store-pcap", action="store_true", dest="store_pcap", default=False, help="store network traffic as pcap files") # Set Timeout value for splitting network captured files engineOpt.add_argument( "-t", "--split-pcap-file-timeout", type=int, dest="timeout_value", default=3600, help="timeout value used to split network captured files") # enable verbose mode (debug mode) engineOpt.add_argument("-v", "--verbose", action="store_true", dest="verbose_mode", default=False, help="enable verbose mode") # disable color CLI engineOpt.add_argument("--disable-colors", action="store_true", dest="disable_colors", default=False, help="disable colors in CLI") # set language engineOpt.add_argument("--language", type=str, dest="language", default="en_US", help="Set the default language. {languages}".format( languages=load_messages().languages_list)) # test CI/ETC engineOpt.add_argument("--test", action="store_true", dest="run_as_test", default=False, help="run a test and exit") # help menu engineOpt.add_argument("-h", "--help", action="store_true", default=False, dest="show_help_menu", help="print this help menu") return parser, parser.parse_args()
#!/usr/bin/env python # -*- coding: utf-8 -*- import logging from config import user_configuration from logging.handlers import RotatingFileHandler FORMATTER = logging.Formatter("%(asctime)s — %(name)s — " + "%(levelname)s — %(filename)s:%(lineno)d — " + "%(message)s") LOG_FILE = user_configuration()["events_log_file"] def get_file_handler(): """ Returns file handler for the log file """ file_handler = RotatingFileHandler(LOG_FILE) file_handler.setFormatter(FORMATTER) return file_handler def get_logger(logger_name): """ Creates the logger with the logger name and returns it Args: logger_name """ logger = logging.getLogger(logger_name) logger.setLevel(logging.DEBUG) # highest level