sdenv获取瑞数6后缀

使用草木一秋大佬的项目:https://github.com/pysunday/sdenv

孪生项目:https://github.com/pysunday/rs-reverse

本人使用的是docker映射本地文件的方式在Linux运行

主要逻辑:

  • 在加载网页内部js(瑞数初始化)前重写open,因为瑞数js关于后缀的open是已经重写的,所以要在瑞数重写open之前重写open
  • 瑞数初始化以后,再手动发起请求

步骤:

  • 将项目克隆到Linux,cd进入sdenv
  • 修改/example/use-remote/index.js

 重写loadPagesSecond

 const {window, sdenv} = await jsdomFromUrl(url, {
        cookieJar,
        userAgent,
        consoleConfig: {error: new Function},
    });

    /*
    === 重写 XMLHttpRequest,只拦截,不请求 ===
    因为瑞数后缀是重写了open,所以要在瑞数重写之前重写open
     */
    const originalOpen = window.XMLHttpRequest.prototype.open;

    window.XMLHttpRequest.prototype.open = function (method, requestUrl, async, user, password) {
        this._requestUrl = requestUrl;
        this._method = method;

        // 关键:彻底阻止 send,替换为空函数
        this.send = function (body) {
           logger.info(`[拦截成功] URL: ${this._requestUrl}`);

            // 模拟一个“完成”状态,防止页面卡死
            setTimeout(() => {
                this.readyState = 4;
                this.status = 0;  // 或 200,取决于想模拟什么
                if (this.onreadystatechange) {
                    this.onreadystatechange();
                }
            }, 0);
        };

        return originalOpen.call(this, method, requestUrl, async, user, password);
    };

 新增手动发送请求代码(只获取URL,不发送请求),借鉴了草木一秋大佬的代码

// 手动发起请求 xhr 触发重写的 open 和 send
    const xhr = new window.XMLHttpRequest();
    xhr.open("POST", 'http://epub.cnipa.gov.cn/Dxb/PageQuery', false);
    xhr.setRequestHeader('Accept', 'application/json');

    xhr.onreadystatechange = function () {
        // 此时的responseURL和responseText应该都为空,因为已经被重写的open拦截
        logger.debug("url:", xhr.responseURL);
        logger.debug("responseText:", xhr.responseText);
        // 状态变化: 1 0  1是被拦截,4是未拦截
        logger.debug('状态变化:', xhr.readyState, xhr.status);
    };

    try {
        xhr.send(); // 触发定义的日志
    } catch (e) {
        logger.error('发送请求失败:', e);
    }
  • docker运行
docker run --rm -v $(pwd)/example/use-remote:/app crpi-vkjftqt0qsdk2jmc.cn-shanghai.personal.cr.aliyuncs.com/pysunday/sdenv-x86_64:1.0.0 /app/index.js

image

posted @ 2025-10-31 10:16  A肆  阅读(92)  评论(0)    收藏  举报