Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api for running modules #360

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
fix_skip,
fix_filter_query,
msg_structure,
root_dir)
root_dir, get_running_modules_details)
from config import (
api_configuration,
user_configuration)
Expand Down Expand Up @@ -648,6 +648,46 @@ def all_module_names():
abort(500)


@app.route("/api/core/running/modules", methods=["GET"])
def all_running_module_details():
"""
Get the list of details of all running module details
---
responses:
'200':
description: Ok
examples:
application/json:
[
{
"Command":"\"/bin/sh -c 'service\u2026\"",
"CreatedAt":"2022-07-27 21:49:43 +0530 IST",
"ID":"b5760a5cc113",
"Image":"ohp_ftpserver_weak_password",
"LocalVolumes":"0",
"Mounts":"/host_mnt/User\u2026",
"Names":"ohp_ftpserver_weak_password",
"Networks":"ohp_internet",
"Ports":"0.0.0.0:21->21/tcp",
"RunningFor":"About an hour ago",
"Size":"3B (virtual 293MB)",
"State":"running",
"Status":"Up About an hour"
}
]
'500':
description: Internal Server Error
examples:
application/json: { "msg": "file/path not found!", "status": "error" }
"""
try:
return jsonify(
get_running_modules_details()
), 200
except Exception:
abort(500)


@app.route("/docs-configuration")
def spec():
"""
Expand Down
26 changes: 25 additions & 1 deletion api/utility.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import os

from core.get_modules import load_all_modules_docker_names


def msg_structure(status="", msg=""):
"""
Expand Down Expand Up @@ -232,3 +234,25 @@ def aggregate_function(data_connection, agr_query):
allowDiskUse=True
)
)


def get_running_modules_details():
"""
Get all running modules details
Returns:
list of details of running modules

"""
module_details = []
delimiter = "}"
data = os.popen("docker ps --format '{{json .}}'").read().replace("\n", "").split(delimiter)
if len(data) > 1 and data[-1] == "":
data = data[:-1]
else:
data = []
for str_module_data in data:
module_data = json.loads(str_module_data + delimiter)
if module_data["Names"] in load_all_modules_docker_names():
module_details.append(module_data)

return module_details
3 changes: 2 additions & 1 deletion core/compatible.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def check_for_requirements(start_api_server):
http_auth=api_config["api_database_http_auth"]
)
connection.indices.get_alias("*")
except Exception:
except Exception as e:
print(e)
exit_failure(messages["elasticsearch_not_found"])
# check if its honeypot server not api server
if not start_api_server:
Expand Down
27 changes: 27 additions & 0 deletions core/get_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,30 @@ def load_all_modules():
else:
warn(messages["module_not_available"].format(module_name))
return module_names


def load_all_modules_docker_names():
"""
load all available modules names

Returns:
an array of all module names used while creating docker containers
"""
module_names = []
module_basepath = os.path.dirname(inspect.getfile(modules))
path_pattern = module_basepath + '/*/*/__init__.py'

for module in glob(path_pattern):

module_dir = os.path.split(module)[0]
sub_module_name = os.path.split(module_dir)[1]
category_name = os.path.split(os.path.split(module_dir)[0])[1]
module_name = category_name + '/' + sub_module_name
dockerfile_path = os.path.join(module_dir, "Dockerfile")

