From f0679ebb26ab1ca1757fd200b7298118c1586a39 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Tue, 22 Feb 2022 17:49:08 +0530 Subject: [PATCH] Agent: Move `pwd`'s import statement to avoid using try/except --- .../credential_collectors/ssh_collector/ssh_handler.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/monkey/infection_monkey/credential_collectors/ssh_collector/ssh_handler.py b/monkey/infection_monkey/credential_collectors/ssh_collector/ssh_handler.py index 2e799e0c4..98ca0df4a 100644 --- a/monkey/infection_monkey/credential_collectors/ssh_collector/ssh_handler.py +++ b/monkey/infection_monkey/credential_collectors/ssh_collector/ssh_handler.py @@ -1,11 +1,6 @@ import glob import logging import os - -try: # can't import on Windows - import pwd -except ModuleNotFoundError: - pass from typing import Dict, Iterable from common.utils.attack_utils import ScanStatus @@ -34,6 +29,8 @@ def get_ssh_info(telemetry_messenger: ITelemetryMessenger) -> Iterable[Dict]: def _get_home_dirs() -> Iterable[Dict]: + import pwd + root_dir = _get_ssh_struct("root", "") home_dirs = [ _get_ssh_struct(x.pw_name, x.pw_dir) for x in pwd.getpwall() if x.pw_dir.startswith("/home")