From cd7ff43f5929defb8df189fb31557edc43dfe1ed Mon Sep 17 00:00:00 2001 From: Omar Santos Date: Tue, 2 May 2023 23:47:09 -0400 Subject: [PATCH] Create sensitive_file_scanner.py --- .../sensitive_file_scanner.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 programming_and_scripting_for_cybersecurity/recon_scripts/finding_sensitive_files/sensitive_file_scanner.py diff --git a/programming_and_scripting_for_cybersecurity/recon_scripts/finding_sensitive_files/sensitive_file_scanner.py b/programming_and_scripting_for_cybersecurity/recon_scripts/finding_sensitive_files/sensitive_file_scanner.py new file mode 100644 index 0000000..1807079 --- /dev/null +++ b/programming_and_scripting_for_cybersecurity/recon_scripts/finding_sensitive_files/sensitive_file_scanner.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +""" +Script Name: sensitive_file_scanner.py +Author: Omar Santos +Version: 0.1 +Description: + This script scans a specified directory for sensitive files based on file extensions and patterns. + It is designed to be used on Linux systems. The script will output the paths of any matching + sensitive files found in the specified directory and its subdirectories. + +Dependencies/Prerequisites: + - Python 3.x + - No additional libraries are required. +""" + +import os +import sys +import fnmatch + +# List of sensitive file extensions and patterns to search for +sensitive_extensions = ['.key', '.pem', '.pgp', '.p12', '.pfx', '.csv'] +sensitive_patterns = ['*password*', '*secret*', '*private*', '*confidential*'] + +# Function to check if the file matches sensitive file patterns +def is_sensitive_file(file_name): + for pattern in sensitive_patterns: + if fnmatch.fnmatch(file_name, pattern): + return True + + _, file_extension = os.path.splitext(file_name) + if file_extension in sensitive_extensions: + return True + + return False + +# Function to scan for sensitive files in the specified directory +def scan_directory(directory): + for root, _, files in os.walk(directory): + for file in files: + if is_sensitive_file(file): + print(f"Sensitive file found: {os.path.join(root, file)}") + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python3 sensitive_file_scanner.py ") + sys.exit(1) + + search_directory = sys.argv[1] + + if not os.path.isdir(search_directory): + print(f"Error: {search_directory} is not a valid directory") + sys.exit(1) + + print(f"Scanning {search_directory} for sensitive files...") + scan_directory(search_directory)