【问题标题】:How to capture all the HTTP packets using tcpdump如何使用 tcpdump 捕获所有 HTTP 数据包
【发布时间】:2012-02-11 15:32:19
【问题描述】:

我想用一些参数运行tcpdump(仍然不知道用什么),然后加载stackoverflow.com页面。

输出应该是 HTTP 通信。后来我想把它当成一个shell脚本,所以每当我想检查一个站点site.com的HTTP通信时,我就可以运行script.sh site.com

HTTP 通信应该足够简单。像这样:

GET /questions/9241391/how-to-capture-all-the-http-communication-data-using-tcp-dump
Host: stackoverflow.com
... 
...

HTTP/1.1 200 OK
Cache-Control: public, max-age=60
Content-Length: 35061
Content-Type: text/html; charset=utf-8
Expires: Sat, 11 Feb 2012 15:36:46 GMT
Last-Modified: Sat, 11 Feb 2012 15:35:46 GMT
Vary: *
Date: Sat, 11 Feb 2012 15:35:45 GMT


....
decoded deflated data
....

现在,我应该与tcpdump 一起使用哪些选项来捕获它?

【问题讨论】:

  • 看起来像“curl -v site.com”是你需要的。 :)

标签: bash http network-programming tcpdump


【解决方案1】:

可以通过ngrep完成

ngrep -q -d eth1 -W byline host stackoverflow.com and port 80 
       ^  ^       ^         ^        
       |  |       |         |
       |  |       |         |
       |  |       |         v
       |  |       |         filter expression
       |  |       |         
       |  |       +-->  -W  is set the dump format ("normal", "byline", "single", "none")
       |  |
       |  +---------->  -d  is use specified device instead of the pcap default
       |
       +------------->  -q  is be quiet ("don't print packet reception hash marks")

【讨论】:

  • 注意:对于那些在 OS X 10.9.x/Mavericks 中使用通过 brew 安装的 ngrep 1.45 的用户,可能会导致“分段错误:11”。 jfarcand 在这里找到了一种解决方法:gist.github.com/jfarcand/8302675,这对我有用:ngrep -q -W byline -d en0 '' 'host some_hostname and port 80'
  • 为 ASCII 艺术点赞。
  • 主机不是http中的主机,只是tcp中的ip
  • 这种 ASCII 文档有生成器吗?看起来病了!
【解决方案2】:

根据您提到的内容,ngrep(在 Unix 上)和 Fiddler(Windows)可能是更好/更简单的解决方案。

如果您绝对想使用 tcpdump,请尝试以下选项

tcpdump -A -vvv 主机 destination_hostname -A(ASCII) -vvv(详细输出)

【讨论】:

    【解决方案3】:
    tcpdump -i eth0 -w dump3.pcap -v  'tcp and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
    

    http://www.tcpdump.org/manpages/tcpdump.1.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-14
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多