Skip to content
Open
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
96 changes: 96 additions & 0 deletions SecurityAuditScript-Update.py
Original file line number Diff line number Diff line change
@@ -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)