tcpdump/nc工具 ================================================================================================================================================ tcpdump 1、语法格式 tcpdump [ -AbdDefhHIJKlLnNOpqRStuUvxX ] [ -B buffer_size ] [ -c count ] [ -C file_size ] [ -G rotate_seconds ] [ -F file ] [ -i interface ] [ -j tstamp_type ] [ -m module ] [ -M secret ] [ -P in|out|inout ] [ -r file ] [ -V file ] [ -s snaplen ] [ -T type ] [ -w file ] [ -W filecount ] [ -E spi@ipaddr algo:secret,... ] [ -y datalinktype ] [ -z postrotate-command ] [ -Z user ] [ expression ] 将报文设置为混杂模式promisc,将报文截获。只有目标MAC地址为本主机网卡的MAC的报文或者广播报文才能被截获。 2、选项 -i interface_name # 指定抓包的接口 -w /path/to/file # 将抓包结果保存到文件中 -nn # 不解析端口及IP地址 -X # ASCII和十六进制两种格式显示 -XX # 显示链路层的信息 -A # 只显示ASCII编码的报文 -vv # 显示详细信息 expression: type:host、net、port、portrange direction:src、dst、src or dst、src and dst protocol:ehter、wlan、ip、arp、tcp、udp 3、示例 抓取tcp协议,端口是80端口的报文 tcpdump -i ens33 tcp port 80 -nn 抓取和指定目的主机的通信报文 tcpdump -i eth0 -nn host 172.18.26.2 抓取两个主机的通信 tcpdump -i eth0 -nn host 172.18.26.1 and 172.18.26.2 抓取指定主机和另外两个主机间的通信 tcpdump -i eth0 -nn host 172.18.26.1 and \(172.18.26.2 or 172.18.26.3\) ================================================================================================================================================ nc用法 1、发送文件 接收方:nc -l 1234 > /etc/fstab 发送方:nc 172.18.26.1 {1234|-p PORT} < /path/to/file 2、模拟Web服务器客户端 [ root@node0 ~ ]# nc 172.18.26.2 80 GET /index.html HTTP/1.1 Host: 172.18.26.2 HTTP/1.1 200 OK Date: Wed, 25 Oct 2017 07:16:19 GMT Server: Apache/2.4.6 (CentOS) Last-Modified: Mon, 16 Oct 2017 05:49:19 GMT ETag: "35-55ba391523284" Accept-Ranges: bytes Content-Length: 53 Content-Type: text/html; charset=UTF-8