首页 > 其他 > 详细

tcpdump和tcpflow使用

时间:2021-01-07 10:52:52      阅读:37      评论:0      收藏:0      [点我收藏+]

一、具体功能

tcpdump和tcpflow是Linux常用的命令行抓包工具,对于网络分析方面可以起到很大的帮助。

二、两者差别

tcpflow实际上也是一个抓包工具,这个抓包工具与tcpdump不同的是它是以流为单位显示数据内容,而cpdump以包为单位显示数据。我们平常会经常分析HTTP数据,用tcpflow会更便捷,且tcpflow看起来会更加直观些。

tcpflow可以理解为是一个抓包工具,其工具看起来更像wireshark的命令行版本,他可以直接从网卡抓包,并且解析出来,支持http ftp这些L7协议,也支持tcp udp抓包,还可以从tcpdump中读取东西,因此是一个非常好的看包工具,有了这个东西以后再也不用把线上服务器上的dump抓下来再用wireshark打开了。

三、具体使用

tcpdump介绍
tcpdump只有在root下才开启混杂模式,非root下不开启。所谓混杂模式就是一台机器的网卡能够接收所有经过它的数据流,而不论其目的地址是否是它。
tcpdump常用的命令方式:sudo可以根据你用户是否有root权限,选择增加

sudo tcpdump -i eth0 -nn -X ‘port 53‘

sudo tcpdump dst host 124.202.197.150 -i eth2 -s 0 -w /tmp/123.cap

tcpdump参数详解:

 1 -i 是interface含义,监听的网卡
 2 -nn 当遇到端口协议号或端口号的时候不要转换为对应的协议名称或端口名称
 3 -X 把协议头和包内容都原原本本的显示出来
 4 port 53 只有源端口和目的端口为53的才会被显示
 5 -t 不打印时间戳
 6 -v  在原有输出的基础之上,你还会看到tos值、ttl值、ID值、总长度、校验值等。
 7 -F  指定过滤表达式所在的文件,例如可以把4向中的port 53写到文件中去,在tcpdump时加-F后面接文件名称
 8 tcpdump -i eth0 -w flowdata;-w  将流量保存到文件中去;存储的都是(raw packets)二进制的无法直接查看,需要用-r命令来查看
 9 tcpdump -r flowdata;-r 读取用-w保存的数据
10 tcpdump -i eth0 -c 10 \udp\‘ 只获取udp协议的包
11 tcpdump -i eth0 \dst 8.8.8.8\‘ 查看源地址和目的地址之间的网络包;src 和dst;
12 tcpdump -i eth0 -c 3 \dst port 53 or dst port 80\‘ 只查看目标机器端口是53或80的网络包,其它端口不关注;除了端口还支持host,net(指定网络段)、portrange:指定端口区域
13 tcpdump port ftp or ftp-data; tcpdump会根据 /etc/services中协议对应的端口信息去找需要过滤端口条件
14 tcpdump ip[2:2] > 576;打印包长超过576字节的网络包
tcpflow介绍
tcpflow和tcpdump差别,tcpflow需要指定参数-p的情况下才会开启混杂模式。
tcpflow常用的命令方式:
tcpflow -cp -i eth0
tcpflow参数详解--直接复制tcpflow -h里面的点:
 1 [root@test ~]$  tcpflow -h
 2 TCPFLOW version 1.4.5
 3 
 4 usage: tcpflow [-aBcCDhJpsvVZ] [-b max_bytes] [-d debug_level] 
 5      [-[eE] scanner] [-f max_fds] [-F[ctTXMkmg]] [-i iface] [-L semlock]
 6      [-m min_bytes] [-o outdir] [-r file] [-R file] 
 7      [-S name=value] [-T template] [-w file] [-x scanner] [-X xmlfile]
 8       [expression]
 9 
10    -a: do ALL post-processing.
11    -b max_bytes: max number of bytes per flow to save
12    -d debug_level: debug level; default is 1
13    -f: maximum number of file descriptors to use
14    -h: print this help message (-hh for more help)
15    -H: print detailed information about each scanner
16    -i: network interface on which to listen
17    -I: generate temporal packet-> byte index files for each flow (.findex)
18    -g: output each flow in alternating colors (note change!)
19    -l: treat non-flag arguments as input files rather than a pcap expression
20    -L  semlock - specifies that writes are locked using a named semaphore
21    -p: dont use promiscuous mode    ---开启混杂模式
22    -q: quiet mode - do not print warnings
23    -r file: read packets from tcpdump pcap file (may be repeated)
24    -R file: read packets from tcpdump pcap file TO FINISH CONNECTIONS
25    -v: verbose operation equivalent to -d 10
26    -V: print version number and exit
27    -w file: write packets not processed to file
28    -o  outdir   : specify output directory (default .)
29    -X  filename : DFXML output to filename
30    -m  bytes    : specifies skip that starts a new stream (default 16777216).
31    -F{p} : filename prefix/suffix (-hh for options)
32    -T{t} : filename template (-hh for options; default %A.%a-%B.%b%V%v%C%c)
33    -Z: do not decompress gzip-compressed HTTP transactions
34 
35 Control of Scanners:
36    -E scanner   - turn off all scanners except scanner
37    -S name=value  Set a configuration parameter (-hh for info)
38 
39 Settable Options (and their defaults): 
40    -S enable_report=YES    Enable report.xml ()
41    -S http_cmd=    Command to execute on each HTTP attachment (http)
42    -S http_alert_fd=-1    File descriptor to send information about completed HTTP attachments (http)
43    -S netviz_histogram_dump=0    Dumps the histogram (netviz)
44    -S netviz_histogram_size=1000    Maximum histogram size (netviz)
45    -S tcp_timeout=0    Timeout for TCP connections (tcpdemux)
46    -S check_fcs=YES    Require valid Frame Check Sum (FCS) (wifiviz)
47 
48    -e http - enable scanner http
49    -e md5 - enable scanner md5
50    -e netviz - enable scanner netviz
51    -e wifiviz - enable scanner wifiviz
52 
53    -x tcpdemux - disable scanner tcpdemux
54 Console output options:
55    -B: binary output, even with -c or -C (normally -c or -C turn it off)
56    -c: console print only (dont create files)
57    -C: console print only, but without the display of source/dest header
58    -0: dont print newlines after packets when printing to console   -s: strip non-printable characters (change to .)
59    -D: output in hex (useful to combine with -c or -C)
60 
61 expression: tcpdump-like filtering expression  ---可以和tcpdump一样配置一定规则
62 
63 See the man page for additional information.

tcpdump和tcpflow使用

原文:https://www.cnblogs.com/laiyh/p/14244930.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!