Closed boost2020 closed 5 months ago
上面使用代码看起来很乱,我再截一些图:
使用自己修改代码后的运行截图:
使用0.82的官方版本:
使用0.76的官方版本:
nginx相关加载lib
ecapture加载的ebpf
改动的代码:
补丁打的没错,运行也没错。看上去是没触发相应hook点? 你可以开启DEBUG模式分析。
DEBUG=1 make nocore
sudo ecapture ...
查看内核的trace日志
cat /sys/kernel/debug/tracing/trace_pipe
另外,我增加了对非android boringssl的日志,见 #555 。不过,boringssl 的版本管理是混乱的,分为 Android 版本和非 Android 版本,对应两个不同的代码仓库。同时,每次发新版,版本号不变,OPENSSL_VERSION_TEXT
的内容没有被修改过。
导致eCapture无法读取动态链接库里的符号信息,来查找这个字段,用于识别对应版本。因此,如果你希望 eCapture 更好地支持非 Android 的 boringssl,你需要自己确认版本的匹配情况。必要时,你需要自己打补丁。
好的,我晚点打开 debug 再看看效果。
@boost2020 开了debug,但貌似不work,没有找到原因
编译环境
fatal: unknown date format format:%Y%m%d
---------------------------------------
eCapture Makefile Environment:
---------------------------------------
PARALLEL 2
----------------[ from args ]---------------
CROSS_ARCH
ANDROID 0
DEBUG 1
SNAPSHOT_VERSION
---------------------------------------
HOST_ARCH x86_64
UNAME_R 4.19.91-27.7.al7.x86_64
CLANG_VERSION 10
GO_VERSION 1.22
---------------------------------------
CMD_CLANG clang
CMD_GIT git
CMD_GO go
CMD_INSTALL install
CMD_LLC llc
CMD_MD5 md5sum
CMD_PKGCONFIG pkg-config
CMD_STRIP llvm-strip
CMD_CC_PREFIX
CMD_TAR tar
CMD_RPMBUILD rpmbuild
CMD_RPM_SETUP_TREE rpmdev-setuptree
---------------------------------------
VERSION_NUM 0.8.2--8e25629
LAST_GIT_TAG 0.8.2--8e25629
BPF_NOCORE_TAG 4_19_91-27_7_al7_x86_64.0_8_2--8e25629
KERN_RELEASE 4.19.91-27.7.al7.x86_64
KERN_BUILD_PATH /lib/modules/4.19.91-27.7.al7.x86_64/build
KERN_SRC_PATH /lib/modules/4.19.91-27.7.al7.x86_64/source
TARGET_ARCH x86_64
GOARCH amd64
LINUX_ARCH x86
LIBPCAP_ARCH x86_64-pc-linux-gnu
AUTOGENCMD test -f kern/bpf/x86/vmlinux.h || bpftool btf dump file /sys/kernel/btf/vmlinux format c > kern/bpf/x86/vmlinux.h
PACKAGE_VERSION 0.0.0
OUT_DEB_FILE ./bin/ecapture_v0.0.0_linux_amd64.deb
运行环境
2024-05-26T23:01:25+08:00 INF AppName="eCapture(旁观者)"
2024-05-26T23:01:25+08:00 INF HomePage=https://ecapture.cc
2024-05-26T23:01:25+08:00 INF Repository=https://github.com/gojue/ecapture
2024-05-26T23:01:25+08:00 INF Author="CFC4N <cfc4ncs@gmail.com>"
2024-05-26T23:01:25+08:00 INF Description="Capturing SSL/TLS plaintext without a CA certificate using eBPF. Supported on Linux/Android kernels for amd64/arm64."
2024-05-26T23:01:25+08:00 INF Version=linux_amd64:0.8.2--8e25629:x86_64
2024-05-26T23:01:25+08:00 INF listen=localhost:28256
2024-05-26T23:01:25+08:00 INF https server starting...You can update the configuration file via the HTTP interface.
2024-05-26T23:01:25+08:00 WRN ========== module starting. ==========
2024-05-26T23:01:25+08:00 INF Kernel Info=4.19.132 Pid=10485
2024-05-26T23:01:25+08:00 INF BTF bytecode mode: non-CORE. btfMode=2
2024-05-26T23:01:25+08:00 INF master key keylogger has been set. eBPFProgramType=KeyLog keylogger=ecapture_openssl_key.og
2024-05-26T23:01:25+08:00 INF module initialization. isReload=false moduleName=EBPFProbeOPENSSL
2024-05-26T23:01:25+08:00 INF Module.Run()
2024-05-26T23:01:25+08:00 INF OpenSSL/BoringSSL version found sslVersion="boringssl na"
2024-05-26T23:01:25+08:00 INF HOOK type:Openssl elf ElfType=2 binrayPath=/usr/lib/x86_64-linux-gnu/libssl.so.1.1 masterHookFuncs=["SSL_in_init"]
2024-05-26T23:01:25+08:00 INF setupManagers eBPFProgramType=KeyLog
2024-05-26T23:01:25+08:00 INF BPF bytecode file is matched. bpfFileName=user/bytecode/boringssl_na_kern_noncore_less52.o
2024-05-26T23:01:25+08:00 INF perfEventReader created mapSize(MB)=4
2024-05-26T23:01:25+08:00 INF module started successfully. isReload=false moduleName=EBPFProbeOPENSSL
strings ecapture-na-0526|grep -i "client_version"
这条命令是用来干什么的?
可以取出bin中所有的变量里面的字面值,
另外我这个问题真还可能是另外的问题了,我用 bpftrace -e 'uprobe:/usr/lib/x86_64-linux-gnu/libssl.so.1.1:SSL_write .....’ bpftrace -e 'uprobe:/usr/lib/x86_64-linux-gnu/libssl.so.1.1:SSL_INIT ....‘ 挨个试了,都没有捕获到任何输出,感觉这个nginx使用的ssl有点诡异,
我在同一台主机发出curl时(作为客户端 随便发出一个https请求) 是能hook到的,
所以确实应该还有可能是这个nginx的hook点不对,我再研究一下。
终于知道原因了,openresty把ssl静态编译进了nginx. bad luck!
可以直接把libssl参数设定为nginx路径。
这个issue感觉可以先关,不然会没完没了
直接指定ng的路径报下面的错:
./ecapture-na-0526 tls -m key --ssl_version="boringssl na" -b 2 --libssl="/usr/local/openresty/openssl111/lib/libssl.a"
2024-05-29T21:31:48+08:00 INF AppName="eCapture(旁观者)"
2024-05-29T21:31:48+08:00 INF HomePage=https://ecapture.cc
2024-05-29T21:31:48+08:00 INF Repository=https://github.com/gojue/ecapture
2024-05-29T21:31:48+08:00 INF Author="CFC4N <cfc4ncs@gmail.com>"
2024-05-29T21:31:48+08:00 INF Description="Capturing SSL/TLS plaintext without a CA certificate using eBPF. Supported on Linux/Android kernels for amd64/arm64."
2024-05-29T21:31:48+08:00 INF Version=linux_amd64:0.8.2--8e25629:x86_64
2024-05-29T21:31:48+08:00 WRN ========== module starting. ==========
2024-05-29T21:31:48+08:00 INF Kernel Info=4.19.132 Pid=61315
2024-05-29T21:31:48+08:00 INF BTF bytecode mode: non-CORE. btfMode=2
2024-05-29T21:31:48+08:00 INF master key keylogger has been set. eBPFProgramType=KeyLog keylogger=ecapture_openssl_key.og
2024-05-29T21:31:48+08:00 INF module initialization. isReload=false moduleName=EBPFProbeOPENSSL
2024-05-29T21:31:48+08:00 INF Module.Run()
2024-05-29T21:31:48+08:00 INF OpenSSL/BoringSSL version found sslVersion="boringssl na"
2024-05-29T21:31:48+08:00 INF HOOK type:Openssl elf ElfType=2 binrayPath=/usr/local/openresty/openssl111/lib/libssl.a masterHookFuncs=["SSL_in_init"]
2024-05-29T21:31:48+08:00 INF setupManagers eBPFProgramType=KeyLog
2024-05-29T21:31:48+08:00 INF BPF bytecode file is matched. bpfFileName=user/bytecode/boringssl_na_kern_noncore_less52.o
2024-05-29T21:31:48+08:00 INF listen=localhost:28256
2024-05-29T21:31:48+08:00 INF https server starting...You can update the configuration file via the HTTP interface.
2024-05-29T21:31:48+08:00 FTL module run failed, skip it. error="couldn't start bootstrap manager error:1 error occurred:\n\t* error:error:parse ELF file: bad magic number '[33 60 97 114]' in record at byte 0x0 , couldn't enable uprobe probe_ssl_master_key, {UID:uprobe_smk_SSL_in_init, EbpfFuncName:probe_ssl_master_key}\n\n, probes activation validation failed ." isReload=false
root@al-001:~# ./ecapture-na-0526 tls -m key --ssl_version="boringssl na" -b 2 --libssl="/usr/local/openresty/nginx/sbin/nginx"
2024-05-29T21:32:01+08:00 INF AppName="eCapture(旁观者)"
2024-05-29T21:32:01+08:00 INF HomePage=https://ecapture.cc
2024-05-29T21:32:01+08:00 INF Repository=https://github.com/gojue/ecapture
2024-05-29T21:32:01+08:00 INF Author="CFC4N <cfc4ncs@gmail.com>"
2024-05-29T21:32:01+08:00 INF Description="Capturing SSL/TLS plaintext without a CA certificate using eBPF. Supported on Linux/Android kernels for amd64/arm64."
2024-05-29T21:32:01+08:00 INF Version=linux_amd64:0.8.2--8e25629:x86_64
2024-05-29T21:32:01+08:00 INF listen=localhost:28256
2024-05-29T21:32:01+08:00 INF https server starting...You can update the configuration file via the HTTP interface.
2024-05-29T21:32:01+08:00 WRN ========== module starting. ==========
2024-05-29T21:32:01+08:00 INF Kernel Info=4.19.132 Pid=61357
2024-05-29T21:32:01+08:00 INF BTF bytecode mode: non-CORE. btfMode=2
2024-05-29T21:32:01+08:00 INF master key keylogger has been set. eBPFProgramType=KeyLog keylogger=ecapture_openssl_key.og
2024-05-29T21:32:01+08:00 INF module initialization. isReload=false moduleName=EBPFProbeOPENSSL
2024-05-29T21:32:01+08:00 INF Module.Run()
2024-05-29T21:32:01+08:00 INF OpenSSL/BoringSSL version found sslVersion="boringssl na"
2024-05-29T21:32:01+08:00 INF HOOK type:Openssl elf ElfType=2 binrayPath=/usr/local/openresty/nginx/sbin/nginx masterHookFuncs=["SSL_in_init"]
2024-05-29T21:32:01+08:00 INF setupManagers eBPFProgramType=KeyLog
2024-05-29T21:32:01+08:00 INF BPF bytecode file is matched. bpfFileName=user/bytecode/boringssl_na_kern_noncore_less52.o
2024-05-29T21:32:01+08:00 FTL module run failed, skip it. error="couldn't start bootstrap manager error:1 error occurred:\n\t* error:opening uprobe: symbol SSL_in_init: not found , isRet:false, opts:&{0 0 0 0 0 }, {UID:uprobe_smk_SSL_in_init, EbpfFuncName:probe_ssl_master_key}\n\n, probes activation validation failed ." isReload=false
openresty静态编译ssl的证据
使用bpftrace无法hook静态库
readelf -s /usr/local/openresty/openssl111/lib/libssl.a|grep SSL_do_handshake
43: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND SSL_do_handshake
306: 0000000000004630 218 FUNC GLOBAL DEFAULT 1 SSL_do_handshake
bpftrace -e 'uprobe:/usr/local/openresty/openssl111/lib/libssl.a:SSL_do_handshake{printf("test is ok/n")}'
Attaching 1 probe...
Could not resolve symbol: /usr/local/openresty/openssl111/lib/libssl.a:SSL_do_handshake
root@al--001:~# bpftrace -e 'uprobe:/usr/local/openresty/nginx/sbin/nginx:SSL_do_handshake{printf("test is ok/n")}'
Attaching 1 probe...
Could not resolve symbol: /usr/local/openresty/nginx/sbin/nginx:SSL_do_handshake
Describe the bug A clear and concise description of what the bug is. nginx使用了boringssl,使用0.76/0.82均无法正常捕获到key,看了一下代码应该是不支持,然后我简单修改了一下代码,但还是不能work,帮忙看看还有可能哪里的问题?
To Reproduce Steps to reproduce the behavior: 改动的代码如下:
Expected behavior 能捕获到key
Screenshots
shell
bpftool
Linux Server/Android (please complete the following information):