tcpdump/tshark: 発信 TCP 接続要求のみを表示

tcpdump/tshark: 発信 TCP 接続要求のみを表示

TCP私のコンピュータ/サーバーが他のホストに送信する要求(synパケット)を見たいのですが。より具体的にを見たいですoutgoing connection requests。どうすればいいですか?

また、マイコンピュータ/サーバーへの接続試行を見たくありません。

次のiptablesコマンドは機能しますが、すべてを記録し、画面にすべてを見たいので、使用するのは不便です。

iptables -I OUTPUT 1 -o eth0 -p tcp -m state --state NEW -j LOG

ベストアンサー1

ホストからの発信TCP接続を表示するには、スイッチをsrc host <ip>パラメータとして使用できますtcpdump

$ tcpdump -i any -nn src host 10.0.2.15 and port 80

はい

アウトバウンドトラフィックシミュレーション:

$ curl -vv telnet://www.google.com:80
* About to connect() to www.google.com port 80 (#0)
*   Trying 172.217.15.100...
* Connected to www.google.com (172.217.15.100) port 80 (#0)
^C

視聴方法tcpdump

$ tcpdump -i any -nn src host 10.0.2.15 and port 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
11:04:19.585773 IP 10.0.2.15.50642 > 216.58.218.4.80: Flags [S], seq 315169574, win 29200, options [mss 1460,sackOK,TS val 38358006 ecr 0,nop,wscale 7], length 0
11:04:19.623676 IP 10.0.2.15.50642 > 216.58.218.4.80: Flags [.], ack 470600706, win 29200, length 0

Syn パケットのフィルタリング

発信シンパケットのみをキャプチャするには、tcpflagsを分析し、特にflagsを見つける必要がありますtcp-syncurl上記と同じコマンドを再利用しますが、tcpdump次のように呼び出します。

$ tcpdump -i any -nn src host 10.0.2.15 and "tcp[tcpflags] == tcp-syn"
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
11:13:39.962475 IP 10.0.2.15.44810 > 64.233.185.103.80: Flags [S], seq 3710429425, win 29200, options [mss 1460,sackOK,TS val 38918382 ecr 0,nop,wscale 7], length 0

TCPフラグ

tcpdumpマニュアルページから:
The general format of a TCP protocol line is:

src > dst: Flags [tcpflags], seq data-seqno, ack ackno, win window, urg urgent, options [opts], length len

Src and dst are the source and destination IP addresses and ports. 
Tcpflags are some combination of S (SYN), F (FIN), P (PUSH), R (RST), U 
(URG), W (ECN CWR), E (ECN-Echo) or `.' (ACK), or `none' if no flags are 
set. Data-seqno describes the portion of sequence space covered by the 
data in this packet (see example below). Ackno is sequence number of the 
next data expected the other direction on this connection. Window is the 
number of bytes of receive buffer space available the other direction on 
this connection. Urg indicates there is `urgent' data in the packet. Opts 
are TCP options (e.g., mss 1024). Len is the length of payload data.

引用する

おすすめ記事