본문 바로가기
프로...NetWork

tcpdump 예제

by 크크다스 2018. 1. 25.
반응형

Useful Examples : https://hackertarget.com/tcpdump-examples/

사용법tcpdump -h

tcpdump version 4.9.0libpcap version 1.1.1OpenSSL 1.0.1 14 Mar 2012Usage: tcpdump [-aAbdDefhHIKlLnNOpqStuUvxX#] [ -B size ] [ -c count ]                [ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]                [ -i interface ] [ -M secret ] [ --number ]                [ -Q in|out|inout ]                [ -r file ] [ -s snaplen ] [ -T type ] [ --version ] [ -V file ]                [ -w file ] [ -W filecount ] [ -y datalinktype ] [ -z postrotate-command ]                [ -Z user ] [ expression ]

pcap화일 전송하기

> https://www.squidhacks.com/single-post/2017/08/08/How-to-Save-TCPDUMP-live-output-on-a-different-server

 

tcpdump -i eth0 port 2233 and less 284 and greater 282 -U -w - | nc 12.19.24.61 12345 &

Length : 캡춰시 표시되는 패킷 길이 기준

 

tcpdump -nni eth0 -s0 -w - | ssh user@192.168.0.10 "cat - > /tmp/name_of_capture.pcap"

 

저장하는 과정중에는 전송하지 않고, 종료한 후에 저장하는 것으로 보임.
-nni: "Don't resolve hostnames nor portnames, that way you see something like 192.168.50.10:23 instead of squidhacks.blog.stuff:telnet" eth0: "This is the interface where we are capturing the traffic"  -s0: "This tells tcpdump to capture the entire frame instead of the default which in some distros is 96 bytes"  -w: - "tells tcpdump to save the file in what follows next which is the ssh session

        Source: pcap-filter(7)

 

예 : All Interface


tcpdump -i any
tcpdump -ni any proto gre


예 : VLAN tag
tcpdump -nnei eth0 -vvv
 
예 : by host
tcpdump -i eth0 'host domain.name'
tcpdump -i eth0 'host xxx.xxx.xxx.xxx'
예 : by port
tcpdump -i eth0 'port xxxx'
예 : by host and[or] port , not
tcpdump -i eth0 'host xxx.xxx.xxx.xxx and[or] [not] port xxxx'
tcpdump host helios and \( hot or not ace \)
예 : ASCII Output
tcpdump -A -i eth0 
예 : Options
<limit counts> tcpdump -c 1234
<hex+ascii> tcpdump -XX
<write into a file> tcpdump -w capture.pcap
<read from a file> tcpdump -r captured.pcap -tttt
<timestamp> --t Don't print a timestamp on each dump line. -tt    Print the timestamp, as seconds since January 1, 1970, 00:00:00, UTC, and fractions of a second since that time, on each dump line. -ttt   Print a delta (micro-second resolution) between current and previous line on each dump line. -tttt  Print a timestamp, as hours, minutes, seconds, and fractions of a second since midnight, preceded by the date, on each dump line. -ttttt Print a delta (micro-second resolution) between current and first line on each dump line.

 

<filter by packet's length> tcpdump greater/less 1234

<filter by packet's length> tcpdump >= 1234

 

<filter by packet's protocol> tcpdump [not] arp/rarp/ip/ip6/tcp/udp  tcpdump proto gre

 

포트 범위 지정

tcpdump -i wan udp and portrange 44400-44500

 

포트 방향 지정

tcpdump -i wan udp and src/dst portrange 67-68

 

네트워크 지정

tcpdump -i wan udp and net 172.16.0.0/16

 
예 : Useful Examples
tcpdump -A -s 0 -q -t -i eth0 'port 80 and ( ((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12:2]&0xf0)>>2)) != 0)'   <=== HTTP

tcpdump -nq -s 0 -A -vvv port 5060 and host 1.2.3.4     <=== SIP Traffic

 

CF> https://originalchoi.tistory.com/entry/TCPDUMP-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0

 

TCPDUMP 사용하기

실시간으로 데이터를 받아 처리하고 있는데, 나중에 Src 데이터와 Dst 데이터를 비교해보니 정합성이 안 맞는 경우가 생긴다. 그렇다면 실시간 데이터를 잘 받아오고 있는가에 대한 검증이 필요

originalchoi.tistory.com

 

반응형

'프로...NetWork' 카테고리의 다른 글

[SWITCH] Flow COntrol Configure by "ethtool"  (0) 2018.07.05
iptables 예제  (0) 2018.01.25
[HowTo-WOL] Wake On LAN 동작원리 및 구현 방법  (0) 2017.09.13
[DNS] Dynamic resolv.conf  (0) 2015.09.23
[Ubuntu] Network  (0) 2015.09.21