How chaoshour/ssh-audits works
Main Components
• Command-Line Interface (CLI) / Entry Point: The project uses a main Go file (cmd/ssh-audits/main.go) which initializes the application and parses command-line arguments.
• SSH Engine/Connector: Core functionality for connecting to remote hosts using SSH is handled by packages under “pkg/sshutil” and “pkg/sshkey”. These modules are responsible for managing SSH sessions, executing commands, and handling keys.
• SFTP Module: The “pkg/sftp” directory contains functionality related to SFTP file transfers. This component uploads files to remote hosts, adjusts permissions, and can trigger execution.
• Inventory Management: The “inventory/hosts” file (and supporting shell scripts) provides the list of target hosts. This represents the configuration or “data” component that drives which systems are contacted.
• Auxiliary Scripts: Additional scripts like “my-thing.sh” and “list.sh” are used for demonstration or extra functionality, interacting with the core modules.
And Map the Component Interactions
• The CLI module (cmd/ssh-audits) accepts parameters such as inventory file, host(s), command chains, and an SFTP flag.
• Once invoked, the application reads the inventory file and selects the target hosts.
• For each host:
– The SSH connector (using sshkey and sshutil packages) establishes a connection.
– If the “-c” (command) flag is provided, it sends commands for execution.
– If the “-sftp” flag is used, the SFTP module takes over: the file is transferred, appropriate permissions are set, and optionally executed by issuing a command.
• There is data flow from the user’s CLI input through the main process to the individual modules and then to the remote hosts.
Architectural Patterns and Design Principles
• Modular Design: The division between command parsing (cmd/ directory) and business logic (pkg/) is an example of separation of concerns.
• Reusability: Packages such as sshkey and sshutil encapsulate specific SSH functionalities making the overall system extensible.
• Clear Dependency Flow: The main application directs flow to the specific helper packages. Illustrate this layered dependency clearly.