From df203a7a559084631079141d6fb31ec74c796296 Mon Sep 17 00:00:00 2001 From: "David J. Bianco" Date: Tue, 20 Aug 2024 14:44:30 -0400 Subject: [PATCH] Log both successful and failed login attempts --- ssh_server.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ssh_server.py b/ssh_server.py index 9611cf4..6ea480d 100644 --- a/ssh_server.py +++ b/ssh_server.py @@ -89,15 +89,31 @@ class MySSHServer(asyncssh.SSHServer): logger.info("SSH connection closed.") def begin_auth(self, username: str) -> bool: - # If the user's password is the empty string, no auth is required - return accounts.get(username) != '' + if accounts.get(username) != '': + logger.info(f"AUTH: User {username} attempting to authenticate.") + return True + else: + logger.info(f"AUTH: SUCCESS for user {username}.") + return False def password_auth_supported(self) -> bool: return True + def host_based_auth_supported(self) -> bool: + return False + def public_key_auth_supported(self) -> bool: + return False + def kbdinit_auth_supported(self) -> bool: + return False def validate_password(self, username: str, password: str) -> bool: pw = accounts.get(username, '*') - return ((pw != '*') and (password == pw)) + + if ((pw != '*') and (password == pw)): + logger.info(f"AUTH: SUCCESS for user {username}.") + return True + else: + logger.info(f"AUTH: FAILED for user {username}.") + return False async def start_server() -> None: await asyncssh.listen(