mirror of
https://github.com/splunk/DECEIVE.git
synced 2025-07-02 00:57:26 -04:00
Compare commits
2 Commits
config-fil
...
multiplatf
Author | SHA1 | Date | |
---|---|---|---|
7be73a7dff | |||
788bd26845 |
@ -8,6 +8,7 @@ import threading
|
||||
import sys
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
from typing import Optional
|
||||
import logging
|
||||
import datetime
|
||||
@ -48,8 +49,18 @@ class MySSHServer(asyncssh.SSHServer):
|
||||
|
||||
def connection_made(self, conn: asyncssh.SSHServerConnection) -> None:
|
||||
# Get the source and destination IPs and ports
|
||||
(src_ip, src_port, _, _) = conn.get_extra_info('peername')
|
||||
(dst_ip, dst_port, _, _) = conn.get_extra_info('sockname')
|
||||
peername = conn.get_extra_info('peername')
|
||||
sockname = conn.get_extra_info('sockname')
|
||||
|
||||
if peername is not None:
|
||||
src_ip, src_port = peername[:2]
|
||||
else:
|
||||
src_ip, src_port = '-', '-'
|
||||
|
||||
if sockname is not None:
|
||||
dst_ip, dst_port = sockname[:2]
|
||||
else:
|
||||
dst_ip, dst_port = '-', '-'
|
||||
|
||||
# Store the connection details in thread-local storage
|
||||
thread_local.src_ip = src_ip
|
||||
@ -63,6 +74,7 @@ class MySSHServer(asyncssh.SSHServer):
|
||||
def connection_lost(self, exc: Optional[Exception]) -> None:
|
||||
if exc:
|
||||
logger.error('SSH connection error', extra={"error": str(exc)})
|
||||
traceback.print_exception(exc)
|
||||
else:
|
||||
logger.info("SSH connection closed")
|
||||
# Ensure session summary is called on connection loss if attributes are set
|
||||
@ -312,6 +324,7 @@ def get_prompts(prompt: Optional[str], prompt_file: Optional[str]) -> dict:
|
||||
|
||||
#### MAIN ####
|
||||
|
||||
try:
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(description='Start the SSH honeypot server.')
|
||||
parser.add_argument('-c', '--config', type=str, default='config.ini', help='Path to the configuration file')
|
||||
@ -399,3 +412,8 @@ asyncio.set_event_loop(loop)
|
||||
loop.run_until_complete(start_server())
|
||||
loop.run_forever()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}", file=sys.stderr)
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
|
Reference in New Issue
Block a user