diff options
| author | user <user@node5.net> | 2024-03-21 23:05:08 +0100 |
|---|---|---|
| committer | user <user@node5.net> | 2024-03-21 23:05:08 +0100 |
| commit | 65302bf60206ea43213e7f2bc18adf15838cf3a2 (patch) | |
| tree | a2d7249460790c816aa71d595a8863f1f6281950 /log_ssh_passwords.py | |
initial commit, logs login attempts to DB
Diffstat (limited to 'log_ssh_passwords.py')
| -rw-r--r-- | log_ssh_passwords.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/log_ssh_passwords.py b/log_ssh_passwords.py new file mode 100644 index 0000000..dc972b8 --- /dev/null +++ b/log_ssh_passwords.py @@ -0,0 +1,52 @@ +import socket +import paramiko +import db_handler +import threading + + +class SSHServer(paramiko.ServerInterface): + def __init__(self, connection_id: int): + self.connection_id = connection_id + + def check_auth_password(self, username, password): + print(f"Username: {username}") + print(f"Password: {password}") + + db_handler.log_login_attempt(username, password, self.connection_id) + + return paramiko.AUTH_FAILED + + +def ssh_thread(client, address, port): + print(f'New connection from: {address}:{port}') + connection_id = db_handler.log_connection(address, port) + + # Create a new paramiko transport + transport = paramiko.Transport(client) + transport.add_server_key(host_key) + server = SSHServer(connection_id) + + # Start the server + transport.start_server(server=server) + + +# Create an SSH server +host_key = paramiko.RSAKey.from_private_key_file("id_rsa") # paramiko.RSAKey.generate(2048) +server = '' +port = 2200 + +# Start the server +server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) +server_socket.bind((server, port)) +server_socket.listen(100) + +print(f"[*] Listening for connections on {server}:{port}") + +while True: + try: + client, addr = server_socket.accept() + thread = threading.Thread(target=ssh_thread, args=(client, addr[0], addr[1])) + thread.start() + except: + pass |
