it-swarm.cn

如何以友好格式读取pcap文件?

pcap文件上的一只简单的猫看起来很糟糕:

$cat tcp_dump.pcap

?ò????YVJ?
          JJ
            [email protected]@.?E<[email protected]@
?CA??qe?U????иh?
.Ceh?YVJ??
          JJ
            [email protected]@.?E<[email protected]@
CA??qe?U????еz?
.ChV?YVJ$?JJ
            [email protected]@.?E<-/@@A?CAͼ?9????F???A&?
[email protected]@.?Ӣ#3E<@3{nͼ?9CA??P?ɝ?F???<K?
?ԛ`.Ck??YVJgeBB
               [email protected]@[email protected]@AFCAͼ?9????F?P?ʀ???
.Ck??ԛ`?YVJ?""@@.?Ӣ#[email protected]?Iͼ?9CA??P?ʝ?F?????
?ԛ?.Ck?220-rly-da03.mx

等等.

我尝试通过以下方式使它更漂亮:

Sudo tcpdump -ttttnnr tcp_dump.pcap
reading from file tcp_dump.pcap, link-type EN10MB (Ethernet)
2009-07-09 20:57:40.819734 IP 67.23.28.65.49237 > 216.239.113.101.25: S 2535121895:2535121895(0) win 5840 <mss 1460,sackOK,timestamp 776168808 0,nop,wscale 5>
2009-07-09 20:57:43.819905 IP 67.23.28.65.49237 > 216.239.113.101.25: S 2535121895:2535121895(0) win 5840 <mss 1460,sackOK,timestamp 776169558 0,nop,wscale 5>
2009-07-09 20:57:47.248100 IP 67.23.28.65.42385 > 205.188.159.57.25: S 2644526720:2644526720(0) win 5840 <mss 1460,sackOK,timestamp 776170415 0,nop,wscale 5>
2009-07-09 20:57:47.288103 IP 205.188.159.57.25 > 67.23.28.65.42385: S 1358829769:1358829769(0) ack 2644526721 win 5792 <mss 1460,sackOK,timestamp 4292123488 776170415,nop,wscale 2>
2009-07-09 20:57:47.288103 IP 67.23.28.65.42385 > 205.188.159.57.25: . ack 1 win 183 <nop,nop,timestamp 776170425 4292123488>
2009-07-09 20:57:47.368107 IP 205.188.159.57.25 > 67.23.28.65.42385: P 1:481(480) ack 1 win 1448 <nop,nop,timestamp 4292123568 776170425>
2009-07-09 20:57:47.368107 IP 67.23.28.65.42385 > 205.188.159.57.25: . ack 481 win 216 <nop,nop,timestamp 776170445 4292123568>
2009-07-09 20:57:47.368107 IP 67.23.28.65.42385 > 205.188.159.57.25: P 1:18(17) ack 481 win 216 <nop,nop,timestamp 776170445 4292123568>
2009-07-09 20:57:47.404109 IP 205.188.159.57.25 > 67.23.28.65.42385: . ack 18 win 1448 <nop,nop,timestamp 4292123606 776170445>
2009-07-09 20:57:47.404109 IP 205.188.159.57.25 > 67.23.28.65.42385: P 481:536(55) ack 18 win 1448 <nop,nop,timestamp 4292123606 776170445>
2009-07-09 20:57:47.404109 IP 67.23.28.65.42385 > 205.188.159.57.25: P 18:44(26) ack 536 win 216 <nop,nop,timestamp 776170454 4292123606>
2009-07-09 20:57:47.444112 IP 205.188.159.57.25 > 67.23.28.65.42385: P 536:581(45) ack 44 win 1448 <nop,nop,timestamp 4292123644 776170454>
2009-07-09 20:57:47.484114 IP 67.23.28.65.42385 > 205.188.159.57.25: . ack 581 win 216 <nop,nop,timestamp 776170474 4292123644>
2009-07-09 20:57:47.616121 IP 67.23.28.65.42385 > 205.188.159.57.25: P 44:50(6) ack 581 win 216 <nop,nop,timestamp 776170507 4292123644>
2009-07-09 20:57:47.652123 IP 205.188.159.57.25 > 67.23.28.65.42385: P 581:589(8) ack 50 win 1448 <nop,nop,timestamp 4292123855 776170507>
2009-07-09 20:57:47.652123 IP 67.23.28.65.42385 > 205.188.159.57.25: . ack 589 win 216 <nop,nop,timestamp 776170516 4292123855>
2009-07-09 20:57:47.652123 IP 67.23.28.65.42385 > 205.188.159.57.25: P 50:56(6) ack 589 win 216 <nop,nop,timestamp 776170516 4292123855>
2009-07-09 20:57:47.652123 IP 67.23.28.65.42385 > 205.188.159.57.25: F 56:56(0) ack 589 win 216 <nop,nop,timestamp 776170516 4292123855>
2009-07-09 20:57:47.668124 IP 67.23.28.65.49239 > 216.239.113.101.25: S 2642380481:2642380481(0) win 5840 <mss 1460,sackOK,timestamp 776170520 0,nop,wscale 5>
2009-07-09 20:57:47.692126 IP 205.188.159.57.25 > 67.23.28.65.42385: P 589:618(29) ack 57 win 1448 <nop,nop,timestamp 4292123893 776170516>
2009-07-09 20:57:47.692126 IP 67.23.28.65.42385 > 205.188.159.57.25: R 2644526777:2644526777(0) win 0
2009-07-09 20:57:47.692126 IP 205.188.159.57.25 > 67.23.28.65.42385: F 618:618(0) ack 57 win 1448 <nop,nop,timestamp 4292123893 776170516>
2009-07-09 20:57:47.692126 IP 67.23.28.65.42385 > 205.188.159.57.25: R 2644526777:2644526777(0) win 0