if os.path.exists(dockerfile_path):
if module_name not in module_names:
module_names.append('ohp_' + category_name + 'server_' + sub_module_name)
else:
warn(messages["module_not_available"].format(module_name))
return module_names
7 changes: 6 additions & 1 deletion lib/messages/de_DE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ received_network_event: 'Empfangenes Netzwerkereignis, ip_dest:{0}, port_dest:{1
received_honeypot_credential_event: 'Empfangenes Honeypot-Anmeldedatenereignis, ip_dest:{0}, username:{1}, password:{2}, module_name:{3}, machine_name:{4}'
received_honeypot_file_change_event: 'Empfangenes Honeypot-Dateiänderungsereignis, file_path:{0}, status:{1}, module_name:{2}, module_name:{3}, machine_name:{3}'
received_honeypot_data_event: 'Empfangenes Honeypot-Datenereignis, ip_dest:{0}, module_name:{1}, machine_name:{2}, data:{3}'
received_network_traffic_file: 'Empfangene Netzwerkdatenverkehrsdatei:{0}, Datum:{1}. Einfügen in das Dateiarchiv'
received_network_traffic_file: 'Empfangene Netzwerkdatenverkehrsdatei:{0}, Datum:{1}. Einfügen in das Dateiarchiv'
running_module: Laufende Module
running_modules_message: Details zu laufenden Modulen (Netzwerkerfassungsprozess)
no_modules_running_message: Derzeit laufen keine Module
modules_api_error_message: Beim Laden laufender Module ist ein Fehler aufgetreten. Bitte versuchen Sie es später erneut.
export_module_heading: Export Running Module Details
5 changes: 5 additions & 0 deletions lib/messages/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ received_honeypot_credential_event: 'Received honeypot credential event, ip_dest
received_honeypot_file_change_event: 'Received honeypot file change event, file_path:{0}, status:{1}, module_name:{2}, module_name:{3}, machine_name:{3}'
received_honeypot_data_event: 'Received honeypot data event, ip_dest:{0}, module_name:{1}, machine_name:{2}, data:{3}'
received_network_traffic_file: 'Received network traffic file:{0}, date:{1}. Inserting it in the File Archive'
running_module: Running Modules
running_modules_message: Details of Running Modules (Network Capture Process)
no_modules_running_message: No modules are running currently
modules_api_error_message: There is some error while loading running modules. Please try again later.
export_module_heading: Export Running Module Details
7 changes: 6 additions & 1 deletion lib/messages/es_ES.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ received_network_event: 'Evento de red recibido, ip_dest: {0}, port_dest: {1}, i
received_honeypot_credential_event: 'Recibido evento de credencial de honeypot, ip_dest:{0}, username:{1}, password:{2}, module_name:{3}, machine_name:{4}'
received_honeypot_file_change_event: 'Recibido evento de cambio de archivo honeypot, file_path:{0}, status:{1}, module_name:{2}, module_name:{3}, machine_name:{3}'
received_honeypot_data_event: 'Recibido evento de datos de honeypot, ip_dest:{0}, module_name:{1}, machine_name:{2}, data:{3}'
received_network_traffic_file: 'Archivo de tráfico de red recibido: {0}, fecha: {1}. Insertarlo en el archivo de archivos'
received_network_traffic_file: 'Archivo de tráfico de red recibido: {0}, fecha: {1}. Insertarlo en el archivo de archivos'
running_module: Módulos en ejecución
running_modules_message: Detalles de los módulos en ejecución (proceso de captura de red)
no_modules_running_message: No hay módulos en ejecución actualmente
modules_api_error_message: Hay algún error al cargar módulos en ejecución. Por favor, inténtelo de nuevo más tarde.
export_module_heading: Exportar detalles del módulo en ejecución
7 changes: 6 additions & 1 deletion lib/messages/fr_FR.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ received_network_event: 'Événement réseau reçu, ip_dest:{0}, port_dest:{1},
received_honeypot_credential_event: "Événement d'identification Honeypot reçu, ip_dest:{0}, username:{1}, password:{2}, module_name:{3}, machine_name:{4}"
received_honeypot_file_change_event: 'Événement de changement de fichier Honeypot reçu, file_path:{0}, status:{1}, module_name:{2}, module_name:{3}, machine_name:{3}'
received_honeypot_data_event: 'Événement de données de pot de miel reçu, ip_dest:{0}, module_name:{1}, machine_name:{2}, data:{3}'
received_network_traffic_file: "Fichier de trafic réseau reçu :{0}, date :{1}. L'insérer dans l'archive de fichiers"
received_network_traffic_file: "Fichier de trafic réseau reçu :{0}, date :{1}. L'insérer dans l'archive de fichiers"
running_module: Modules en cours d'exécution
running_modules_message: Détails des modules en cours d'exécution (processus de capture réseau)
no_modules_running_message: Aucun module n'est en cours d'exécution actuellement
modules_api_error_message: Il y a une erreur lors du chargement des modules en cours d'exécution. Veuillez réessayer plus tard.
export_module_heading: Exporter les détails du module en cours d'exécution
7 changes: 6 additions & 1 deletion lib/messages/ru_RU.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,9 @@ received_network_event: 'Получено сетевое событие, ip_dest
received_honeypot_credential_event: 'Получено событие учетных данных Honeypot, ip_dest:{0}, username:{1}, password:{2}, module_name:{3}, machine_name:{4}'
received_honeypot_file_change_event: 'Получено событие изменения файла Honeypot, file_path:{0}, status:{1}, module_name:{2}, module_name:{3}, machine_name:{3}'
received_honeypot_data_event: 'Получено событие данных HoneyPot, ip_dest:{0}, module_name:{1}, machine_name:{2}, data:{3}'
received_network_traffic_file: 'Получен файл сетевого трафика: {0}, дата: {1}. Вставка в файловый архив'
received_network_traffic_file: 'Получен файл сетевого трафика: {0}, дата: {1}. Вставка в файловый архив'
running_module: Запуск модулей
running_modules_message: Сведения о запущенных модулях (процесс захвата сети)
no_modules_running_message: В настоящее время ни один модуль не запущен
modules_api_error_message: Произошла ошибка при загрузке запущенных модулей. Пожалуйста, попробуйте позже.
export_module_heading: Экспорт сведений о работающем модуле
9 changes: 8 additions & 1 deletion web/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ body {
float: center;
}

