Se você quiser ver conexões TCP de saída originadas de seu host, você pode usar a opção src host <ip>
como um argumento para tcpdump
:
$ tcpdump -i any -nn src host 10.0.2.15 and port 80
Exemplo
Tráfego de saída simulado:
$ 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
Assistindo com 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
Filtrando em pacotes de sincronização
Para capturar apenas os pacotes syn de saída, você precisará analisar os tcpflags, procurando especificamente o tcp-syn
flag. Novamente usando o mesmo comando curl
acima, mas agora invocando tcpdump
da seguinte forma:
$ 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
tcpflags
Na páginatcpdump
man:
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.