好吧...这很漂亮,但它没有显示实际的消息。我实际上可以仅查看RAW文件来提取更多信息。仅查看pcap文件的所有内容的最佳方法(最好是最简单的方法)是什么?

[〜#〜] update [〜#〜]

感谢下面的回复,我取得了一些进展。这是现在的样子:

tcpdump -qns 0 -A -r blah.pcap
    20:57:47.368107 IP 205.188.159.57.25 > 67.23.28.65.42385: tcp 480
        0x0000:  4500 0214 834c 4000 3306 f649 cdbc 9f39  [email protected]
        0x0010:  4317 1c41 0019 a591 50fe 18ca 9da0 4681  C..A....P.....F.
        0x0020:  8018 05a8 848f 0000 0101 080a ffd4 9bb0  ................
        0x0030:  2e43 6bb9 3232 302d 726c 792d 6461 3033  .Ck.220-rly-da03
        0x0040:  2e6d 782e 616f 6c2e 636f 6d20 4553 4d54  .mx.aol.com.ESMT
        0x0050:  5020 6d61 696c 5f72 656c 6179 5f69 6e2d  P.mail_relay_in-
        0x0060:  6461 3033 2e34 3b20 5468 752c 2030 3920  da03.4;.Thu,.09.
        0x0070:  4a75 6c20 3230 3039 2031 363a 3537 3a34  Jul.2009.16:57:4
        0x0080:  3720 2d30 3430 300d 0a32 3230 2d41 6d65  7.-0400..220-Ame
        0x0090:  7269 6361 204f 6e6c 696e 6520 2841 4f4c  rica.Online.(AOL
        0x00a0:  2920 616e 6420 6974 7320 6166 6669 6c69  ).and.its.affili
        0x00b0:  6174 6564 2063 6f6d 7061 6e69 6573 2064  ated.companies.d

等等.

这看起来不错,但仍然使右侧的实际消息难以阅读。有没有办法以更友好的方式查看这些消息?

[〜#〜] update [〜#〜]

这很漂亮:

tcpick -C -yP -r tcp_dump.pcap

谢谢!

140
Tony

Wireshark可能是最好的,但是如果您想要/需要查看有效负载而不加载GUI,则可以使用-X或-A选项

tcpdump -qns 0 -X -r serverfault_request.pcap

14:28:33.800865 IP 10.2.4.243.41997 > 69.59.196.212.80: tcp 1097
        0x0000:  4500 047d b9c4 4000 4006 63b2 0a02 04f3  E..}[email protected]@.c.....
        0x0010:  453b c4d4 a40d 0050 f0d4 4747 f847 3ad5  E;.....P..GG.G:.
        0x0020:  8018 f8e0 1d74 0000 0101 080a 0425 4e6d  .....t.......%Nm
        0x0030:  0382 68a1 4745 5420 2f71 7565 7374 696f  ..h.GET./questio
        0x0040:  6e73 2048 5454 502f 312e 310d 0a48 6f73  ns.HTTP/1.1..Hos
        0x0050:  743a 2073 6572 7665 7266 6175 6c74 2e63  t:.serverfault.c
        0x0060:  6f6d 0d0a 5573 6572 2d41 6765 6e74 3a20  om..User-Agent:.
        0x0070:  4d6f 7a69 6c6c 612f 352e 3020 2858 3131  Mozilla/5.0.(X11
        0x0080:  3b20 553b 204c 696e 7578 2069 3638 363b  ;.U;.Linux.i686;

tcpdump -qns 0 -A -r serverfault_request.pcap

14:29:33.256929 IP 10.2.4.243.41997 > 69.59.196.212.80: tcp 1097
E..}[email protected]@.c.
...E;...^M.P..^w.G.......t.....
.%.}..l.GET /questions HTTP/1.1
Host: serverfault.com

还有许多其他工具可用于读取和获取统计信息,提取有效载荷等。快速浏览一下debian软件包存储库中依赖libpcap的事物数量,可以看到50多种工具的清单,这些工具可用于以各种方式对捕获进行切片,切块,查看和操作。

例如。

131
Zoredache

Wireshark

您可能永远都不会回望:)

顺便说一句,您应该确保原始捕获的快照与捕获的流量的MTU匹配或超过。否则内容将被截断。

30
Dan Carley

您可以使用wireshark这是一个gui应用程序,也可以使用tshark这是cli的对应项。

此外,您可以使用多种可视化工具来可视化pcap:

如果要分析pcap文件,则可以使用出色的nsm-console

最后但并非最不重要的一点是,您可以将pcap上传到pcapr.net并在那里观看。 pcapr.net是一种社交网站,可以对流量捕获进行分析和评论。

22
chmeee

tshark -r file.pcap -V如果您在没有wireshark/gui的情况下被卡住,则非常有用。

21
Marcin

您只需在 Wireshark 中加载pcap文件即可浏览它们。

4
Emmanuel BERNAT

您可以使用tcpdump直接查看/捕获到Wireshark的远程数据包。

使用WireShark和tcpdump进行远程数据包捕获

如何使用tcpdump捕获pcap文件(wireshark转储)

2
Rahul Panwar