From 4526dceb9f5f0adf8e7d31edf635e9d39102a5e2 Mon Sep 17 00:00:00 2001 From: "Michael J. Rodriguez" <120982002+mjrodri@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:52:14 -0700 Subject: [PATCH 1/2] Add files via upload --- SecurityAuditScript-Update.py | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 SecurityAuditScript-Update.py diff --git a/SecurityAuditScript-Update.py b/SecurityAuditScript-Update.py new file mode 100644 index 0000000..c22cb1a --- /dev/null +++ b/SecurityAuditScript-Update.py @@ -0,0 +1,96 @@ +import os +import subprocess +import winapps + +# Constants for commands +POWERSHELL_COMMANDS = { + 'NUCMD': 'net user', + 'AdminCMD': 'net localgroup administrators', + 'RDPCMD': 'get-service "remote desktop services" | select Displayname,Status,ServiceName,Can*', + 'AVCMD': 'Get-MpComputerStatus', + 'SinfoCMD': 'systeminfo', + 'FWCMD': 'netsh advfirewall show Publicprofile', + 'FWCMD2': 'netsh advfirewall show privateprofile', + 'IPCMD': 'ipconfig /all', + 'BLCMD': 'manage-bde -status', + 'SRVCMD': """Get-Service | Select StartType, Status, Name, DisplayName | Where-Object {$_.Status -eq 'Running'} | Format-Table -AutoSize""" +} + +# Output file +outputfile = 'output.txt' + +# Labels and formats +LABEL_FORMAT = '===============================================================================\n ############## {} ##############\n===============================================================================\n' +CMD_BREAK = '-------------------------------------------------------------------------------\n' + +# Label variables +AV_NAME = 'AV Example' # Change the variable to your AV name +VPN_NAME = 'VPN Example' # Change the variable to your VPN name +SECTION_LABELS = { + 'Users': 'Users', + 'RDP': 'Remote Connections', + 'Anydesk': 'Anydesk', + 'TV': 'Team Viewer', + 'AV': 'Anti Virus Status', + 'FW': 'Firewall Status', + 'Sinfo': 'System Info', + 'IP': 'IP Config', + 'BL': 'Bit Locker', + 'SRV': 'Services', + 'SFT': 'Software' +} + + +def format_label(variable): + return LABEL_FORMAT.format(variable) + + +def write_to_file(text): + with open(outputfile, 'a') as f: + f.write(text + '\n') + + +def run_powershell_command(command): + try: + result = subprocess.run(['powershell.exe', command], shell=True, capture_output=True, text=True, check=True) + write_to_file(result.stdout) + except subprocess.CalledProcessError as e: + write_to_file(f"Error running command: {command}\n{e.stderr}") + + +def search_and_write(name): + apps = list(winapps.search_installed(name)) + if apps: + write_to_file(f"\n{name} is installed\n") + else: + write_to_file(f"\n-----------------------------------\n|!!!!! {name} not found !!!!!|\n-----------------------------------\n") + + +def installed_software(): + try: + output = subprocess.run(["powershell.exe", "-Command", 'wmic product get name'], shell=True, capture_output=True, text=True, check=True) + lines = output.stdout.split("\n") + for line in lines: + if line.strip(): + write_to_file(line + "\n") + except subprocess.CalledProcessError as e: + write_to_file(f"Error getting installed software:\n{e.stderr}") + + +def main(): + write_to_file(format_label("AV&VPN")) + search_and_write(AV_NAME) + search_and_write(VPN_NAME) + + for section, label in SECTION_LABELS.items(): + write_to_file(format_label(label)) + if section in POWERSHELL_COMMANDS: + run_powershell_command(POWERSHELL_COMMANDS[section]) + elif section == 'SFT': + installed_software() + write_to_file(CMD_BREAK) + + +if __name__ == "__main__": + main() + os.startfile(outputfile) \ No newline at end of file From 03150d81481836d3f9c74071e75b67bd7d484574 Mon Sep 17 00:00:00 2001 From: "Michael J. Rodriguez" <120982002+mjrodri@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:57:53 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 140eb79..959e94c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,31 @@ +# Overview +This project aims to improve a Python script for system information gathering and reporting. The script collects various system details, such as user information, installed software, antivirus status, firewall status, etc., and outputs them to a text file. + +# Features +Consolidation of PowerShell commands into a dictionary for better manageability. +Adoption of consistent snake_case naming convention for variables. +Use of F-strings for cleaner string formatting. +Addition of error handling mechanisms for subprocess and file operations, enhancing script robustness. +Modularization of the code into reusable functions for improved readability and maintainability. +Inclusion of docstrings for function clarity and usage explanation. +Ensuring consistent code formatting, including indentation, for improved readability. + +# How to Use +Fork the repository. +Clone the forked repository to your local machine. +Make necessary changes or improvements to the script. +Commit your changes and push them to your fork. +Create a pull request to merge your changes into the original repository. +Once approved, your changes will be merged. + +# Contributors +Michael J. Rodriguez github.com/mjrodri +and +https://github.com/CesarIllustrious + +License +This project is licensed under the MIT License. + # SecurityAuditScript My security audit script that decreases time wasted on obtaining audit information and returns it into a textfile. It then opens the text file ready to be analysed. It was written and compiled in Python 3.10.5.