動態

詳情 返回 返回

AList嵌入動態驗證碼實現引流 - 動態 詳情

前言

曉傑利用ALists創建了個網盤資源站,想着如何增加個動態驗證碼進行驗證後才能進行訪問下載,剛開始利用了固定的驗證碼,用户可以通過JS代碼中進行繞過或直接拿到驗證碼,經過曉傑多次優化,最終版本支持動態獲取驗證碼,使用了禁止打開控制枱校驗等方式減少繞過幾率,現在分享給大家。

AList介紹

‌AList是一個支持多種存儲、支持網頁瀏覽和WebDAV的文件列表程序‌,AList的功能包括但不限於添加雲盤服務,如阿里雲盤,通過簡單的步驟如點擊服務狀態按鈕運行、添加驅動、獲取刷新令牌等操作,實現雲盤的掛載和使用。用户還可以通過AList管理自己的網盤,包括添加、刪除、瀏覽和分享文件等。此外,AList還支持將網盤掛載到本地,通過特定的軟件如RaiDrive,實現本地訪問。
總的來説,AList是一個功能強大的本地網盤管理器,它提供了一個直觀的用户界面和豐富的功能,使用户能夠方便地管理和訪問自己的雲存儲資源‌

技術棧

THINKPHP5.1+Redis+mysql

代碼

前端代碼

部分代碼參考:Javascript反調試實現判斷用户是否打開了瀏覽器控制枱
嵌入位置看下圖

<script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool'></script>
<script >
if (checkPwd(localStorage.getItem('pan_password'))) {

} else {
    checkPassword("success", "輸入密碼進入")
}
function checkPwd(password) {
    if (password === "" || password === null) {
        return false;
    }
    const xhr = new XMLHttpRequest();
    xhr.open("POST", "https://自己的域名/code", false); // 注意這裏的第三個參數為 false
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            const data = JSON.parse(xhr.responseText);
            if (data.code === 200) {
                localStorage.setItem("pan_password", password);
                return true;
            }
        }
        return false;
    };
    xhr.send(JSON.stringify({ "password": password }));
    return xhr.onreadystatechange();
}
function checkPassword(ic, ti) {
    swal({
        title: "免責申明",
        text: "\n本站所展示內容均收集於網絡\n僅供本人學習研究及收藏存檔\n如有侵犯權益,敬請聯繫刪除\n\n公眾號:軟件接口平台\n回覆【密碼】獲取密碼",
        closeOnConfirm: false,
        closeOnClickOutside: false,
        icon: ic,
        buttons: {
            confirm: {
                text: "確認訪問",
                value: "confirm",
                className: "custom-swal-button swal-button--confirm"
            },
            viewAnnouncement: {
                text: "獲取密碼",
                value: "view_announcement",
                className: "custom-swal-button swal-button--copy"
            },
        },
        content: {
            element: "input",
            attributes: {
                placeholder: "請輸入驗證碼",
                type: "text",
            },
        },
    })
        .then((value) => {
            if (value == '') {
                checkPassword("warning", "請輸入正確的密碼");
            }else if (value === "view_announcement") {
                // 彈出顯示公告內容的提示框
                showAnnouncement();
            } else if (checkPwd(value)) {
                swal("歡迎!", {
                    button: false,
                });
            } else {
                checkPassword("warning", "密碼錯誤");
            }
        });
    function showAnnouncement() {
        swal({
            title: '軟件接口平台',
            text: "掃碼下面二維碼或關注\n“軟件接口平台”公眾號\n回覆“密碼”獲取最新驗證碼",
            buttons: {
                cancel: {
                    text: "關閉",
                    value: false,
                    visible: true,
                },
            },
            icon: "info",
            content: {
                element: "img",
                attributes: {
                    src: "https://zhanzhang.sogou.com/api/wxapp/file/link?uuid=07e7299ffd299325a6e383897c23eb6d.jpg", // 這裏用佔位圖代替實際圖片
                },
            },
        }).then((value) => {
            checkPassword("success", "輸入密碼進入");
        });
    }

}
document.addEventListener('keydown', function(event) {
    // 檢查 F12 鍵
    if (event.key === 'F12') {
        event.preventDefault();
    }
    // 檢查 Ctrl + Shift + I 組合鍵
    if (event.ctrlKey && event.shiftKey && event.key === 'i') {
        event.preventDefault();
    }
    // 檢查 Ctrl + Shift + J 組合鍵
    if (event.ctrlKey && event.shiftKey && event.key === 'j') {
        event.preventDefault();
    }
    // 檢查 Ctrl + Shift + C 組合鍵
    if (event.ctrlKey && event.shiftKey && event.key === 'c') {
        event.preventDefault();
    }
});
document.addEventListener('contextmenu', function(event) {
    event.preventDefault();
});
var ConsoleManager={
    onOpen(){
        location.href="https://www.java.pet";
    },
    onClose(){
    },
    init(){
        var self = this;
        var x = document.createElement('div');
        var isOpening = false,isOpened=false;
        Object.defineProperty(x, 'id', {
            get(){
                if(!isOpening){
                    self.onOpen();
                    isOpening=true;
                }
                isOpened=true;
            }
        });
        setInterval(function(){
            isOpened=false;
            console.info(x);
            console.clear();
            if(!isOpened && isOpening){
                self.onClose();
                isOpening=false;
            }
        },200)
    }
}

