总结分享-Wireshark远程抓包配置方法

云原生知识说科技2024-05-26 18:01:54  70

需求背景需要实时看到业务环境里的抓包结果,查看资料[1,2],了解到有两种配置方法:

方案1:利用wireshark的远程接口功能方案2:利用wireshrk的SSH remote capture功能利用远程接口功能1.安装依赖包

yum install glibc-static2.下载rpcapd的源码包

下载跟wireshark版本相近的4.0.1-WpcapSrc.zip[3]

3.编译配置

[root@node1 ~]# CFLAGS=-static ./configure...checking for flex... nochecking for bison... nochecking for capable lex... insufficientconfigure: 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 . 根据报错信息,安装缺少的相关依赖包:

yum install flex bison编译报错:

[root@node1 libpcap]# makegcc -O2 -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" @V_HAVE_REMOTE@ -c ./pcap-linux.cgcc: 错误:@V_HAVE_REMOTE@:没有那个文件或目录make: *** [pcap-linux.o] 错误 1 重新下载4.1.1-WpcapSrc.zip源码包,编译成功:

[root@node1 libpcap]# makegcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap-linux.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap-usb-linux.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./fad-getad.csed -e 's/.*/static const char pcap_version_string[] = "libpcap version &";/' ./VERSION > version.hgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./inet.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./gencode.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./optimize.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./nametoaddr.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./etherent.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./savefile.crm -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.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./bpf_image.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./bpf_dump.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c scanner.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -Dyylval=pcap_lval -c grammar.csed -e 's/.*/char pcap_version[] = "&";/' ./VERSION > version.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c version.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap-new.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./pcap-remote.cgcc -O2 -fPIC -static -I. -DHAVE_CONFIG_H -D_U_="__attribute__((unused))" -DHAVE_REMOTE -c ./sockutils.car 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.oranlib libpcap.ased -e 's|@includedir[@]|/usr/local/include|g' -e 's|@libdir[@]|/usr/local/lib|g' -e 's|@DEPLIBS[@]||g' pcap-config.in >pcap-config.tmpmv pcap-config.tmp pcap-configchmod a+x pcap-config[root@node1 libpcap]#[root@node1 libpcap]# cd rpcapd[root@node1 rpcapd]# makegcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c rpcapd.cgcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c daemon.cdaemon.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.cgcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c fileconf.cgcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c ../pcap-remote.cgcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c ../sockutils.cgcc -pthread -DHAVE_REMOTE -DHAVE_SNPRINTF -I../ -c ../pcap-new.cgcc -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服务

[root@node1 rpcapd]# ./rpcapd -4 -n -p 2002Press CTRL + C to stop the server... 查看监听结果

[root@node1 ~]# netstat -anp|grep -w 2002tcp 0 0 0.0.0.0:2002 0.0.0.0:* LISTEN 28399/./rpcapd 启动Wireshark,在Wireshark的捕获->选项->管理接口->远程接口页面下新增主机和端口,提示错误“PCAP没有发现”,查看资料[4],需要下载npcap解决。

远程接口连接后,后台提示如下错误:

[root@node1 rpcapd]# ./rpcapd -4 -n -p 2002Press CTRL + C to stop the server... Not enough space in the temporary send buffer按照资料[4]的解决方法,Wireshark页面配置后提示超时,后台依然报错:

[root@node1 rpcapd]# ./rpcapd -n -p 2002Press CTRL + C to stop the server... Not enough space in the temporary send buffer.The RPCAP runtime timeout has expiredI'm exiting from the child loopChild 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

转载此文是出于传递更多信息目的。若来源标注错误或侵犯了您的合法权益,请与本站联系,我们将及时更正、删除、谢谢。
https://www.414w.com/read/590483.html
0
最新回复(0)