情况描述
最近项目中进行双向认证,客户端无法抓取TCP信息,认证一直失败,服务器无法访问。顿时陷入绝境。
服务器是阿里云,没有图形界面,没法再Ubuntu上安装wireshark。 经高手指点,使用tcpdump抓包,然后wireshark分析。
环境准备
1、windows安装wireshark
2、ubuntu安装tcpdump
很多ubuntu默认安装了tcpdump,可以用指令查询
# tcpdump -help
tcpdump version 4.9.3
libpcap version 1.7.4
OpenSSL 1.0.2g 1 Mar 2016
Usage: tcpdump [-aAbdDefhHIJKlLnNOpqStuUvxX#] [ -B size ] [ -c count ]
[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]
[ -i interface ] [ -j tstamptype ] [ -M secret ] [ --number ]
[ -Q in|out|inout ]
[ -r file ] [ -s snaplen ] [ --time-stamp-precision precision ]
[ --immediate-mode ] [ -T type ] [ --version ] [ -V file ]
[ -w file ] [ -W filecount ] [ -y datalinktype ] [ -z postrotate-command ]
[ -Z user ] [ expression ]
抓TCP数据包
抓取指令,抓取结束后可以使用ctrl+C 结束
# tcpdump tcp port 443 -w ./tcpdump.log
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
抓取中遇到 Permission denied 问题
# sudo tcpdump tcp port 443 -w ./tcpdump.log
tcpdump: ./tcpdump.log: Permission denied
解决办法:
/*查看 tcpdump状态 */
# grep tcpdump /sys/kernel/security/apparmor/profiles
/usr/sbin/tcpdump (enforce)
/*需要更改 tcpdump状态为 complain */
# aa-complain /usr/sbin/tcpdump
The program 'aa-complain' is currently not installed. You can install it by typing:
apt install apparmor-utils
/*需要安装 apparmor */
# apt-get install apparmor-utils
/*重试指令 */
# aa-complain /usr/sbin/tcpdump
Setting /usr/sbin/tcpdump to complain mode.
/* 查看状态 */
# grep tcpdump /sys/kernel/security/apparmor/profiles
/usr/sbin/tcpdump (complain)
/*tcpdump 可以抓包了 */
抓包完成后,将数据从服务器中导出来,我使用ftp服务器。
wireshark分析数据
打开wareshark,直接使用wareshark打开保存的tcp数据即可,wareshark会自动解析。
操作完成