zu1k / Good-MITM

Rule-based MITM engine. Rewriting, redirecting and rejecting on HTTP(S) requests and responses, supports JavaScript rule.
https://good-mitm.zu1k.com
MIT License
801 stars 102 forks source link

[Bug] 用rules/js.yaml的例子启动报错! #69

Closed qwe1177 closed 1 year ago

qwe1177 commented 1 year ago

Verify steps

Version

0.4.2

What OS are you seeing the problem on?

Windows

Rule file

- name: "js_modify_request"
  mitm: "*"
  filters:
    url-regex: '^https?:\/\/www\.baidu\.com'
  actions:
    js: |
      function process() {
        console.log("from quick_js");

        if (data.request != undefined) {
          let req = data.request;
          console.log(req.headers["user-agent"]);
          return req;
        }
        if (data.response != undefined) {
          let res = data.response;
          if (res.body != undefined) {
            res.body = res.body.replaceAll("百度", "百毒");
          }
          return res;
        }
      }
      process()

log

D:/goodmitm> ./good-mitm.exe run -r rules                                                           10/08/23 14:59:01 PM
[2023-10-08T06:59:19Z INFO  good_mitm] CA Private key use: ca/private.key
[2023-10-08T06:59:19Z INFO  good_mitm] CA Certificate use: ca/cert.crt
[2023-10-08T06:59:19Z INFO  good_mitm] Http Proxy listen on: http://127.0.0.1:34567
[2023-10-08T06:59:19Z ERROR good_mitm::file] load rule (rules\js.yaml) failed: .[0]: data did not match any variant of untagged enum SingleOrMulti at line 1 column 3

[Bug] 用rules/js.yaml的例子启动报错!
我是用的例子跑的,跑起来就报错,我看下代码,问题在这里:
impl<T> From<SingleOrMulti<T>> for Vec<T> {
    fn from(sm: SingleOrMulti<T>) -> Vec<T> {
        match sm {
            SingleOrMulti::Single(v) => vec![v],
            SingleOrMulti::Multi(mv) => mv,
            **_ => vec![],**
        }
    }
}
是不是要做下兜底捕获,请尽快修复下BUG,谢谢!

Description

image

qwe1177 commented 1 year ago

我希望能通过某种rules来修改request header和body,通过哪些rules能实现呢,都尝试过,好像没办法修改。

zu1k commented 1 year ago

js 支持默认是关闭的,如果有需要请通过打开 js feature 自行编译

zu1k commented 1 year ago

我希望能通过某种rules来修改request header和body,通过哪些rules能实现呢,都尝试过,好像没办法修改。

这个是支持的,看你需要怎么修改,具体请看文档:https://good-mitm.zu1k.com/#/rule/modify

modify-response 修改为 modify-request 即可

zu1k commented 1 year ago

js 支持默认是关闭的,如果有需要请通过打开 js feature 自行编译

good-mitm_win.zip

qwe1177 commented 1 year ago

我希望能通过某种rules来修改request header和body,通过哪些rules能实现呢,都尝试过,好像没办法修改。

这个是支持的,看你需要怎么修改,具体请看文档:https://good-mitm.zu1k.com/#/rule/modify

modify-response 修改为 modify-request 即可

我尝试过把 modify-response 修改为 modify-request ,改header头一直没生效

action:

qwe1177 commented 1 year ago

js 支持默认是关闭的,如果有需要请通过打开 js feature 自行编译

good-mitm_win.zip

这个是编译好的默认开启支持 js feature 的包吗?我试试

qwe1177 commented 1 year ago

js 支持默认是关闭的,如果有需要请通过打开 js feature 自行编译

good-mitm_win.zip

Perfect,这个默认支持js

zu1k commented 1 year ago

我希望能通过某种rules来修改request header和body,通过哪些rules能实现呢,都尝试过,好像没办法修改。

这个是支持的,看你需要怎么修改,具体请看文档:https://good-mitm.zu1k.com/#/rule/modify modify-response 修改为 modify-request 即可

我尝试过把 modify-response 修改为 modify-request ,改header头一直没生效

这个不会体现在客户端,服务端能看到修改

qwe1177 commented 1 year ago

js 支持默认是关闭的,如果有需要请通过打开 js feature 自行编译

在哪里开启JS feature , 我看Cargo.toml 已经开启了 js = ["quick-js"] 还需要配置哪里吗? image 现在本地调试还是报错

zu1k commented 1 year ago

编译的时候 -F js 即可开启

qwe1177 commented 1 year ago

编译的时候 -F js 即可开启

我尝试本地编译后,出现了编译报错! perl也装了 , 用的是 stable-x86_64-pc-windows-gnu 工具链, 在编译到这个openssl-sys 的时候一直有问题!卡在这了居然,无语!

PS C:\rust\Good-MITM-0.4.2> cargo run Compiling openssl-sys v0.9.87 error: failed to run custom build command for openssl-sys v0.9.87

