A Python script for SSH login bruteforcing, allowing security testing by systematically trying passwords from a list against a target host. Features user-friendly prompts and detailed logging for effective security assessments.
-
Logging: The script uses the
pwn
library for logging, making it easy to understand what's happening. -
Security Check: After trying passwords, the script checks and logs the security settings of the SSH connection.
-
User Interaction: You can input details like the target host IP, username, and the password file's path.
-
Structured Logs: The script logs attempts, security details, and errors in an organized way.
-
Exception Handling: Handles errors during SSH attempts and security checks, logging them for reference.
- TIMEOUT: A predefined constant regulates the timeout duration for SSH connection attempts.
-
Initialization:
- Logging is initiated, signaling the commencement of the SSH bruteforce script.
-
User Input:
- The script prompts the user for crucial information, including the target host IP, username, and the password file's path.
-
SSH Login Attempt:
- The script iterates through passwords, attempting an SSH login using the
ssh()
function from thepwn
module.
- The script iterates through passwords, attempting an SSH login using the
-
Security Settings Check:
- Upon successful login, the script thoroughly inspects and logs the security settings of the SSH connection.
-
Exception Handling:
- Robust exception handling captures and logs errors during both SSH connection attempts and the security settings check.
-
Cleanup:
- The script gracefully concludes the SSH connection and loops for subsequent iterations.
-
Script Completion:
- A conclusive log message signifies the successful completion of the SSH bruteforce script.
- Purpose: A powerful library for exploitation and binary manipulation.
- Usage: Used for logging and handling interactions in an organized way.
- Functions:
log.info()
: Logs informational messages.log.success()
: Logs success messages.log.failure()
: Logs failure messages.
- Purpose: A Python implementation of the SSH protocol, providing support for secure connections.
- Usage: Used for SSH connection attempts and security settings inspection.
- Classes:
Transport
: Represents an SSH transport, allowing for connection and security checks.Transport.get_security_options()
: Retrieves security options (ciphers, digests, etc.) from the established transport.SecurityOptions
Class:- Purpose: Simple object containing the security preferences of an SSH transport.
- Usage: Preferences include acceptable ciphers, digests, key types, key exchange algorithms, and compression algorithms.
- Methods:
__init__(transport)
: Initializes the object with a given transport.__repr__()
: Returns a string representation of the object for debugging.
- Properties:
ciphers
: Symmetric encryption ciphers.digests
: Digest (one-way hash) algorithms.key_types
: Public-key algorithms.kex
: Key exchange algorithms.compression
: Compression algorithms.
- Functions:
input()
: Takes user input for the target host IP, username, and the path to the password file.- Usage: Collects information required for SSH bruteforcing.
- Functions:
with open(password_file, "r") as password_list:
: Opens the password file for reading.for password in password_list:
: Iterates through the password list.ssh()
: Initiates an SSH connection attempt using the provided credentials.
- Purpose: Captures and logs errors during SSH connection attempts and security settings checks.
- Functions:
paramiko.ssh_exception.AuthenticationException
: Handles authentication errors during SSH login attempts.Exception
: Catches and logs general exceptions.
- Purpose: Checks and logs the security settings of the established SSH connection.
- Functions:
Transport.get_security_options()
: Retrieves and logs security options.
- Functions:
transport.close()
: Closes the SSH connection.log.info("SSH bruteforce script completed")
: Logs a completion message for the script.
In summary, the script utilizes the pwn
library for logging and interaction, the paramiko
library for SSH connection attempts and security settings inspection, along with constants and user input to perform a bruteforce attack on an SSH login. Exception handling ensures robust error logging, and the script concludes by closing the SSH connection and logging the completion message.
-
Check SSH Server Status:
sudo service ssh start
Ensure that the SSH server is running. If not, install the SSH server:
sudo apt update sudo apt install openssh-server
-
Verify SSH Port: Confirm that your SSH server is running on port 22. Adjust the port if necessary.
-
Firewall Check: Make sure your firewall allows incoming connections on port 22.
-
Inspect SSH Server Logs: Look into the SSH server logs for error messages
cat /var/log/auth.log
-
Verify Localhost Resolution: Ensure that "
localhost
" resolves to127.0.0.1
:ping localhost
-
Install SSH Server:
sudo apt update sudo apt install openssh-server
-
Start SSH Service:
sudo service ssh start
After addressing these steps, attempt to run your Python script again:
sudo python3 ssh_bruteforce.py
Ensure that the script has the necessary permissions to access the SSH service. If issues persist, review error messages and logs for further troubleshooting.
Note: This script is designed for educational purposes and ethical use only. Unauthorized access to systems is illegal and unethical.