依照文件指定連接埠範圍時出現 tcpdump 語法錯誤

依照文件指定連接埠範圍時出現 tcpdump 語法錯誤

我正在 OpenBSD 上使用 tcpdump 並嘗試從其上的底漆

我想捕獲一系列端口,但似乎完成此操作的方式已經改變。我甚至在手冊頁中找不到 portrange 作為關鍵字,這也表明了這一點。

# tcpdump portrange 100-65535 
tcpdump: syntax error

不是一件事:

# man tcpdump | grep portrange
# 

我認為這已經改變了,或者在 OpenBSD 上有所不同。如果有人能告訴我該怎麼做,因為我的第一堂課我們將學習一些實用的東西,那就太好了。如果有人告訴我有關 tcpdump 的更新底漆,那就更好了。

OpenBSD 附帶了它自己的 tcpdump,這可能是一個分支,我不太確定。

答案1

portrangeOpenBSD 的 pcap-filter 中沒有,但你可以偽造它。

tcpdump -i em0 tcp[2:2] > 79 and tcp[2:2] < 85

您可以對資料包的各個部分進行尋址並與它們進行比較。第一個數字是封包中的偏移量(從零開始),第二個數字是要使用的位元組數。因此,上面的範例會匹配目標連接埠為 80 到 84 的任何 tcp 封包。

與來源連接埠匹配的是tcp[0:2]. UDP 實際上是相同的,因為連接埠具有相同的偏移量。

答案2

顯示過濾器由 libpcap 處理,OpenBSD 有自己的 libpcap 和 tcpdump,它們不一定會從 tcpdump.org 的 libpcap 和 tcpdump 中取得變更。

如果portrange不起作用,對它的支援可能是 OpenBSD 沒有選擇的事情之一。

答案3

man pcap-filter不 應該使用man tcpdump

根據man pcap-filter

dst portrange port1-port2
              True  if  the packet is ip/tcp, ip/udp, ip6/tcp or ip6/udp and has a destination port value between port1 and port2.  port1 and port2 are interpreted
              in the same fashion as the port parameter for port.


   src portrange port1-port2
          True if the packet has a source port value between port1 and port2.

   portrange port1-port2
          True if either the source or destination port of the packet is between port1 and port2.

          Any of the above port or port range expressions can be prepended with the keywords, tcp or udp, as in:
               tcp src port port
          which matches only tcp packets whose source port is port.

相關內容