Agent: Rename SSH credentials collector to match class name

This commit is contained in:
Ilija Lazoroski 2022-02-16 17:28:11 +01:00
parent 3d64d0d2e4
commit b1b0840aed
1 changed files with 11 additions and 11 deletions

View File

@ -2,37 +2,37 @@ import logging
from typing import Dict, Iterable, List
from infection_monkey.credential_collectors import (
Credentials,
ICredentialCollector,
SSHKeypair,
Username,
)
from infection_monkey.i_puppet.credential_collection import Credentials, ICredentialCollector
from infection_monkey.credential_collectors.ssh_collector import ssh_handler
logger = logging.getLogger(__name__)
class SSHCollector(ICredentialCollector):
class SSHCredentialCollector(ICredentialCollector):
"""
SSH keys and known hosts collection module
SSH keys credential collector
"""
def collect_credentials(self, _options=None) -> List[Credentials]:
logger.info("Started scanning for SSH credentials")
ssh_info = ssh_handler.get_ssh_info()
logger.info("Scanned for SSH credentials")
logger.info("Finished scanning for SSH credentials")
return SSHCollector._to_credentials(ssh_info)
return SSHCredentialCollector._to_credentials(ssh_info)
@staticmethod
def _to_credentials(ssh_info: Iterable[Dict]) -> List[Credentials]:
ssh_credentials = []
identities = []
secrets = []
for info in ssh_info:
credentials_obj = Credentials(identities=[], secrets=[])
if "name" in info and info["name"] != "":
credentials_obj.identities.append(Username(info["name"]))
identities.append(Username(info["name"]))
ssh_keypair = {}
for key in ["public_key", "private_key"]:
@ -40,9 +40,9 @@ class SSHCollector(ICredentialCollector):
ssh_keypair[key] = info[key]
if len(ssh_keypair):
credentials_obj.secrets.append(SSHKeypair(ssh_keypair))
secrets.append(SSHKeypair(ssh_keypair))
if credentials_obj.identities != [] or credentials_obj.secrets != []:
ssh_credentials.append(credentials_obj)
if identities != [] or secrets != []:
ssh_credentials.append(Credentials(identities, secrets))
return ssh_credentials