惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CERT Recently Published Vulnerability Notes
V
Vulnerabilities – Threatpost
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Schneier on Security
Schneier on Security
T
Threatpost
P
Proofpoint News Feed
MongoDB | Blog
MongoDB | Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
大猫的无限游戏
大猫的无限游戏
T
Threat Research - Cisco Blogs
罗磊的独立博客
Security Latest
Security Latest
D
Docker
S
Secure Thoughts
博客园 - 聂微东
A
Arctic Wolf
Recorded Future
Recorded Future
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
P
Palo Alto Networks Blog
Project Zero
Project Zero
Blog — PlanetScale
Blog — PlanetScale
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
T
The Blog of Author Tim Ferriss
Latest news
Latest news
AWS News Blog
AWS News Blog
U
Unit 42
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
F
Full Disclosure
Martin Fowler
Martin Fowler
T
The Exploit Database - CXSecurity.com
Attack and Defense Labs
Attack and Defense Labs
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
V
V2EX
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
小众软件
小众软件
宝玉的分享
宝玉的分享

拓源网

微信和QQ访问页面提示使用右上角浏览器打开 - 拓源网 批量替换文件名的powershell脚本 - 拓源网 使用Python移除PDF编辑权限密码 - 拓源网 写一款《PPT将指定页面另存为》小工具 - 拓源网 让jquery代码只能在指定域名下运行的三种方法 - 拓源网 PPT拼图批量生成工具 - 拓源网 Deepseek微信聊天机器人 - 拓源网 使用Python自动抓取zblog文章到腾讯云大模型知识引擎LKE,投喂数据专属化自己的知识库 - 拓源网 deepseek生图指令 - 拓源网
[反调试]审查元素清空页面或重定向 - 拓源网
2025-08-21 · via 拓源网

为防止用户通过浏览器审查元素代码,以保护网页内容的安全性和隐私性。以下是一个反调试示例代码,可以阻止用户通过审查元素查看网页源代码,变量为1时清空页面内容,变量为2时重定向到指定页面。

反调试脚本

function checkDevTools() {
    const threshold = 160;
    const devtoolsOpen = window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold;
    if (devtoolsOpen) {
        /*
        *   debugprotect =
        *   1: 审查元素时->[清空页面内容]
        *   2: 审查元素时->[重定向到指定页面]
        */
        const debugprotect = '1';
        switch (debugprotect) {
            case '1':
                document.documentElement.parentNode.replaceChild(document.createElement('html'), document.documentElement);
                break;
            case '2':
                window.location.href = 'https://www.toyean.com/';
                break;
        }
    }
}
setInterval(checkDevTools, 100);

完整代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>[反调试]审查元素清空页面或重定向-拓源网</title>
    <script>
        function checkDevTools() {
            const threshold = 160;
            const devtoolsOpen = window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold;
            if (devtoolsOpen) {
                /*
                *   debugprotect =
                *   1: 审查元素时->[清空页面内容]
                *   2: 审查元素时->[重定向到指定页面]
                */
                const debugprotect = '1';
                switch (debugprotect) {
                    case '1':
                        document.documentElement.parentNode.replaceChild(document.createElement('html'), document.documentElement);
                        break;
                    case '2':
                        window.location.href = 'https://www.toyean.com/';
                        break;
                }
            }
        }
        setInterval(checkDevTools, 100);
    </script>
</head>
<body>
    <p>热爱可抵 岁月漫长!</p>
</body>
</html>

猛戳查看->演示效果

需要注意的是,反调试方法并非绝对可靠,一些高级用户仍可能绕过限制。

以下是绕过限制的方法介绍,和升级后的反调试代码,增加了performance检测、禁用鼠标右键、禁用选中文本、禁用复制文本、无限debugger、以及禁用调试快捷键等:

呜呼~~ 您需要有拓源网 VIP会员 账号,并且 登录 后即可查看或下载隐藏部分的内容.