Skip to content

03 js调试技巧

找数据加密的位置

  1. 确定要找的参数
  2. 找到起始位置
  3. 跟调用堆栈
  4. 确定加密位置
  • xhr 断点 -> xhr提取断点
  • dom 断点 -> 定位元素 -> 监听点击事件

demo

04 HOOK技术

<img src="https://gitee.com/kualk/pic-go/raw/master/imgs/image-20250820111125814.png" alt="image-20250820111125814" />

debugger参考文档:https://www.cnblogs.com/liyuanhong/articles/18210072

web接口大全(看不懂js代码的时候搜查):Web API

写好了的hook代码直接用:JavaScript常用的Hook脚本 - 小伟哥哥~ - 博客园

npm源:npm config set registry https://registry.npm.taobao.org

加密的位置:

  1. 加载html
  2. 加载js代码
  3. 用户触发事件(ajax)
  4. 构造请求对象
  5. 请求拦截器
  6. 发送请求
  7. 返回数据
  8. 响应拦截器(解密)
  9. 请求成功的回调

构造debugger

  • 定时器
html
&lt;!DOCTYPE html>
  &lt;html lang="en">
  &lt;head>
      &lt;meta charset="UTF-8">
      &lt;title>Title&lt;/title>
  &lt;/head>
  
  &lt;h1 id="box">&lt;/h1>
  
  &lt;body>
  
  <script>
      var ss = document.getElementById('box')
      function ff() {
          debugger;
      }
      setInterval(ff,100);
  
      ss.innerHTML = "大家晚上好";
  
  </script>
  &lt;/body>
  &lt;/html>
  • 控制台监测
html
&lt;!DOCTYPE html>
  &lt;html lang="en">
  &lt;head>
      &lt;meta charset="UTF-8">
      &lt;title>Title&lt;/title>
  &lt;/head>
  &lt;body>
  
  <script>
      function resize(){
      var threshold = 200;
      var widthThreshold = window.outerWidth - window.innerWidth > threshold;
      var heightThreshold = window.outerHeight - window.innerHeight > threshold;
      if(widthThreshold || heightThreshold){
          debugger
          console.log('控制台打开了')
      }
  }
  setInterval(resize, 100)
  </script>
  hello
  &lt;/body>
  &lt;/html>
  • 构造器断点
html
&lt;!DOCTYPE html>
  &lt;html lang="en">
  &lt;head>
      &lt;meta charset="UTF-8">
      &lt;title>Title&lt;/title>
  &lt;/head>
  &lt;body>
  
  <script>
  function check() {
      function doCheck(a) {
          (function() {}["constructor"]("debugger")()); //debugger
          doCheck(++a);
      }
      try {
          doCheck(0)
      } catch(err) {
          console.log(err)
      }
  };
  check()
  
  variable = Function("debugger;");
  variable();
  </script>
  hello
  &lt;/body>
  &lt;/html>
  • HOOK跳过构造器debugger代码(异步生成的):
js
var _constructor = constructor;
  Function.prototype.constructor = function(s) {
      
      if ( s== "debugger") {
          console.log(s);
          return null;
      }
      return _constructor(s);
  }

跳过debugger

  • 不再此处暂停
  • 添加条件断点(False,拒绝执行)
  • 方法置空(将方法=null,会影响代码逻辑)
  • 替换文件(注释debugger,删代码)
  • 注入代码(if else跳过debugger的情况)

demo

05 JS调用和扣代码

调用js代码的方法

  • 包PyExecJS(同步库)
python
import execjs
print(execjs.get())  # 确保版本为Node.js(V8)
# 出现问题,重装pycharm
  • 使用进程库subprocess在终端调用js文件执行,捕捉执行结果(异步方法)(调用异步方法,打印结果。才能接收数据)
python
import subprocess
res = subprocess.run(['node', 'test.js'], capture_output=True, text=True)
print(res.stdout.strip())  # stdout:需要将结果输出到控制台
  • js库express 使用nodejs开发js接口进行调用js代码
shell
npm install express

加密算法

分类

  • 哈希算法

    • MD5(Message-Digest Algorithm)
      • 长度:32位
      • 数据:16进制
    • SHA
    • HMAC
  • 对称加密

  • 非对称加密

  • 安装库

shell
npm install crypto-js

拦截器类型

  • 请求拦截器
  • 发送请求
  • 响应拦截器

记录学习,分享技术