Caused by: process didn't exit successfully: C:\rust\Good-MITM-0.4.2\target\debug\build\openssl-sys-69504b32c82f9c65\build-script-main (exit code: 101) --- stdout cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_GNU_OPENSSL_NO_VENDOR X86_64_PC_WINDOWS_GNU_OPENSSL_NO_VENDOR unset cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR OPENSSL_NO_VENDOR unset cargo:rerun-if-env-changed=CC_x86_64-pc-windows-gnu CC_x86_64-pc-windows-gnu = None cargo:rerun-if-env-changed=CC_x86_64_pc_windows_gnu CC_x86_64_pc_windows_gnu = None cargo:rerun-if-env-changed=HOST_CC HOST_CC = None cargo:rerun-if-env-changed=CC CC = None cargo:rerun-if-env-changed=CFLAGS_x86_64-pc-windows-gnu CFLAGS_x86_64-pc-windows-gnu = None cargo:rerun-if-env-changed=CFLAGS_x86_64_pc_windows_gnu CFLAGS_x86_64_pc_windows_gnu = None cargo:rerun-if-env-changed=HOST_CFLAGS HOST_CFLAGS = None cargo:rerun-if-env-changed=CFLAGS CFLAGS = None cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None DEBUG = Some("true") CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2") cargo:rerun-if-env-changed=AR_x86_64-pc-windows-gnu AR_x86_64-pc-windows-gnu = None cargo:rerun-if-env-changed=AR_x86_64_pc_windows_gnu AR_x86_64_pc_windows_gnu = None cargo:rerun-if-env-changed=HOST_AR HOST_AR = None cargo:rerun-if-env-changed=AR AR = None cargo:rerun-if-env-changed=ARFLAGS_x86_64-pc-windows-gnu ARFLAGS_x86_64-pc-windows-gnu = None cargo:rerun-if-env-changed=ARFLAGS_x86_64_pc_windows_gnu ARFLAGS_x86_64_pc_windows_gnu = None cargo:rerun-if-env-changed=HOST_ARFLAGS HOST_ARFLAGS = None cargo:rerun-if-env-changed=ARFLAGS ARFLAGS = None cargo:rerun-if-env-changed=RANLIB_x86_64-pc-windows-gnu RANLIB_x86_64-pc-windows-gnu = None cargo:rerun-if-env-changed=RANLIB_x86_64_pc_windows_gnu RANLIB_x86_64_pc_windows_gnu = None cargo:rerun-if-env-changed=HOST_RANLIB HOST_RANLIB = None cargo:rerun-if-env-changed=RANLIB RANLIB = None cargo:rerun-if-env-changed=RANLIBFLAGS_x86_64-pc-windows-gnu RANLIBFLAGS_x86_64-pc-windows-gnu = None cargo:rerun-if-env-changed=RANLIBFLAGS_x86_64_pc_windows_gnu RANLIBFLAGS_x86_64_pc_windows_gnu = None cargo:rerun-if-env-changed=HOST_RANLIBFLAGS HOST_RANLIBFLAGS = None cargo:rerun-if-env-changed=RANLIBFLAGS RANLIBFLAGS = None running "perl" "./Configure" "--prefix=/C/rust/Good-MITM-0.4.2/target/debug/build/openssl-sys-469eb8e65dcee10b/out/openssl-build/install" "--openssldir=SYS$MANAGER:[OPENSSL]" "no-dso" "no-shared" "n o-ssl3" "no-unit-test" "no-comp" "no-zlib" "no-zlib-dynamic" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "no-engine" "mingw64" "-O2" "-ffunction-sections" "-fdata-sections" "-g dwarf-2" "-fno-omit-frame-pointer" "-m64" "-Wa,-mbig-obj" Configuring OpenSSL version 1.1.1t (0x1010114fL) for mingw64 Using os-specific seed configuration

--- stderr


This perl implementation doesn't produce Unix like paths (with forward slash directory separators). Please use an implementation that matches your building platform.

This Perl version: 5.32.1 for MSWin32-x64-multi-thread


thread 'main' panicked at C:\Users\Administrator.cargo\registry\src\index.crates.io-6f17d22bba15001f\openssl-src-111.25.3+1.1.1t\src\lib.rs:506:13:

Error configuring OpenSSL build: Command: "perl" "./Configure" "--prefix=/C/rust/Good-MITM-0.4.2/target/debug/build/openssl-sys-469eb8e65dcee10b/out/openssl-build/install" "--openssldir=SYS$MANAGER:[OPENSSL]" "no-dso" "no-share d" "no-ssl3" "no-unit-test" "no-comp" "no-zlib" "no-zlib-dynamic" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "no-engine" "mingw64" "-O2" "-ffunction-sections" "-fdata-sections " "-gdwarf-2" "-fno-omit-frame-pointer" "-m64" "-Wa,-mbig-obj" Exit status: exit code: 255

note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

zu1k commented 1 year ago
  1. 查看文档: https://docs.rs/openssl/latest/openssl/
  2. 安装 OpenSSL 库
  3. 删除 vendored feature
qwe1177 commented 1 year ago
  1. 查看文档: https://docs.rs/openssl/latest/openssl/
  2. 安装 OpenSSL 库
  3. 删除 vendored feature

真坑啊 搞了好久,发现是版本perl 的版本问题,已经OK了