ConsoleManager.onOpen = function(){
    location.href="https://www.java.pet";
}
ConsoleManager.init();

DisableDevtool({
    ondevtoolopen: (type) => {
        const info = 'devtool opened!; type =' + type;
        },
})
</script>

後端代碼

Code.php 校驗 和獲取 接口

<?php

namespace app\api\controller;

use think\cache\driver\Redis;
use tools\Tools;

class Code
{
//用於公眾號或WXQQ機器人調用
 public function getCode(){
       
        $redis= new Redis();
        $yzmRedisKey ='GZHsoftwareinterface'.date("Y-m-d");
        if(!$redis->has($yzmRedisKey)){
            $times = 86400;
            $yzmCode=ToolsModel::random_str(6,1);
            $redis->set($yzmRedisKey,$yzmCode,$times);

        }
        $yzmCode = $redis->get($yzmRedisKey);
        return $yzmCode;
    }
    //用於網頁調用
    public function index()
    {
        if (request()->isPost()){
            $data = json_decode(file_get_contents('php://input'),true);
            isset($data['password'])?$password = $data['password']:exit(json_encode(array('code'=>0,'msg'=>'驗證碼不能為空')));
            $redis = new Redis();
            $yzmRedisKey = 'GZHsoftwareinterface'.date("Y-m-d");//存儲有效驗證碼
            $redisKey = 'GZHyzms'.Tools::GetIp().date("Y-m-d");//存儲同一個獲取次數 防止惡意掃描
            $sd = $redis->get($redisKey);
            if (empty($sd)){
                $sd =1;
                $redis->set($redisKey,$sd,86400);
            }else{
                $redis->inc($redisKey);
            }
            if ($sd>100){
                $data = array(
                    'code'=>0,
                    'msg'=>'今日驗證碼次數已超過100次',
                );
                return json_encode($data);
            }
            $yzmCode = $redis->get($yzmRedisKey);
            if(empty($yzmCode)){
                $yzmCode = Tools::random_str(6,1);
                $redis->set($yzmRedisKey,$yzmCode,86400);
            }
            if ($yzmCode==$password && !empty($password)){
                $data = array(
                    'code'=>200,
                    'msg'=>'驗證碼正確',
                );
                return json_encode($data);
            }else{
                $data = array(
                    'code'=>0,
                    'msg'=>'驗證碼錯誤',
                );
                return json_encode($data);
            }
        }
        header("HTTP/1.1 403 FORBIDDEN");
        header("Status: 403 FORBIDDEN");
        throw new \think\exception\HttpException(403, '~~~非法請求~~~');
        return;
    }
}

示例網址

https://pan.metanetdisk.com/

本人作者

Soujer

user avatar eolink 頭像 hsr2022 頭像 limingxin 頭像 yanping_5ca1d91415e55 頭像 banni99 頭像
點贊 5 用戶, 點贊了這篇動態!
點贊

Add a new 評論

Some HTML is okay.