设为首页 收藏本站
查看: 3139|回复: 0

[经验分享] linux主机上编译安装rpcapd实现wireshark远程抓包功能

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-2 09:31:26 | 显示全部楼层 |阅读模式
简介
        由于在做分布式HLR时,需要一边测试,一边抓取信令消息,而现在分布式HLR的系统都是采用linux,抓包可以使用tcpdump工具,不过感觉不是很方便。正好,之前的测试的同事,已经实现了使用笔记本上的wireshark远程抓包,而我以前对此没有做过了解,不是很懂,抽空在网上查了查资料,大概屡清楚了实现方法。实现远程抓包,主要借助winpacp这个软件中的rpcapd工具,这里就对在linux下的rpcapd工具的安装,使用和windows下的wireshark使用做简要介绍。
        rpcapd原理非常简单:其是 RemotePacket CaptureDaemon的缩写,这是winpacp软件附带的一个工具。它可以实现在本地linux系统下打开一个端口,接收监控端发送来的命令,来捕获本地的数据包,并通过网络传给监控端,这样wireshark就可以实现远程抓包。
        测试环境:使用了和分布式HLR抓包时一样的环境,windows主机一台为真实宿主机,安装wireshark软件,linux主机两台,使用centos6.4(DHLR使用的是RHEL6.5,这都没有关系,使用其他发行版本的linux也是一样的)为虚拟机实现,linux需要安装rpcapd工具,宿主机和虚拟机之间使用网络连接使用网卡的桥接模式,两台虚拟机之间的网卡使用自定义方式,连接到同一个vmnet。这样windows主机通过桥接的网卡连接到虚拟机1,然后抓取两台虚拟机之间的数据包即完成了远程抓包。        

安装rpcapd
        在centos自带的yum源中没找到和rpcapd相关的pacp的软件包,而且winpcap软件本来就是用于windows平台的程序,因此如果想在linux下使用远程抓包,就只能找到其源代码包来安装了。我们可以到http://www.winpcap.org/install/bin/WpcapSrc_4_1_3.zip这里下载最新的winpcap源代码包,到http://www.winpcap.org/docs/docs_412/html/group__remote.html这里查看相关的安装和使用的文档说明。
        安装步骤:
  • 将WpcapSrc压缩文件复制到任意目录下,通常放在/root目录下,然后使用unzip解压缩

[iyunv@base ~]# unzip -aWpcapSrc_4_1_3.zip
Archive:  WpcapSrc_4_1_3.zip
creating: winpcap/
inflating:winpcap/build_wpdpack.bat  [text]  
inflating:winpcap/build_wpdpack.txt  [text]  
…………………………
inflating:winpcap/wpcap/Win32-Extensions/Win32-Extensions.h  [text]  
可以发现在/root目录下会生成winpcap目录
[iyunv@base ~]# ll /root/
total 89616
-rw-------.  1 root root     1013 Apr 13  2014 anaconda-ks.cfg
-rw-r--r--.  1 root root    19546 Apr 13  2014 install.log
-rw-r--r--.  1 root root     4670 Apr 13  2014 install.log.syslog
drwxr-xr-x.  9 root root     4096 Feb 28  2013 winpcap
-rwxr-xr-x.  1 root root  3833073 Nov  9 21:04 WpcapSrc_4_1_2.zip
-rwxr-xr-x. 1 root root   3834716 Nov  9 22:29 WpcapSrc_4_1_3.zip
  • 进入到/root/winpcap/wpcap/libpcap/这个目录,给目录下的configure文件添加执行权限

[iyunv@baselibpcap]#cd /root/winpcap/wpcap/libpcap/
[iyunv@baselibpcap]# ll configure
-rw-r--r--.1 root root 300261 Feb 28  2013 configure
[iyunv@baselibpcap]# chmod +x configure
[iyunv@baselibpcap]# ll configure
-rwxr-xr-x.1 root root 300261 Feb 28  2013 configure
  • 运行./configure来进行编译前检查及准备工作,并检查执行的结果中是否有错误

[iyunv@base libpcap]# ./configure--prefix=/usr/local/winpcap --sysconfdir=/etc/winpcap
checking build system type...x86_64-unknown-linux-gnu
checking host system type...x86_64-unknown-linux-gnu
checking target system type...x86_64-unknown-linux-gnu
checking for gcc... gcc
…………..
config.status: creating Makefile
config.status: creatingpcap-filter.manmisc
config.status: creatingpcap-linktype.manmisc
config.status: creatingpcap-savefile.manfile
config.status: creatingpcap.3pcap
config.status: creatingpcap_compile.3pcap
config.status: creatingpcap_datalink.3pcap
config.status: creatingpcap_dump_open.3pcap
config.status: creatingpcap_list_datalinks.3pcap
config.status: creatingpcap_open_dead.3pcap
config.status: creatingpcap_open_offline.3pcap
                config.status:creating config.h
  • 运行make开始编译winpcap软件包并检查编译的输出中是否有错误

