Пример #1
0
def update_language(argv_options):
    """
    Update language for messages

    Args:
        argv_options
    """
    if argv_options.language not in load_messages().languages_list:
        exit_failure("Invalid language code. Available options are " +
                     ", ".join(load_messages().languages_list))
Пример #2
0
 def test_language_code(self):
     language_list = load_messages().languages_list
     self.assertIn("en_US", language_list)
     self.assertIn("es_ES", language_list)
     self.assertIn("ru_RU", language_list)
     self.assertIn("fr_FR", language_list)
     self.assertIn("de_DE", language_list)
Пример #3
0
def terminate_thread(thread, verbose=True):
    """
    kill a thread https://stackoverflow.com/a/15274929

    Args:
        thread: an alive thread
        verbose: verbose mode/boolean

    Returns:
        True/None
    """
    from core.messages import load_messages
    from core.alert import info
    messages = load_messages().message_contents
    if verbose:
        info(messages["killing_thread"].format(thread.name))
    if not thread.is_alive():
        return

    exc = ctypes.py_object(SystemExit)
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(
        ctypes.c_long(thread.ident), exc)
    if res == 0:
        raise ValueError("nonexistent thread id")
    elif res > 1:
        # if it returns a number greater than one, you're in trouble,
        # and you should call it again with exc=NULL to revert the effect
        ctypes.pythonapi.PyThreadState_SetAsyncExc(thread.ident, None)
        raise SystemError("PyThreadState_SetAsyncExc failed")
    return True
Пример #4
0
def index():
    """
    index page for WebUI

    Returns:
        rendered HTML page
    """
    data = load_messages().message_contents
    return render_template("index.html", data=data, encoded_data=data)
Пример #5
0
def check_for_requirements(start_api_server):
    """
    check if requirements exist

    Returns:
        True if exist otherwise False
    """
    # TODO : Fix the cyclic dependency later
    from config import api_configuration
    from core.messages import load_messages
    messages = load_messages().message_contents
    # check external required modules
    api_config = api_configuration()
    external_modules = open(os.path.join(os.getcwd(), 'requirements.txt'),
                            'r').read().split('\n')
    for module_name in external_modules:
        try:
            __import__(
                module_name.split('==')[0] if 'library_name=' not in
                module_name else module_name.split('library_name=')[1].split(
                )[0])
        except Exception:
            exit_failure("pip3 install -r requirements.txt ---> " +
                         module_name + " not installed!")
    # check elasticsearch
    try:
        connection = elasticsearch.Elasticsearch(
            api_config["api_database"], http_auth=api_config["api_database"])
        connection.indices.get_alias("*")
    except Exception:
        exit_failure(messages["elasticsearch_not_found"])
    # check if its honeypot server not api server
    if not start_api_server:
        # check docker
        try:
            subprocess.check_output(["docker", "--help"],
                                    stderr=subprocess.PIPE)
        except Exception:
            exit_failure(messages["cannot_communicate_with_docker"])
        # check for commandline requirements
        commands = {
            'tshark': which('tshark'),
            'ps': which('ps'),
            'grep': which('grep'),
            'kill': which('kill')
        }
        for command in commands:
            if commands[command] is None:
                exit_failure(messages["install_tools"] +
                             "{0}".format(json.dumps(commands, indent=4)))
    return True
Пример #6
0
 def test_language_list(self):
     language_list = load_messages().languages_list
     languages = ["es_ES", "ru_RU", "en_US", "fr_FR", "de_DE"]
     self.assertCountEqual(language_list, languages)
Пример #7
0
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()
Пример #8
0
                             get_module_dir_path, is_verbose_mode, logo,
                             make_tmp_thread_dir, mkdir)
from core.exit_helper import exit_failure, exit_success, terminate_thread
from core.get_modules import (load_all_modules,
                              virtual_machine_name_to_container_name,
                              virtual_machine_names_to_container_names)
from core.network import network_traffic_capture
from database.connector import (push_events_queues_to_database,
                                push_events_to_database_from_thread,
                                create_indices)
from core.messages import load_messages

# tmp dirs
tmp_directories = []
processor_threads = []
messages = load_messages().message_contents


def all_existing_networks():
    """
    list of all existing networks

    Returns:
        an array with list of all existing networks name
    """
    return [
        network_name.rsplit()[1] for network_name in os.popen(
            "docker network ls").read().rsplit("\n")[1:-1]
    ]