Skip to content

Commit

Permalink
Merge pull request #23 from fkie-cad/hl7-config-fix
Browse files Browse the repository at this point in the history
hl7 server: config bug fix
  • Loading branch information
euwint authored Mar 20, 2024
2 parents 802164c + 329fc75 commit fbcde6e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion honeypots/base_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, **kwargs):
self.process = None
self.uuid = f"honeypotslogger_{self.__class__.__name__}_{str(uuid4())[:8]}"
self.config: dict = kwargs.get("config", {})
self.logs = setup_logger(self.__class__.__name__, self.uuid, self.config)
self.logs = setup_logger(self.NAME, self.uuid, self.config)
if self.config:
set_local_vars(self, self.config)
self.ip = kwargs.get("ip", None) or (hasattr(self, "ip") and self.ip) or "0.0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion honeypots/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def setup_logger(name: str, temp_name: str, config_data: dict, drop: bool = Fals
elif "terminal" in logs:
ret_logs_obj.addHandler(CustomHandler(temp_name, logs, custom_filter))
if "file" in logs:
server = name[1:].lower().replace("server", "")
server = name.replace("_", "").replace("server", "")
server_config = config_data.get("honeypots", {}).get(server, {})
logs_location = config_data.get("logs_location")
logs_path = Path(logs_location) if logs_location else Path(gettempdir()) / "logs"
Expand Down
12 changes: 11 additions & 1 deletion tests/test_hl7_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@
)

PORT = "52575"
LOG_FILE_NAME = "hl7.jsonl"
SERVER_CONFIG = {
"honeypots": {
"hl7": {
"log_file_name": LOG_FILE_NAME,
},
}
}


@pytest.mark.parametrize(
"server_logs",
[{"server": HL7Server, "port": PORT}],
[{"server": HL7Server, "port": PORT, "custom_config": SERVER_CONFIG}],
indirect=True,
)
def test_hl7_server(server_logs):
Expand All @@ -31,6 +39,8 @@ def test_hl7_server(server_logs):
connection.send(message.to_mllp().encode())
response = connection.recv(1024).decode()

log_file = [f.name for f in server_logs.iterdir()][0]
assert log_file == LOG_FILE_NAME
logs = load_logs_from_file(server_logs)

assert len(logs) == 2
Expand Down
4 changes: 4 additions & 0 deletions tests/test_http_proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

PORT = "58080"
PORT_2 = "58081"
LOG_FILE_NAME = "httpproxy.jsonl"
SERVER_CONFIG = {
"honeypots": {
"httpproxy": {
"options": ["capture_commands"],
"log_file_name": LOG_FILE_NAME,
},
}
}
Expand All @@ -37,6 +39,8 @@ def test_http_proxy_server(server_logs):
timeout=2,
)

log_file = [f.name for f in server_logs.iterdir()][0]
assert log_file == LOG_FILE_NAME
logs = load_logs_from_file(server_logs)

assert len(logs) == 2
Expand Down

0 comments on commit fbcde6e

Please sign in to comment.