[iyunv@base libpcap]# make
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./pcap-linux.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./pcap-usb-linux.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./fad-getad.c
sed -e 's/.*/static const charpcap_version_string[] = "libpcap version &";/'./VERSION > version.h
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./pcap.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./inet.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./gencode.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./optimize.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./nametoaddr.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./etherent.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./savefile.c
rm -f bpf_filter.c
ln -s ./bpf/net/bpf_filter.cbpf_filter.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c bpf_filter.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./bpf_image.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./bpf_dump.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c scanner.c
gcc -O2 -fPIC -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 -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c version.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./pcap-new.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./pcap-remote.c
gcc -O2 -fPIC -I. -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))"-DHAVE_REMOTE  -c ./sockutils.c
ar rc libpcap.a pcap-linux.opcap-usb-linux.o fad-getad.o pcap.o inet.o gencode.o optimize.onametoaddr.o etherent.o savefile.o bpf_filter.o bpf_image.obpf_dump.o  scanner.o grammar.o version.o  pcap-new.o pcap-remote.osockutils.o  
ranlib libpcap.a
sed -e's|@includedir[@]|/usr/local/winpcap/include|g'
            -e's|@libdir[@]|/usr/local/winpcap/lib|g'
            -e 's|@DEPLIBS[@]||g'
            pcap-config.in>pcap-config.tmp
mv pcap-config.tmp pcap-config
chmoda+x pcap-config

  • 进入到/root/winpcap/wpcap/libpcap/rpcapd/目录中,还需要使用make对rpcapd进行编译,编译后,该目录下就会生成rpcapd可执行文件,这就是实现远程抓包的程序,而且在编译winpcap时已经自动启用远程抓包的功能

[iyunv@baselibpcap]# cd /root/winpcap/wpcap/libpcap/rpcapd/
[iyunv@base rpcapd]# make
gcc -pthread -DHAVE_REMOTE-DHAVE_SNPRINTF -I../ -c rpcapd.c
gcc -pthread -DHAVE_REMOTE-DHAVE_SNPRINTF -I../ -c daemon.c
daemon.c: In function?.aemon_AuthUserPwd?.
daemon.c:684: warning: cast topointer from integer of different size
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.odaemon.o utils.o fileconf.o pcap-remote.o sockutils.o pcap-new.o-L../ -lpcap –lcrypt
[iyunv@baserpcapd]# ll rpcapd
-rwxr-xr-x.1 root root 274673 Nov  9 23:19 rpcapd
  • 将rpcapd程序的路径加入到环境变量PATH中

[iyunv@baserpcapd]# export PATH=$PATH:/root/winpcap/wpcap/libpcap/rpcapd
[iyunv@baserpcapd]#echo “export PATH=$PATH:/root/winpcap/wpcap/libpcap/rpcapd”>> /etc/profile


Rpcapd的使用
使用rpcapd–h可以查看命令的使用方法
[iyunv@baserpcapd]# rpcapd -h
USAGE:
rpcapd[-b ] [-p ] [-6] [-l ][-a ]
[-n][-v] [-d] [-s ] [-f ]
-b: the address to bind to (either numeric or literal).
Default:it binds to all local IPv4 addresses
-p: the port to bind to. Default: it binds to port 2002
-4:use only IPv4 (default both IPv4 and IPv6 waiting sockets are used)
-l: a file that keeps the list of the hosts which areallowed
toconnect to this server (if more than one, list them one per line).
Wesuggest to use literal names (instead of numeric ones) in order to
avoidproblems with different address families
-n:permit NULL authentication (usually used with '-l')
-a: run in active mode when connecting to 'host' onport 'port'
Incase 'port' is omitted, the default port (2003) is used
-v:run in active mode only (default: if '-a' is specified, it accepts
passiveconnections as well
-d:run in daemon mode (UNIX only) or as a service (Win32 only)
Warning(Win32): this switch is provided automatically when the service
isstarted from the control panel
-s: save the current configuration to file
-f: load the current configuration from file; all theswitches
specifiedfrom the command line are ignored
-h:print this help screen

-b        指定rpcapd进程监听的IP地址,从别的本机地址进入的到rpcapd的请求,其是不会给予响应的。如果省略该选项,就表示rpcapd监听所有的本地ipv4的地址
-p        指定rpcapd进程监听的端口,默认是2002,可以省略。
-l        指定一个地址列表,允许哪些地址可以访问rpcapd进程
-n        不启用认证功能,任何主机都可以访问rpcapd进程
-d        以守护进程方式运行

通常只要使用rpcapd–n –d 即可启用进程
[iyunv@baserpcapd]# rpcapd -n –d

另外还需要在远端的wireshark上稍作配置,即可开始远程抓包
如图所示,选择Options选项
wKioL1R8jPCRgmEuAAGFEaWsB_4395.jpg

点击ManageInterfaces选项
wKiom1R8jI-TDahjAAT3F09xTeg859.jpg
选择RemoteInterfaces和Add选项
wKioL1R8jVWA-cpmAAE-HycUzd0488.jpg

输入rpcapd端的ip地址和端口,点击OK,然后就会显示出远程所能监听的端口
wKiom1R8jQfiTP8jAADguVNyzzU131.jpg

最后选择屏蔽掉不抓包的端口,点击Apply即完成了远程抓包的设置。
wKioL1R8jbfgNRfiAAHOIDbPxdA281.jpg

然后我用icmp包来测试,远程抓包是成功的
wKiom1R8jVLTNl9QAAGoksecuoY421.jpg

wKioL1R8jfbzX6KNAAmIOXKZMqg845.jpg

至此,远程抓包就完成了,有一点需要注意,抓包过程可能会受到iptables的影响,在实验环境下,我将iptables都清空了,所以没有问题,在实际环境时,需要根据实际情况,放通tcp的2002端口即可。抓包结束后可以使用如下命令来结束rpcapd进程:
#killall -15 rpcapd





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-34286-1-1.html 上篇帖子: RAID磁盘阵列 下篇帖子: Openldap错误:ldap_sasl_interactive_bind_s: Invalid credenti linux 主机
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表