Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New module: AWS Credentials Finder #455

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions nxc/modules/aws-credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class NXCModule:
"""
Search for aws credentials files on linux and windows machines

Module by Fortress
"""

name = "aws-credentials"
description = "Search for aws credentials files."
supported_protocols = ["ssh", "smb", "winrm"]
opsec_safe = True
multiple_hosts = True

def __init__(self):
self.search_path_linux = "'/home/' '/tmp/'"
self.search_path_win = "'C:\\Users\\', 'C:\\ProgramData\\AWSCLI\\', 'C:\\Temp\\'"


def options(self, context, module_options):
r"""
SEARCH_PATH_LINUX Linux location where to search for aws credentials related files
Default: '/home/ - /tmp/'

SEARCH_PATH_WIN Windows locations where to search for aws credentials related files
Default: 'C:\\Users\\ - C:\\ProgramData\\AWSCLI\\ - C:\\Temp\\
"""
if "SEARCH_PATH_LINUX" in module_options:
self.search_path_linux = module_options["SEARCH_PATH_LINUX"]

if "SEARCH_PATH_WIN" in module_options:
self.search_path_win = module_options["SEARCH_PATH_WIN"]

def on_login(self, context, connection):
# search for aws_credentials-related files on linux systems
if "ssh" in context.protocol:
search_aws_creds_files_payload = f'find {self.search_path_linux} -type f -name credentials -o -name credentials.bk -o -name config.bk -o -name config'
search_aws_creds_files_cmd = f'/bin/bash -c "{search_aws_creds_files_payload}"'
search_aws_creds_files_output = connection.execute(search_aws_creds_files_cmd, True)
else:
# search for aws_credentials-related files on windows systems
search_aws_creds_files_payload_win = f"Get-ChildItem -Path {self.search_path_win} -Recurse -Force -Include ('credentials','credentials.bk','config','config.bk') -ErrorAction SilentlyContinue | Select FullName -ExpandProperty FullName"
search_aws_creds_files_cmd_win = f'powershell.exe "{search_aws_creds_files_payload_win}"'
search_aws_creds_files_output_win = connection.execute(search_aws_creds_files_cmd_win, True)