#error-message-element{
#error-message-element, #error-message-element-modules {
text-align: center;
max-width: 80%;
margin: 0 auto;
Expand Down Expand Up @@ -201,4 +201,11 @@ blink {

.button:hover {
transform: scale(1.05);
}

table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
Binary file added web/static/img/csv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/static/img/excel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/static/img/json.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/static/img/pdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 67 additions & 24 deletions web/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<script src="/js/bootstrap.min.js"></script>
<!-- main.js used as general js file for index.html -->
<script src="/js/main.js"></script>
<script src="/js/modules.js"></script>
<script src="/js/explore.js"></script>
<script src="/js/xlsx.full.min.js"></script>
<!-- end of header header -->
Expand All @@ -44,6 +45,10 @@
<label class="log-explorer-label btn btn-outline-info"
onclick="get_layout('log-explorer')">{{ data.explorer }}</label>
</li>
<li class="nav-item">
<label class="log-explorer-label btn btn-outline-primary"
onclick="get_layout('running-module-explorer')">{{ data.running_module }}</label>
</li>
</ul>
</nav>
<!-- start body -->
Expand Down Expand Up @@ -160,37 +165,75 @@
</div>
</form>
</div>
<div id="log-explorer-table" class="row" style="margin-left:100px; margin-right:100px;" hidden="true">
<div class="container">
<div class="card material-table">
<table id="datatable" class="table striped responsive" style="float:center">
</table>
</div>
</div>
</div>
</div>
</div>
<div id="running-module-explorer" hidden=true>
<div id="module-container">

<h1 style="text-align: center; font-size: 24px">{{ data.running_modules_message }}</h1>
<table id="running-module-details">

<div id="log-explorer-table" class="row" style="margin-left:100px; margin-right:100px;" hidden="true">
<div class="container">
<div class="card material-table">
<table id="datatable" class="table striped responsive" style="float:center">
</table>
</div>
<div class="alert alert-danger" id="error-message-element-modules" role="alert" hidden>

</div>
<h1 style="text-align: center; font-size: 24px; margin-top: 1rem"
id="export_module_heading">{{ data.export_module_heading }}</h1>
<div style="display: flex; justify-content: space-around; width: 100%">
<button class="button" onclick="download_module_report_as_pdf('module-container')"
id="download-module-report"
hidden><img
src="img/pdf.png" width="40" height="40"> Export
</button>
<button class="button" onclick="download_module_report_as_csv()"
id="download-module-report-csv"
hidden><img
src="img/csv.png" width="40" height="40"> Export
</button>

<button class="button" onclick="download_module_report_as_json('running-module-details')"
id="download-module-report-json"
hidden><img
src="img/json.png" width="40" height="40"> Export
</button>

<button class="button" onclick="download_module_report_as_excel('running-module-details')"
id="download-module-report-excel"
hidden><img
src="img/excel.jpg" width="40" height="40"> Export
</button>
</div>
</div>
</div>

<!-- end of analytics-->
<div class="align-content-center text-center">
<!-- footer -->
<!-- OWASP Logo -->
<a class="" href="/"><img am-TopLogo alt="SECUREVIEW" src="/img/owasp.png" class="img-responsive"></a><br>
<!-- Links -->
<a href="https://www.owasp.org">OWASP Honeypot</a> -
<a href="https://github.com/zdresearch/OWASP-Honeypot">GitHub</a>
<!-- end of footer -->
</div>

<script>
const translations = {{ encoded_data | safe}};
</script>
<!-- main.js used as general js file for index.html -->
<script src="/js/main.js"></script>
<script src="/js/explore.js"></script>
<br>
<!-- end of body -->
<!-- end of analytics-->
<div class="align-content-center text-center" id="footer">
<!-- footer -->
<!-- OWASP Logo -->
<a class="" href="/"><img am-TopLogo alt="SECUREVIEW" src="/img/owasp.png" class="img-responsive"></a><br>
<!-- Links -->
<a href="https://www.owasp.org">OWASP Honeypot</a> -
<a href="https://github.com/zdresearch/OWASP-Honeypot">GitHub</a>
<!-- end of footer -->
</div>

<script>
const translations = {{ encoded_data | safe}};
</script>
<!-- main.js used as general js file for index.html -->
<script src="/js/main.js"></script>
<script src="/js/explore.js"></script>
<br>
<!-- end of body -->
</div>
</body>

</html>
17 changes: 17 additions & 0 deletions web/static/js/explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,22 @@ function displayErrorMessage(message) {
errorMessageElement.hidden = false;
}

/**
* Function is called when there is an error in Modules Display
* @param message error message that is to be displayed
*/
function displayErrorMessageForModules(message, html_element_id) {
const errorMessageElement = document.getElementById("error-message-element-modules");
document.getElementById("download-module-report").hidden = true;
document.getElementById("download-module-report-csv").hidden = true;
document.getElementById("download-module-report-json").hidden = true;
document.getElementById("download-module-report-excel").hidden = true;
document.getElementById("export_module_heading").hidden = true;
document.getElementById(html_element_id).hidden = true;
errorMessageElement.innerText = message;
errorMessageElement.hidden = false;
}

/**
* Form update based on event type selected
*/
Expand All @@ -674,6 +690,7 @@ function get_layout(layout_type) {
document.getElementById("dashboard").hidden = (layout_type !== "dashboard");
document.getElementById("log-explorer").hidden = (layout_type !== "log-explorer");
document.getElementById("log-explorer-table").hidden = (layout_type !== "log-explorer");
document.getElementById("running-module-explorer").hidden = (layout_type !== "running-module-explorer");
}

load_module_options();
Loading