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 패킷 필터링

나가는 syn 패킷만 캡처하려면 tcpflags를 분석하고 특히 flags를 찾아야 합니다 tcp-syn. curl위와 동일한 명령을 다시 사용하되 이제 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.

인용하다

관련 정보