def start_api_server(): """ start API server Returns: True """ # Starting the API my_api_configuration = api_configuration() write_to_api_console( " * API access key: {0}\n".format( my_api_configuration["api_access_key"] if not my_api_configuration["api_access_without_key"] else "NOT REQUIRED!" ) ) global app app.config["OWASP_HONEYPOT_CONFIG"] = { "api_access_key": my_api_configuration["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": my_api_configuration["api_access_without_key"], "language": "en" } app.run( host=my_api_configuration["api_host"], port=my_api_configuration["api_port"], debug=my_api_configuration["api_debug_mode"], threaded=True ) return True
def check_for_requirements(start_api_server): """ check if requirements exist Returns: True if exist otherwise False """ from core.alert import messages from config import api_configuration # check external required modules try: import pymongo import netaddr import flask del netaddr del flask except Exception as _: exit_failure("pip install -r requirements.txt") # check mongodb try: connection = pymongo.MongoClient( api_configuration()["api_database"], serverSelectionTimeoutMS=api_configuration() ["api_database_connection_timeout"]) connection.list_database_names() except Exception as _: exit_failure("cannot connect to mongodb") # 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 as _: exit_failure(messages("en", "docker_error")) # check tshark try: subprocess.check_output(["tshark", "--help"], stderr=subprocess.PIPE) except Exception as _: exit_failure("please install tshark first!") return True
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
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
from api.utility import struct_msg from flask import Flask, render_template, request, jsonify, render_template, redirect, url_for from config import api_configuration import datetime import vonage app = Flask(__name__, template_folder="../templates") api_config = api_configuration() app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' client = vonage.Client(key=api_config["vonage_key"], secret=api_config["vonage_secret"]) sms = vonage.Sms(client) Phno = None hours = 0 @app.errorhandler(400) def error_400(error): """ handle 400 error Args: error: the flask error Returns: 400 JSON error """ return jsonify(struct_msg(status="error", msg=error.description)), 400 @app.route("/", methods=["GET", "POST"]) def index(): return render_template("index.html")
#!/usr/bin/env python # -*- coding: utf-8 -*- import pymongo import os import inspect from core._time import now from config import api_configuration from lib.ip2location import IP2Location client = pymongo.MongoClient(api_configuration()["api_database"], serverSelectionTimeoutMS=api_configuration() ["api_database_connection_timeout"]) database = client[api_configuration()["api_database_name"]] honeypot_events = database.honeypot_events network_events = database.network_events IP2Location = IP2Location.IP2Location( os.path.join(os.path.dirname(inspect.getfile(IP2Location)), "IP2LOCATION-LITE-DB1.BIN")) def insert_selected_modules_network_event(ip, port, module_name): """ insert selected modules event to honeypot_events collection Args: ip: connected ip port: connected port module_name: module name ran on the port
#!/usr/bin/env python # -*- coding: utf-8 -*- import pymongo import os import inspect from core._time import now from config import api_configuration from lib.ip2location import IP2Location client = pymongo.MongoClient( api_configuration()["api_database"], serverSelectionTimeoutMS=api_configuration()["api_database_connection_timeout"] ) database = client[api_configuration()["api_database_name"]] honeypot_events = database.honeypot_events network_events = database.network_events IP2Location = IP2Location.IP2Location( os.path.join( os.path.dirname( inspect.getfile(IP2Location) ), "IP2LOCATION-LITE-DB1.BIN") ) # todo: write documentation about machine_name def insert_selected_modules_network_event(ip, port, module_name, machine_name): """