需求背景 需要实时看到业务环境里的抓包结果,查看资料[1,2],了解到有两种配置方法:
方案1:利用wireshark的远程接口功能
方案2:利用wireshrk的SSH remote capture功能
利用远程接口功能 1.安装依赖包
1 yum install glibc-static
2.下载rpcapd的源码包
下载跟wireshark版本相近的4.0.1-WpcapSrc.zip[3]
3.编译配置
1 2 3 4 5 6 7 8 9 [root@node1 ~] ... checking for flex... no checking for bison... no checking for capable lex... insufficient configure: error: Your operating system's lex is insufficient to compile libpcap. flex is a lex replacement that has many advantages, including being able to compile libpcap. For more information, see http://www.gnu.org/software/flex/flex.html .
根据报错信息,安装缺少的相关依赖包:
编译报错:
1 2 3 4 [root@node1 libpcap] gcc -O2 -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" @V_HAVE_REMOTE@ -c ./pcap-linux.c gcc: 错误:@V_HAVE_REMOTE@:没有那个文件或目录 make: *** [pcap-linux.o] 错误 1
重新下载4.1.1-WpcapSrc.zip源码包,编译成功:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 [root@node1 libpcap] gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap-linux.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap-usb-linux.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./fad-getad.c sed -e 's/.*/static const char pcap_version_string[] = "libpcap version &";/' ./VERSION > version.h gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./inet.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./gencode.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./optimize.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./nametoaddr.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./etherent.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./savefile.c rm -f bpf_filter.cln -s ./bpf/net/bpf_filter.c bpf_filter.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c bpf_filter.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./bpf_image.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./bpf_dump.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c scanner.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -Dyylval=pcap_lval -c grammar.c sed -e 's/.*/char pcap_version[] = "&";/' ./VERSION > version.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c version.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap-new.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap-remote.c gcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./sockutils.c ar rc libpcap.a pcap-linux.o pcap-usb-linux.o fad-getad.o pcap.o inet.o gencode.o optimize.o nametoaddr.o etherent.o savefile.o bpf_filter.o bpf_image.o bpf_dump.o scanner.o grammar.o version.o pcap-new.o pcap-remote.o sockutils.o ranlib libpcap.a sed -e 's|@includedir[@]|/usr/local/include|g' \ -e 's|@libdir[@]|/usr/local/lib|g' \ -e 's|@DEPLIBS[@]||g' \ pcap-config.in >pcap-config.tmp mv pcap-config.tmp pcap-configchmod a+x pcap-config[root@node1 libpcap] [root@node1 libpcap] [root@node1 rpcapd] gcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c rpcapd.c gcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c daemon.c daemon.c: 在函数‘daemon_AuthUserPwd’中: daemon.c:684:30: 警告:将一个整数转换为大小不同的指针 [-Wint-to-pointer-cast] if (strcmp(usersp->sp_pwdp, (char *) crypt(password, usersp->sp_pwdp) ) != 0) ^ gcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c utils.c gcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c fileconf.c gcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c ../pcap-remote.c gcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c ../sockutils.c gcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c ../pcap-new.c gcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -o rpcapd rpcapd.o daemon.o utils.o fileconf.o pcap-remote.o sockutils.o pcap-new.o -L../ -lpcap -lcrypt
启动rpcapd服务
1 2 [root@node1 rpcapd] Press CTRL + C to stop the server...
查看监听结果
1 2 [root@node1 ~] tcp 0 0 0.0.0.0:2002 0.0.0.0:* LISTEN 28399/./rpcapd
启动Wireshark,在Wireshark的捕获->选项->管理接口->远程接口页面下新增主机和端口,提示错误“PCAP没有发现”,查看资料[4],需要下载npcap解决。
远程接口连接后,后台提示如下错误:
1 2 3 [root@node1 rpcapd] Press CTRL + C to stop the server... Not enough space in the temporary send buffer
按照资料[4]的解决方法,Wireshark页面配置后提示超时,后台依然报错:
1 2 3 4 5 6 [root@node1 rpcapd] Press CTRL + C to stop the server... Not enough space in the temporary send buffer. The RPCAP runtime timeout has expired I'm exiting from the child loop Child terminated
考虑到该方法依赖rpcapd,且该依赖包需要在相同的环境下编译,暂不采用。
利用SSH remote capture功能 启动Wireshark,在Wireshark的捕获->选项->输入页面下找到SSH remote capture,点击左侧的设置图标,打开ssh登录设置。
在弹出页面上配置ssh的连接参数,包括服务器地址,端口,用户名,密码(也可以用证书)等等。
配置完成后,点击开始按钮,开始远程抓包。
参考资料 1.https://zhuanlan.zhihu.com/p/551549544
2.https://blog.csdn.net/weixin_40991654/article/details/126779792
3.https://www.winpcap.org/archive/
4.https://blog.csdn.net/m0_37678467/article/details/127940287