Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
chathaj committed Nov 15, 2024
1 parent 14daa59 commit 7a85f8b
Show file tree
Hide file tree
Showing 19 changed files with 919 additions and 0 deletions.
Binary file not shown.
41 changes: 41 additions & 0 deletions Enumerating a System over the Network/README
Original file line number Diff line number Diff line change
@@ -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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
80 changes: 80 additions & 0 deletions Enumerating a System over the Network/clientkali.py
Original file line number Diff line number Diff line change
@@ -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()
81 changes: 81 additions & 0 deletions Enumerating a System over the Network/clientwindows.py
Original file line number Diff line number Diff line change
@@ -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()
78 changes: 78 additions & 0 deletions Enumerating a System over the Network/clientwindowsvm.py
Original file line number Diff line number Diff line change
@@ -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()
35 changes: 35 additions & 0 deletions Enumerating a System over the Network/config_handler.py
Original file line number Diff line number Diff line change
@@ -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, {})
Loading

0 comments on commit 7a85f8b

Please sign in to comment.