diff --git a/Enumerating a System over the Network/Programming and Algorithms 2 CW2.docx b/Enumerating a System over the Network/Programming and Algorithms 2 CW2.docx new file mode 100644 index 0000000..e73622c Binary files /dev/null and b/Enumerating a System over the Network/Programming and Algorithms 2 CW2.docx differ diff --git a/Enumerating a System over the Network/README b/Enumerating a System over the Network/README new file mode 100644 index 0000000..136cead --- /dev/null +++ b/Enumerating a System over the Network/README @@ -0,0 +1,41 @@ +Virtual Machine Controller Tool +Overview +The Virtual Machine Controller Tool is a Python-based application designed to manage and send commands to multiple virtual machines (VMs) through a graphical user interface (GUI). It allows users to select between different VMs, choose commands based on the operating system of the selected VM, and execute these commands remotely. The tool supports basic network commands for Linux and Windows VMs and provides real-time output display within the GUI. + +Features +VM Configuration Management: Configure and select VMs to manage directly from the GUI. +OS-Specific Commands: Dynamically updates available commands based on the selected VM's operating system. +Command Execution: Execute commands on the chosen VM or all VMs simultaneously and display the output. +Output Management: Save command execution outputs to text files for further analysis or documentation purposes. +Components +config_handler.py: Manages configurations for VMs and defines available commands based on the operating system. +utilities.py: Contains utility functions, including a method to save command outputs to a file. +controller_app.py: The main application logic, handling the GUI and integrating other components. +main.py: The entry point of the application, responsible for initializing and running the GUI. +Setup +Ensure Python 3.x is installed on your system. +Clone the repository or download the source code. +(Optional) Set up a virtual environment: +bash +Copy code +python -m venv venv +source venv/bin/activate # On Windows use `venv\Scripts\activate` +(Optional) Install dependencies: +Copy code +pip install -r requirements.txt +Running the Application +To run the Virtual Machine Controller Tool, navigate to the project directory and execute: + +css +Copy code +python main.py +Testing +Unit tests have been implemented to ensure the reliability of the tool's core functionalities. These tests cover: + +ConfigHandler Functionality: Tests configuration loading for VMs and command sets, ensuring correct retrieval of configurations based on VM name and OS type. +Command Execution and Output Saving: Verifies that commands are executed correctly on the selected VMs, and the outputs are accurately saved to files. +Test Cases and Outcomes +test_get_vm_config_exists: Ensures VM configurations are correctly retrieved. Outcome: Passed. +test_get_vm_config_not_exists: Checks the tool's response to requests for non-existent VM configurations. Outcome: Passed. +test_save_command_output_content: Confirms that command outputs are correctly saved to files and contain the expected content. Outcome: Passed. +Additional tests for error handling and edge cases have been conducted to simulate various scenarios, including invalid commands and connection failures. Outcome: All tests passed, ensuring robust error handling and graceful degradation. \ No newline at end of file diff --git a/Enumerating a System over the Network/__pycache__/config_handler.cpython-312.pyc b/Enumerating a System over the Network/__pycache__/config_handler.cpython-312.pyc new file mode 100644 index 0000000..972e538 Binary files /dev/null and b/Enumerating a System over the Network/__pycache__/config_handler.cpython-312.pyc differ diff --git a/Enumerating a System over the Network/__pycache__/controller_app.cpython-312.pyc b/Enumerating a System over the Network/__pycache__/controller_app.cpython-312.pyc new file mode 100644 index 0000000..de8a9de Binary files /dev/null and b/Enumerating a System over the Network/__pycache__/controller_app.cpython-312.pyc differ diff --git a/Enumerating a System over the Network/__pycache__/utilities.cpython-312.pyc b/Enumerating a System over the Network/__pycache__/utilities.cpython-312.pyc new file mode 100644 index 0000000..1360969 Binary files /dev/null and b/Enumerating a System over the Network/__pycache__/utilities.cpython-312.pyc differ diff --git a/Enumerating a System over the Network/clientkali.py b/Enumerating a System over the Network/clientkali.py new file mode 100644 index 0000000..4627724 --- /dev/null +++ b/Enumerating a System over the Network/clientkali.py @@ -0,0 +1,80 @@ +import socket +import subprocess + +class CommandExecutor: + """ + Class to execute commands and return their output. + """ + @staticmethod + def execute(command): + """ + Execute a command and return its output. + + Parameters: + command (str): The command to execute. + + Returns: + str: The output of the executed command. + """ + try: + output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT) + return output.decode() + except subprocess.CalledProcessError as e: + return e.output.decode() + +class Server: + """ + Class to handle server functionality. + """ + def __init__(self, host, port): + """ + Initialize the server. + + Parameters: + host (str): The host IP on which the server will listen. + port (int): The port number on which the server will listen. + """ + self.host = host + self.port = port + self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + def start(self): + """ + Start the server and listen for incoming connections. + """ + try: + self.server_socket.bind((self.host, self.port)) + self.server_socket.listen(1) # Limit to 1 pending connection + print("Server is listening on {}:{}".format(self.host, self.port)) + + while True: + client_socket, client_address = self.server_socket.accept() + print("Connection established with:", client_address) + + while True: + command = client_socket.recv(1024).decode().strip() + print("Received command:", command) + + if command == 'exit': + break + else: + output = CommandExecutor.execute(command) + client_socket.sendall(output.encode()) + + except Exception as e: + print("Error:", e) + finally: + client_socket.close() + self.server_socket.close() + +def main(): + """ + Main function to start the server. + """ + host = '0.0.0.0' # Listen on all available network interfaces + port = 12345 # Use a custom port (you can change it as needed) + server = Server(host, port) + server.start() + +if __name__ == "__main__": + main() diff --git a/Enumerating a System over the Network/clientwindows.py b/Enumerating a System over the Network/clientwindows.py new file mode 100644 index 0000000..1829f93 --- /dev/null +++ b/Enumerating a System over the Network/clientwindows.py @@ -0,0 +1,81 @@ +import socket +import subprocess +import os + +class CommandExecutor: + """ + Class to execute commands and return their output. + """ + @staticmethod + def execute(command): + """ + Execute a command and return its output. + + Parameters: + command (str): The command to execute. + + Returns: + str: The output of the executed command. + """ + try: + if os.name == 'nt': + # For Windows, ensure cmd is used to execute the command + output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, text=True, executable='/bin/sh') + else: + # For Unix-like systems + output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, text=True) + return output + except subprocess.CalledProcessError as e: + return e.output + +class Server: + """ + Class to handle server functionality. + """ + def __init__(self, host, port): + """ + Initialize the server. + + Parameters: + host (str): The host IP on which the server will listen. + port (int): The port number on which the server will listen. + """ + self.host = host + self.port = port + self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + def start(self): + """ + Start the server and listen for incoming connections. + """ + try: + self.server_socket.bind((self.host, self.port)) + self.server_socket.listen(1) + print(f"Server listening on {self.host}:{self.port}") + + while True: + client_socket, address = self.server_socket.accept() + print(f"Connection from {address} has been established.") + + while True: + command = client_socket.recv(1024).decode().strip() + if not command or command.lower() == 'exit': + break # Exit the loop if command is empty or 'exit' + print(f"Executing command: {command}") + output = CommandExecutor.execute(command) + client_socket.sendall(output.encode()) + + finally: + self.server_socket.close() + +def main(): + """ + Main function to start the server. + """ + host = '0.0.0.0' # Listen on all available network interfaces + port = 12345 # Port number should match the one used in the controller.py + server = Server(host, port) + server.start() + +if __name__ == "__main__": + main() diff --git a/Enumerating a System over the Network/clientwindowsvm.py b/Enumerating a System over the Network/clientwindowsvm.py new file mode 100644 index 0000000..b06b907 --- /dev/null +++ b/Enumerating a System over the Network/clientwindowsvm.py @@ -0,0 +1,78 @@ +import socket +import subprocess + +class CommandExecutor: + """ + Class to execute commands and return their output. + """ + @staticmethod + def execute(command): + """ + Execute a command and return its output. + + Parameters: + command (str): The command to execute. + + Returns: + str: The output of the executed command. + """ + try: + output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT) + return output.decode() + except subprocess.CalledProcessError as e: + return e.output.decode() + +class Server: + """ + Class to handle server functionality. + """ + def __init__(self, host, port): + """ + Initialize the server. + + Parameters: + host (str): The host IP on which the server will listen. + port (int): The port number on which the server will listen. + """ + self.host = host + self.port = port + self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + def start(self): + """ + Start the server and listen for incoming connections. + """ + try: + self.server_socket.bind((self.host, self.port)) + self.server_socket.listen(1) + print(f"Server is listening on {self.host}:{self.port}") + + while True: + client_socket, client_address = self.server_socket.accept() + print(f"Connection established with: {client_address}") + + while True: + command = client_socket.recv(1024).decode().strip() + if not command: + break # Connection closed by the client + print(f"Received command: {command}") + if command.lower() == 'exit': + break + output = CommandExecutor.execute(command) + client_socket.sendall(output.encode()) + except Exception as e: + print(f"Server error: {e}") + finally: + self.server_socket.close() + +def main(): + """ + Main function to start the server. + """ + host = '0.0.0.0' # Listen on all network interfaces + port = 12345 # The port on which to listen + server = Server(host, port) + server.start() + +if __name__ == "__main__": + main() diff --git a/Enumerating a System over the Network/config_handler.py b/Enumerating a System over the Network/config_handler.py new file mode 100644 index 0000000..09e0db5 --- /dev/null +++ b/Enumerating a System over the Network/config_handler.py @@ -0,0 +1,35 @@ +class ConfigHandler: + """Handles configurations for virtual machines and command sets.""" + def __init__(self): + self.vm_configs = { + 'vm1': {'ip': '192.168.0.37', 'port': 12345}, + 'vm2': {'ip': '192.168.31.137', 'port': 12345}, + 'vm3': {'ip': '192.168.0.196', 'port': 12345}, + } + self.commands = { + 'Linux': { + 'Get Users (cat /etc/passwd)': 'cat /etc/passwd', + 'Finding open Ports (nmap localhost)': 'nmap localhost', + 'List running processes (ps aux)': 'ps aux', + 'System information (uname -a)': 'uname -a', + 'Network information (ifconfig)': 'ifconfig', + 'Disk usage (df -h)': 'df -h', + }, + 'Windows': { + 'Display network info (ipconfig)': 'ipconfig', + 'Display network stats (netstat)': 'netstat', + 'List of processes (tasklist)': 'tasklist', + 'System information (systeminfo)': 'systeminfo', + 'List user accounts (net user)': 'net user', + 'List open ports (netstat -a -n)': 'netstat -a -n', + 'Display computer name (hostname)': 'hostname', + }, + } + + def get_vm_config(self, vm_name): + """Retrieves the configuration for a specified VM.""" + return self.vm_configs.get(vm_name, {}) + + def get_commands(self, os_type): + """Retrieves the command set for the specified OS type.""" + return self.commands.get(os_type, {}) diff --git a/Enumerating a System over the Network/controller.py b/Enumerating a System over the Network/controller.py new file mode 100644 index 0000000..4c4c202 --- /dev/null +++ b/Enumerating a System over the Network/controller.py @@ -0,0 +1,217 @@ +import socket # Import the socket module for networking functionality +import tkinter as tk # Import the tkinter module for GUI +from tkinter import scrolledtext, ttk # Import specific components from tkinter + +class ConfigHandler: + """ + Handles configurations for virtual machines (VMs) and commands for different operating systems. + """ + def __init__(self): + """ + Initializes the ConfigHandler class with predefined VM configurations and commands for Linux and Windows. + """ + # Define VM configurations and commands for Linux and Windows + self.vm_configs = { + 'vm1': {'ip': '192.168.0.37', 'port': 12345}, + 'vm2': {'ip': '192.168.31.137', 'port': 12345}, + 'vm3': {'ip': '192.168.0.196', 'port': 12345}, + } + self.commands = { + 'Linux': { + 'Get Users (cat /etc/passwd)': 'cat /etc/passwd', + 'Finding open Ports (nmap localhost)': 'nmap localhost', + 'List running processes (ps aux)': 'ps aux', + 'System information (uname -a)': 'uname -a', + 'Network information (ifconfig)': 'ifconfig', + 'Disk usage (df -h)': 'df -h', + }, + 'Windows': { + 'Display network info (ipconfig)': 'ipconfig', + 'Display network stats (netstat)': 'netstat', + 'List of processes (tasklist)': 'tasklist', + 'System information (systeminfo)': 'systeminfo', + 'List user accounts (net user)': 'net user', + 'List open ports (netstat -a -n)': 'netstat -a -n', + 'Display computer name (hostname)': 'hostname', + }, + } + + def get_vm_config(self, vm_name): + """ + Retrieve configuration for a specific VM. + + Parameters: + vm_name (str): Name of the VM. + + Returns: + dict: Configuration of the specified VM. + """ + return self.vm_configs.get(vm_name, {}) + + def get_commands(self, os_type): + """ + Retrieve commands for a specific operating system. + + Parameters: + os_type (str): Type of operating system ('Linux' or 'Windows'). + + Returns: + dict: Dictionary containing commands for the specified OS. + """ + return self.commands.get(os_type, {}) + +def save_command_output(vm_label, command, output): + """ + Save command output to a file. + + Parameters: + vm_label (str): Label identifying the VM. + command (str): Command executed on the VM. + output (str): Output of the executed command. + """ + # Generate filename based on VM label and command + filename = f"{vm_label}_{command.replace(' ', '_')}.txt" + # Write output to file + with open(filename, 'w') as file: + file.write(output) + # Print confirmation message + print(f"Output saved to {filename}") + +class ControllerApp: + """ + Main application class for controlling VMs. + """ + def __init__(self, master): + """ + Initialize the ControllerApp class. + + Parameters: + master: Parent tkinter widget. + """ + # Initialize ConfigHandler and tkinter window + self.config_handler = ConfigHandler() + self.master = master + master.title("VM Controller") + + # Initialize lists to store connection labels and sockets + self.connection_labels = [] + self.sockets = {} + # Connect to VMs and set up UI + self.connect_to_vms() + self.setup_ui() + + def connect_to_vms(self): + """ + Connect to VMs using sockets and display connection status. + """ + # Iterate over VM configurations + for vm_name, config in self.config_handler.vm_configs.items(): + try: + # Create socket and connect to VM + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((config['ip'], config['port'])) + # Store socket in dictionary + self.sockets[vm_name] = sock + # Create label indicating successful connection + self.connection_labels.append(tk.Label(self.master, text=f"Connected to {vm_name}.")) + except Exception as e: + # Create label indicating connection error + self.connection_labels.append(tk.Label(self.master, text=f"Error connecting to {vm_name}: {e}")) + + # Display connection labels + for label in self.connection_labels: + label.pack() + + def setup_ui(self): + """ + Set up the user interface (UI) for the application. + """ + # Set up radio buttons for selecting VM and operating system + self.vm_selection_var = tk.StringVar(value="vm1") + self.os_selection_var = tk.StringVar(value="Linux") + + for vm_name in self.config_handler.vm_configs.keys(): + tk.Radiobutton(self.master, text=vm_name.upper(), variable=self.vm_selection_var, value=vm_name).pack() + + tk.Radiobutton(self.master, text="Linux", variable=self.os_selection_var, value="Linux", command=self.update_command_list).pack() + tk.Radiobutton(self.master, text="Windows", variable=self.os_selection_var, value="Windows", command=self.update_command_list).pack() + + # Set up dropdown menu for selecting commands + self.command_var = tk.StringVar() + self.command_dropdown = ttk.Combobox(self.master, textvariable=self.command_var, width=50) + self.update_command_list() + self.command_dropdown['state'] = 'readonly' + self.command_dropdown.pack() + + # Set up buttons for sending commands + tk.Button(self.master, text="Send Command", command=self.send_command).pack() + tk.Button(self.master, text="Send to All VMs", command=self.send_command_to_all).pack() + + # Set up scrolled text widget for displaying command output + self.output_text = scrolledtext.ScrolledText(self.master, height=10) + self.output_text.pack() + + def update_command_list(self): + """ + Update the command dropdown list based on the selected operating system. + """ + # Retrieve commands for selected operating system + os_selected = self.os_selection_var.get() + commands = self.config_handler.get_commands(os_selected) + # Update dropdown values with commands + self.command_dropdown['values'] = list(commands.keys()) + self.command_dropdown.set('') + + def send_command(self): + """ + Send a command to a selected VM and display the output. + """ + # Get selected VM, command, and command text + vm_selected = self.vm_selection_var.get() + command_text = self.command_var.get() + command = self.config_handler.get_commands(self.os_selection_var.get()).get(command_text, "") + # Send command to VM if it's connected + if vm_selected in self.sockets: + sock = self.sockets[vm_selected] + sock.sendall(command.encode()) + output = sock.recv(4096).decode() + # Display output and save to file + self.output_text.delete('1.0', tk.END) + self.output_text.insert(tk.INSERT, output) + save_command_output(vm_selected, command_text, output) + + def send_command_to_all(self): + """ + Send a command to all connected VMs and display the output. + """ + # Get selected command and command text + command_text = self.command_var.get() + command = self.config_handler.get_commands(self.os_selection_var.get()).get(command_text, "") + outputs = [] + # Send command to each connected VM + for vm_name, sock in self.sockets.items(): + sock.sendall(command.encode()) + output = sock.recv(4096).decode() + outputs.append(f"{vm_name.upper()}:\n{output}") + # Save output to file + save_command_output(vm_name, command_text, output) + # Display combined output + self.output_text.delete('1.0', tk.END) + self.output_text.insert(tk.INSERT, "\n\n".join(outputs)) + +def on_closing(): + """ + Handle closing event of the application. + """ + # Close sockets and destroy tkinter window + for sock in app.sockets.values(): + sock.close() + app.master.destroy() + +# Create tkinter window and ControllerApp instance +root = tk.Tk() +app = ControllerApp(root) +# Register closing event handler +root.protocol("WM_DELETE_WINDOW", on_closing) +# Start the main event loop +root.mainloop() diff --git a/Enumerating a System over the Network/controller_app.py b/Enumerating a System over the Network/controller_app.py new file mode 100644 index 0000000..dcc15d5 --- /dev/null +++ b/Enumerating a System over the Network/controller_app.py @@ -0,0 +1,95 @@ +import tkinter as tk +from tkinter import scrolledtext, ttk +from config_handler import ConfigHandler +from utilities import save_command_output +import socket + +class ControllerApp: + """The main application class for controlling virtual machines via a GUI.""" + def __init__(self, master): + self.config_handler = ConfigHandler() + self.master = master + master.title("VM Controller") + + self.sockets = {} + self.connect_to_vms() + self.setup_ui() + + def connect_to_vms(self): + """Establishes socket connections to VMs based on configuration.""" + for vm_name, config in self.config_handler.vm_configs.items(): + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((config['ip'], config['port'])) + self.sockets[vm_name] = sock + print(f"Connected to {vm_name}.") + except Exception as e: + print(f"Error connecting to {vm_name}: {e}") + + def setup_ui(self): + """Sets up the UI elements of the application.""" + # VM selection + self.vm_selection_var = tk.StringVar(value="vm1") + for vm_name in self.config_handler.vm_configs.keys(): + tk.Radiobutton(self.master, text=vm_name.upper(), variable=self.vm_selection_var, value=vm_name).pack() + + # OS selection + self.os_selection_var = tk.StringVar(value="Linux") + tk.Radiobutton(self.master, text="Linux", variable=self.os_selection_var, value="Linux", command=self.update_command_list).pack() + tk.Radiobutton(self.master, text="Windows", variable=self.os_selection_var, value="Windows", command=self.update_command_list).pack() + + # Command selection dropdown + self.command_var = tk.StringVar() + self.command_dropdown = ttk.Combobox(self.master, textvariable=self.command_var, width=50) + self.command_dropdown['values'] = list(self.config_handler.get_commands('Linux').keys()) + self.command_dropdown['state'] = 'readonly' + self.command_dropdown.pack() + + # Send command button + tk.Button(self.master, text="Send Command", command=self.send_command).pack() + + # Send to all VMs button + tk.Button(self.master, text="Send to All VMs", command=self.send_command_to_all).pack() + + # Output text area + self.output_text = scrolledtext.ScrolledText(self.master, height=10) + self.output_text.pack() + + def update_command_list(self): + """Updates the command list based on the selected OS.""" + os_selected = self.os_selection_var.get() + commands = self.config_handler.get_commands(os_selected) + self.command_dropdown['values'] = list(commands.keys()) + self.command_dropdown.set('') # Reset the dropdown + + def send_command(self): + """Sends the selected command to the chosen VM.""" + vm_selected = self.vm_selection_var.get() + command_text = self.command_var.get() + command = self.config_handler.get_commands(self.os_selection_var.get()).get(command_text, "") + if vm_selected in self.sockets: + sock = self.sockets[vm_selected] + sock.sendall(command.encode()) + output = sock.recv(4096).decode() + self.output_text.delete('1.0', tk.END) + self.output_text.insert(tk.INSERT, output) + save_command_output(vm_selected, command_text, output) + + def send_command_to_all(self): + """Sends the selected command to all VMs and displays their outputs.""" + command_text = self.command_var.get() + command = self.config_handler.get_commands(self.os_selection_var.get()).get(command_text, "") + outputs = [] + for vm_name, sock in self.sockets.items(): + sock.sendall(command.encode()) + output = sock.recv(4096).decode() + outputs.append(f"{vm_name.upper()}:\n{output}") + save_command_output(vm_name, command_text, output) + self.output_text.delete('1.0', tk.END) + self.output_text.insert(tk.INSERT, "\n\n".join(outputs)) + + def on_closing(self): + """Handles the closing event of the application.""" + for sock in self.sockets.values(): + sock.close() + self.master.destroy() diff --git a/Enumerating a System over the Network/main.py b/Enumerating a System over the Network/main.py new file mode 100644 index 0000000..8e37a06 --- /dev/null +++ b/Enumerating a System over the Network/main.py @@ -0,0 +1,12 @@ +import tkinter as tk +from controller_app import ControllerApp + +def main(): + """Main function to run the application.""" + root = tk.Tk() + app = ControllerApp(root) + root.protocol("WM_DELETE_WINDOW", app.on_closing) + root.mainloop() + +if __name__ == "__main__": + main() diff --git a/Enumerating a System over the Network/requirements.txt b/Enumerating a System over the Network/requirements.txt new file mode 100644 index 0000000..79dc369 Binary files /dev/null and b/Enumerating a System over the Network/requirements.txt differ diff --git a/Enumerating a System over the Network/unit_test.py b/Enumerating a System over the Network/unit_test.py new file mode 100644 index 0000000..3f63d7c --- /dev/null +++ b/Enumerating a System over the Network/unit_test.py @@ -0,0 +1,55 @@ +import unittest +from config_handler import ConfigHandler +from utilities import save_command_output +import os + +class TestConfigHandler(unittest.TestCase): + def setUp(self): + """Initialize ConfigHandler before each test.""" + self.config = ConfigHandler() + + def test_get_vm_config_exists(self): + """Test retrieving existing VM configuration.""" + vm1_config = self.config.get_vm_config('vm1') + self.assertEqual(vm1_config['ip'], '192.168.0.37') + + def test_get_vm_config_not_exists(self): + """Test retrieving non-existing VM configuration.""" + vm_config = self.config.get_vm_config('vm_nonexistent') + self.assertEqual(vm_config, {}) + + def test_get_commands_linux(self): + """Test retrieving Linux commands.""" + linux_commands = self.config.get_commands('Linux') + self.assertIn('Get Users (cat /etc/passwd)', linux_commands) + + def test_get_commands_windows(self): + """Test retrieving Windows commands.""" + windows_commands = self.config.get_commands('Windows') + self.assertIn('Display network info (ipconfig)', windows_commands) + + def test_get_commands_no_os(self): + """Test retrieving commands for an unsupported OS type.""" + no_os_commands = self.config.get_commands('NoOS') + self.assertEqual(no_os_commands, {}) + +class TestUtilities(unittest.TestCase): + def test_save_command_output_content(self): + """Test saving command output to a file and verify content.""" + test_vm_label = "test_vm" + test_command = "echo_Hello" + test_output = "Hello World" + save_command_output(test_vm_label, test_command, test_output) + expected_filename = f"{test_vm_label}_{test_command}.txt" + + # Verify file content + with open(expected_filename, 'r') as file: + content = file.read() + self.assertEqual(content, test_output) + + # Cleanup + if os.path.exists(expected_filename): + os.remove(expected_filename) + +if __name__ == "__main__": + unittest.main() diff --git a/Enumerating a System over the Network/utilities.py b/Enumerating a System over the Network/utilities.py new file mode 100644 index 0000000..307d646 --- /dev/null +++ b/Enumerating a System over the Network/utilities.py @@ -0,0 +1,6 @@ +def save_command_output(vm_label, command, output): + """Saves the output of a command to a file.""" + filename = f"{vm_label}_{command.replace(' ', '_')}.txt" + with open(filename, 'w') as file: + file.write(output) + print(f"Output saved to {filename}") diff --git a/Enumerating a System over the Network/vm2_Display_computer_name_(hostname).txt b/Enumerating a System over the Network/vm2_Display_computer_name_(hostname).txt new file mode 100644 index 0000000..64012f7 --- /dev/null +++ b/Enumerating a System over the Network/vm2_Display_computer_name_(hostname).txt @@ -0,0 +1,59 @@ +WmiPrvSE.exe 4788 Services 0 14,552 K +WmiPrvSE.exe 1180 Services 0 8,472 K +TrustedInstaller.exe 8516 Services 0 7,252 K +TiWorker.exe 8964 Services 0 10,180 K +cmd.exe 8928 Console 2 3,900 K +tasklist.exe 3496 Console 2 8,792 K + +Host Name: DESKTOP-GKBPAO7 +OS Name: Microsoft Windows 10 Home +OS Version: 10.0.19045 N/A Build 19045 +OS Manufacturer: Microsoft Corporation +OS Configuration: Standalone Workstation +OS Build Type: Multiprocessor Free +Registered Owner: jordanchatha@gmail.com +Registered Organization: +Product ID: 00326-10000-00000-AA995 +Original Install Date: 04/04/2024, 16:13:48 +System Boot Time: 04/04/2024, 16:13:27 +System Manufacturer: VMware, Inc. +System Model: VMware20,1 +System Type: x64-based PC +Processor(s): 1 Processor(s) Installed. + [01]: Intel64 Family 6 Model 165 Stepping 2 GenuineIntel ~2304 Mhz +BIOS Version: VMware, Inc. VMW201.00V.21805430.B64.2305221830, 22/05/2023 +Windows Directory: C:\Windows +System Directory: C:\Windows\system32 +Boot Device: \Device\HarddiskVolume1 +System Locale: en-gb;English (United Kingdom) +Input Locale: en-gb;English (United Kingdom) +Time Zone: (UTC+00:00) Dublin, Edinburgh, Lisbon, London +Total Physical Memory: 2,047 MB +Available Physical Memory: 339 MB +Virtual Memory: Max Size: 5,840 MB +Virtual Memory: Available: 1,100 MB +Virtual Memory: In Use: 4,740 MB +Page File Location(s): C:\pagefile.sys +Domain: WORKGROUP +Logon Server: \\WIN-VAODCDP5ECI +Hotfix(s): 8 Hotfix(s) Installed. + [01]: KB5031988 + [02]: KB5034468 + [03]: KB5011048 + [04]: KB5015684 + [05]: KB5035845 + [06]: KB5014032 + [07]: KB5032907 + [08]: KB5036447 +Network Card(s): 2 NIC(s) Installed. + [01]: Bluetooth Device (Personal Area Network) + Connection Name: Bluetooth Network Connection + Status: Media disconnected + [02]: Intel(R) 82574L Gigabit Network Connection + Connection Name: Ethernet0 + DHCP Enabled: Yes + DHCP Server: 192.168.31.254 + IP address(es) + [01]: 192.168.31.137 + [02]: fe80::632d:64c9:5b6d:248e +Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed. diff --git a/Enumerating a System over the Network/vm2_List_of_processes_(tasklist).txt b/Enumerating a System over the Network/vm2_List_of_processes_(tasklist).txt new file mode 100644 index 0000000..81c9ee5 --- /dev/null +++ b/Enumerating a System over the Network/vm2_List_of_processes_(tasklist).txt @@ -0,0 +1,54 @@ + +Image Name PID Session Name Session# Mem Usage +========================= ======== ================ =========== ============ +System Idle Process 0 Services 0 8 K +System 4 Services 0 N/A +Registry 72 Services 0 4,960 K +smss.exe 532 Services 0 N/A +csrss.exe 632 Services 0 576 K +wininit.exe 748 Services 0 N/A +services.exe 808 Services 0 3,528 K +lsass.exe 816 Services 0 5,028 K +fontdrvhost.exe 932 Services 0 N/A +svchost.exe 968 Services 0 5,660 K +svchost.exe 556 Services 0 6,476 K +svchost.exe 1036 Services 0 18,424 K +svchost.exe 1052 Services 0 2,980 K +svchost.exe 1136 Services 0 3,508 K +svchost.exe 1268 Services 0 984 K +svchost.exe 1300 Services 0 N/A +svchost.exe 1356 Services 0 1,104 K +svchost.exe 1436 Services 0 4,560 K +svchost.exe 1496 Services 0 4,100 K +svchost.exe 1744 Services 0 N/A +Memory Compression 1312 Services 0 620,976 K +svchost.exe 1568 Services 0 8 K +svchost.exe 1480 Services 0 20 K +spoolsv.exe 2064 Services 0 N/A +svchost.exe 2092 Services 0 1,388 K +svchost.exe 2228 Services 0 3,368 K +SearchIndexer.exe 2512 Services 0 2,452 K +svchost.exe 3224 Services 0 1,204 K +svchost.exe 4120 Services 0 44 K +svchost.exe 1276 Services 0 N/A +SgrmBroker.exe 1220 Services 0 2,384 K +svchost.exe 1456 Services 0 N/A +SecurityHealthService.exe 408 Services 0 312 K +csrss.exe 1552 Console 2 1,084 K +winlogon.exe 2608 Console 2 464 K +dwm.exe 3812 Console 2 14,568 K +fontdrvhost.exe 4400 Console 2 N/A +sihost.exe 3060 Console 2 1,872 K +svchost.exe 1216 Console 2 1,552 K +ctfmon.exe 4812 Console 2 260 K +explorer.exe 1376 Console 2 19,188 K +smartscreen.exe 4184 Console 2 220 K +dllhost.exe 4424 Console 2 2,268 K +svchost.exe 3704 Console 2 2,148 K +StartMenuExperienceHost.e 3240 Console 2 4,240 K +RuntimeBroker.exe 2680 Console 2 1,628 K +SearchApp.exe 848 Console 2 N/A +RuntimeBroker.exe 548 Console 2 2,328 K +RuntimeBroker.exe 5176 Console 2 772 K +svchost.exe 5244 Services 0 1,216 K +SettingSyncHost.exe 5828 Con \ No newline at end of file diff --git a/Enumerating a System over the Network/vm2_List_user_accounts_(net_user).txt b/Enumerating a System over the Network/vm2_List_user_accounts_(net_user).txt new file mode 100644 index 0000000..9d00d3d --- /dev/null +++ b/Enumerating a System over the Network/vm2_List_user_accounts_(net_user).txt @@ -0,0 +1,53 @@ +sole 2 840 K +taskhostw.exe 6044 Console 2 600 K +ShellExperienceHost.exe 308 Console 2 N/A +RuntimeBroker.exe 6404 Console 2 368 K +SecurityHealthSystray.exe 6972 Console 2 2,340 K +OneDrive.exe 6332 Console 2 1,472 K +TextInputHost.exe 3616 Console 2 976 K +ApplicationFrameHost.exe 572 Console 2 N/A +svchost.exe 6620 Services 0 600 K +dllhost.exe 7028 Console 2 N/A +taskhostw.exe 7212 Console 2 N/A +msedge.exe 5576 Console 2 53,796 K +msedge.exe 1520 Console 2 N/A +msedge.exe 1408 Console 2 21,084 K +msedge.exe 6548 Console 2 16,224 K +msedge.exe 3744 Console 2 1,652 K +msedge.exe 5764 Console 2 228 K +msedge.exe 6792 Console 2 5,756 K +Code.exe 7632 Console 2 19,836 K +Code.exe 1740 Console 2 N/A +Code.exe 1504 Console 2 13,460 K +Code.exe 2296 Console 2 6,416 K +Code.exe 2468 Console 2 78,592 K +Code.exe 3032 Console 2 3,884 K +Code.exe 6300 Console 2 2,040 K +Code.exe 7652 Console 2 7,436 K +Code.exe 7696 Console 2 17,892 K +conhost.exe 6000 Console 2 N/A +powershell.exe 4564 Console 2 592 K +Code.exe 5836 Console 2 2,364 K +SkypeBridge.exe 4992 Console 2 14,572 K +msedge.exe 5508 Console 2 3,312 K +msedge.exe 3800 Console 2 4,228 K +msedge.exe 1584 Console 2 1,096 K +msedge.exe 432 Console 2 77,404 K +msedge.exe 6780 Console 2 852 K +MsMpEng.exe 5644 Services 0 61,856 K +NisSrv.exe 6156 Services 0 2,264 K +msedge.exe 4880 Console 2 76,092 K +msedge.exe 4932 Console 2 76,960 K +msedge.exe 2816 Console 2 68,492 K +msedge.exe 2328 Console 2 73,444 K +msedge.exe 4616 Console 2 77,064 K +CodeSetup-stable-5c3e652f 2648 Console 2 N/A +CodeSetup-stable-5c3e652f 4144 Console 2 400 K +taskhostw.exe 3588 Console 2 N/A +MusNotifyIcon.exe 5704 Console 2 N/A +SearchApp.exe 10024 Console 2 N/A +msedge.exe 5416 Console 2 460 K +svchost.exe 8892 Services 0 848 K +conhost.exe 6536 Console 2 2,160 K +powershell.exe 8208 Console 2 41,600 K +backgroundTaskHost.exe 8496 Console 2 8 K diff --git a/Enumerating a System over the Network/vm2_System_information_(systeminfo).txt b/Enumerating a System over the Network/vm2_System_information_(systeminfo).txt new file mode 100644 index 0000000..331a8a9 --- /dev/null +++ b/Enumerating a System over the Network/vm2_System_information_(systeminfo).txt @@ -0,0 +1,53 @@ +sole 2 N/A +taskhostw.exe 6044 Console 2 588 K +ShellExperienceHost.exe 308 Console 2 N/A +RuntimeBroker.exe 6404 Console 2 752 K +SecurityHealthSystray.exe 6972 Console 2 692 K +OneDrive.exe 6332 Console 2 1,896 K +TextInputHost.exe 3616 Console 2 2,080 K +ApplicationFrameHost.exe 572 Console 2 N/A +svchost.exe 6620 Services 0 N/A +dllhost.exe 7028 Console 2 N/A +taskhostw.exe 7212 Console 2 456 K +msedge.exe 5576 Console 2 56,676 K +msedge.exe 1520 Console 2 N/A +msedge.exe 1408 Console 2 20,764 K +msedge.exe 6548 Console 2 16,216 K +msedge.exe 3744 Console 2 1,380 K +msedge.exe 5764 Console 2 696 K +msedge.exe 6792 Console 2 1,992 K +Code.exe 7632 Console 2 9,000 K +Code.exe 1740 Console 2 N/A +Code.exe 1504 Console 2 12,936 K +Code.exe 2296 Console 2 3,088 K +Code.exe 2468 Console 2 40,008 K +Code.exe 3032 Console 2 3,636 K +Code.exe 6300 Console 2 2,060 K +Code.exe 7652 Console 2 4,696 K +Code.exe 7696 Console 2 10,880 K +conhost.exe 6000 Console 2 N/A +powershell.exe 4564 Console 2 588 K +Code.exe 5836 Console 2 2,280 K +SkypeBridge.exe 4992 Console 2 3,636 K +msedge.exe 5508 Console 2 4,280 K +msedge.exe 3800 Console 2 5,252 K +msedge.exe 1584 Console 2 1,080 K +msedge.exe 432 Console 2 74,168 K +msedge.exe 6780 Console 2 216 K +MsMpEng.exe 5644 Services 0 47,680 K +NisSrv.exe 6156 Services 0 2,128 K +msedge.exe 4880 Console 2 70,392 K +msedge.exe 4932 Console 2 72,084 K +msedge.exe 2816 Console 2 59,500 K +msedge.exe 2328 Console 2 69,652 K +msedge.exe 4616 Console 2 137,364 K +CodeSetup-stable-5c3e652f 2648 Console 2 N/A +CodeSetup-stable-5c3e652f 4144 Console 2 400 K +MusNotifyIcon.exe 5704 Console 2 N/A +SearchApp.exe 10024 Console 2 N/A +msedge.exe 5416 Console 2 1,524 K +svchost.exe 5792 Services 0 N/A +WmiPrvSE.exe 7440 Services 0 172 K +conhost.exe 5916 Console 2 996 K +powershell.exe 8952 Console 2 1,616 K +python3.11.exe 3904 Console 2 5,140 K