forked from p15670423/monkey
Agent: Move get_credentials() to credentials.py
This commit is contained in:
parent
a060313d09
commit
e6399de860
|
@ -19,8 +19,7 @@ from infection_monkey.exploit.powershell_utils.auth_options import (
|
|||
AuthOptions,
|
||||
get_auth_options,
|
||||
)
|
||||
from infection_monkey.exploit.powershell_utils.credential_generators import get_credentials
|
||||
from infection_monkey.exploit.powershell_utils.credentials import Credentials
|
||||
from infection_monkey.exploit.powershell_utils.credentials import Credentials, get_credentials
|
||||
from infection_monkey.exploit.powershell_utils.utils import (
|
||||
IClient,
|
||||
get_client_based_on_auth_options,
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
from itertools import product
|
||||
from typing import List
|
||||
|
||||
from infection_monkey.exploit.powershell_utils.credentials import Credentials
|
||||
|
||||
|
||||
def get_credentials(
|
||||
usernames: List[str], passwords: List[str], is_windows: bool
|
||||
) -> List[Credentials]:
|
||||
credentials = []
|
||||
credentials.extend(_get_empty_credentials(is_windows))
|
||||
credentials.extend(_get_username_only_credentials(usernames, is_windows))
|
||||
credentials.extend(_get_username_password_credentials(usernames, passwords))
|
||||
|
||||
return credentials
|
||||
|
||||
|
||||
def _get_empty_credentials(is_windows: bool) -> List[Credentials]:
|
||||
if is_windows:
|
||||
return [Credentials(username=None, password=None)]
|
||||
|
||||
return []
|
||||
|
||||
|
||||
def _get_username_only_credentials(usernames: List[str], is_windows: bool) -> List[Credentials]:
|
||||
credentials = [Credentials(username=username, password="") for username in usernames]
|
||||
|
||||
if is_windows:
|
||||
credentials.extend(
|
||||
[Credentials(username=username, password=None) for username in usernames]
|
||||
)
|
||||
|
||||
return credentials
|
||||
|
||||
|
||||
def _get_username_password_credentials(
|
||||
usernames: List[str], passwords: List[str]
|
||||
) -> List[Credentials]:
|
||||
username_password_pairs = product(usernames, passwords)
|
||||
|
||||
return [Credentials(credentials[0], credentials[1]) for credentials in username_password_pairs]
|
|
@ -1,8 +1,46 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import Union
|
||||
from itertools import product
|
||||
from typing import List, Union
|
||||
|
||||
|
||||
@dataclass
|
||||
class Credentials:
|
||||
username: Union[str, None]
|
||||
password: Union[str, None]
|
||||
|
||||
|
||||
def get_credentials(
|
||||
usernames: List[str], passwords: List[str], is_windows: bool
|
||||
) -> List[Credentials]:
|
||||
credentials = []
|
||||
credentials.extend(_get_empty_credentials(is_windows))
|
||||
credentials.extend(_get_username_only_credentials(usernames, is_windows))
|
||||
credentials.extend(_get_username_password_credentials(usernames, passwords))
|
||||
|
||||
return credentials
|
||||
|
||||
|
||||
def _get_empty_credentials(is_windows: bool) -> List[Credentials]:
|
||||
if is_windows:
|
||||
return [Credentials(username=None, password=None)]
|
||||
|
||||
return []
|
||||
|
||||
|
||||
def _get_username_only_credentials(usernames: List[str], is_windows: bool) -> List[Credentials]:
|
||||
credentials = [Credentials(username=username, password="") for username in usernames]
|
||||
|
||||
if is_windows:
|
||||
credentials.extend(
|
||||
[Credentials(username=username, password=None) for username in usernames]
|
||||
)
|
||||
|
||||
return credentials
|
||||
|
||||
|
||||
def _get_username_password_credentials(
|
||||
usernames: List[str], passwords: List[str]
|
||||
) -> List[Credentials]:
|
||||
username_password_pairs = product(usernames, passwords)
|
||||
|
||||
return [Credentials(credentials[0], credentials[1]) for credentials in username_password_pairs]
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from infection_monkey.exploit.powershell_utils.credential_generators import get_credentials
|
||||
from infection_monkey.exploit.powershell_utils.credentials import Credentials
|
||||
from infection_monkey.exploit.powershell_utils.credentials import Credentials, get_credentials
|
||||
|
||||
TEST_USERNAMES = ["user1", "user2"]
|
||||
TEST_PASSWORDS = ["p1", "p2"]
|
Loading…
Reference in New Issue