From 0a73ca717cde163d07948abef95ce5fa3d27c941 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Thu, 15 Sep 2022 12:07:03 +0530 Subject: [PATCH] Agent: Fix some mypy issues in zerologon.py --- monkey/infection_monkey/exploit/zerologon.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/monkey/infection_monkey/exploit/zerologon.py b/monkey/infection_monkey/exploit/zerologon.py index 11f2e02fb..d9e48d5a0 100644 --- a/monkey/infection_monkey/exploit/zerologon.py +++ b/monkey/infection_monkey/exploit/zerologon.py @@ -132,6 +132,8 @@ class ZerologonExploiter(HostExploiter): except BaseException as e: logger.info(f"Unexpected error: {e}") + return None + def attempt_exploit(self, rpc_con: rpcrt.DCERPC_v5) -> object: request = nrpc.NetrServerPasswordSet2() ZerologonExploiter._set_up_request(request, self.dc_name) @@ -220,9 +222,9 @@ class ZerologonExploiter(HostExploiter): finally: if rpc_con: - rpc_con.disconnect() + rpc_con.disconnect() # type: ignore[attr-defined] - def get_all_user_creds(self) -> List[Tuple[str, Dict]]: + def get_all_user_creds(self) -> Optional[List[Tuple[str, Dict]]]: try: options = OptionsForSecretsdump( # format for DC account - "NetBIOSName$@0.0.0.0" @@ -237,7 +239,7 @@ class ZerologonExploiter(HostExploiter): self._extract_user_creds_from_secrets(dumped_secrets=dumped_secrets) - creds_to_use_for_getting_original_pwd_hashes = [] + creds_to_use_for_getting_original_pwd_hashes: List[Tuple[str, Dict]] = [] admin = "Administrator" for user in self._extracted_creds.keys(): if user == admin: # most likely to work so try this first @@ -304,16 +306,18 @@ class ZerologonExploiter(HostExploiter): self._publish_credentials_stolen_event(extracted_credentials) - def _publish_credentials_stolen_event(self, extracted_credentials: Sequence[Credentials]): + def _publish_credentials_stolen_event( + self, extracted_credentials: Sequence[Credentials] + ) -> None: credentials_stolen_event = CredentialsStolenEvent( tags=ZEROLOGON_EVENT_TAGS, stolen_credentials=extracted_credentials, ) self.event_queue.publish(credentials_stolen_event) - def get_original_pwd_nthash(self, username: str, user_pwd_hashes: List[str]) -> str: + def get_original_pwd_nthash(self, username: str, user_pwd_hashes: List[str]) -> Optional[str]: if not self.save_HKLM_keys_locally(username, user_pwd_hashes): - return + return None try: options = OptionsForSecretsdump( @@ -339,6 +343,8 @@ class ZerologonExploiter(HostExploiter): finally: self.remove_locally_saved_HKLM_keys() + return None + def save_HKLM_keys_locally(self, username: str, user_pwd_hashes: List[str]) -> bool: logger.info(f"Starting remote shell on victim with user: {username}")