1) 옵션 없이 사용하는 경우 - 'tcpdump' 명령을 옵션 없이 수행하면 현재 시스템에서 주고받는
모든 패킷을 캡처하여 패킷의 헤더 부분을 출력 ==============================================================
sjw@sjw-HP-Mini-110-3500:~$ sudo tcpdump [sudo] password for sjw: tcpdump: WARNING: eth0: no IPv4 address assigned tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes ^C 0 packets captured 0 packets received by filter 0 packets dropped by kernel sjw@sjw-HP-Mini-110-3500:~$ sudo tcpdump -i wlan0 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes 12:30:28.512065 IP 192.168.0.16.mdns > 224.0.0.251.mdns: 0 [4q] PTR (QM)? _0D7DBB76._sub._googlecast._tcp.local. PTR (QM)? _5FD0CDC9._sub._googlecast._tcp.local. PTR (QM)? _CC1AD845._sub._googlecast._tcp.local. PTR (QM)? _googlecast._tcp.local. (93) 12:30:29.138387 IP 192.168.0.12.33902 > kns.kornet.net.domain: 57975+ PTR? 251.0.0.224.in-addr.arpa. (42) 12:30:29.138499 IP 192.168.0.12.33902 > kns2.kornet.net.domain: 57975+ PTR? 251.0.0.224.in-addr.arpa. (42) 12:30:29.142216 IP kns.kornet.net.domain > 192.168.0.12.33902: 57975 NXDomain 0/1/0 (99) 12:30:29.143223 IP kns2.kornet.net.domain > 192.168.0.12.33902: 57975 NXDomain 0/1/0 (99) 12:30:29.143315 IP 192.168.0.12.36220 > kns.kornet.net.domain: 50420+ PTR? 16.0.168.192.in-addr.arpa. (43) 12:30:29.143403 IP 192.168.0.12 > kns2.kornet.net: ICMP 192.168.0.12 udp port 33902 unreachable, length 135 12:30:29.146251 IP kns.kornet.net.domain > 192.168.0.12.36220: 50420 NXDomain* 0/1/0 (93) ^C 8 packets captured 14 packets received by filter 0 packets dropped by kernel sjw@sjw-HP-Mini-110-3500:~$ ==============================================================
- 'tcpdump' 는 'Ctrl + c' 로 종료하지 않으면 계속 캡처하여 출력 - 'Ctrl + c' 로 종료하면 캡처한 파일의 갯수를 출력하고 종료
2) 캡처할 패킷 개수 지정하기 : -c 옵션 - 'tcpdump' 명령에 '-c' 옵션을 사용하여 캡처할 패킷의 개수를 지정할 수 있음 - 예를 들어 패킷을 세 개만 캡처하려면 '-c 3' 을 옵션으로 지정 ============================================================== sjw@sjw-HP-Mini-110-3500:~$ sudo tcpdump -i wlan0 -c 3 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes 12:36:11.219295 IP 192.168.0.12.38007 > 180.70.93.71.https: Flags [.], ack 380699362, win 320, length 0 12:36:11.233879 IP 180.70.93.71.https > 192.168.0.12.38007: Flags [.], ack 1, win 65535, length 0 12:36:12.203449 IP 192.168.0.12.50408 > kns.kornet.net.domain: 63683+ PTR? 71.93.70.180.in-addr.arpa. (43) 3 packets captured 9 packets received by filter 0 packets dropped by kernel sjw@sjw-HP-Mini-110-3500:~$
==============================================================
3) 캡처한 패킷 정보를 파일로 저장하기 : -w 옵션 - 'tcpdump' 명령의 캡처한 패킷 정보를 파일에 저장 하려면 '-w' 옵션을 사용 - 예를 들어 패킷 3개르 캡처하여 dump.out 파일에 저장시 ============================================================== sjw@sjw-HP-Mini-110-3500:~$ sudo tcpdump -i wlan0 -c 3 -w dump.out tcpdump: listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes 3 packets captured 5 packets received by filter 0 packets dropped by kernel sjw@sjw-HP-Mini-110-3500:~$ ls dump.out dump.out sjw@sjw-HP-Mini-110-3500:~$ cat dump.out �ò����<HU/= ��^��W��Ey@��������eC� _0D7DBB76_sub _googlecast_tcplocal _5FD0CDC9� _CC1AD845� �<HUO� jj^�pV���E\������� ����H��_raop_tcplocal _airplay� _airport� �<HU�� ~~33�pV���O��`�H���rV�����O����Hʰ_raop_tcplocal _airplay� _airport� sjw@sjw-HP-Mini-110-3500:~$ ============================================================== - 패킷을 저장한 파일이 바니어니 파일이기 때문에 'cat' 이나 'vi' 명령으로 파일 내용을 확인할 수 없음 - 'file' 명령으로 파일 종류를 확인하면 tcpdump 캡처파일이라고 출력 - 'cat' 명령으로 dump.out 파일을 확인하면 이상한 문자가 출력 - 캡처한 파일의 내용을 확인하려면 '-r' 옵션을 사용해야 함. ============================================================== sjw@sjw-HP-Mini-110-3500:~$ file dump.out dump.out: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 65535) sjw@sjw-HP-Mini-110-3500:~$
==============================================================
4) 캡처한 패킷 파일 읽기 : -r 옵션 - tcpdump 명령으로 캡처한 패킷 정보를 저장한 파일의 내용을 읽으려면 '-r' 옵션을 사용 ============================================================== sjw@sjw-HP-Mini-110-3500:~$ sudo tcpdump -r dump.out [sudo] password for sjw: reading from file dump.out, link-type EN10MB (Ethernet) 12:44:44.671023 IP 192.168.0.16.mdns > 224.0.0.251.mdns: 0 [4q] PTR (QM)? _0D7DBB76._sub._googlecast._tcp.local. PTR (QM)? _5FD0CDC9._sub._googlecast._tcp.local. PTR (QM)? _CC1AD845._sub._googlecast._tcp.local. PTR (QM)? _googlecast._tcp.local. (93) 12:44:44.773199 IP 192.168.0.10.mdns > 224.0.0.251.mdns: 0 [3q] PTR (QM)? _raop._tcp.local. PTR (QM)? _airplay._tcp.local. PTR (QM)? _airport._tcp.local. (64) 12:44:44.774810 IP6 fe80::7256:81ff:fea2:c04f.mdns > ff02::fb.mdns: 0 [3q] PTR (QM)? _raop._tcp.local. PTR (QM)? _airplay._tcp.local. PTR (QM)? _airport._tcp.local. (64) sjw@sjw-HP-Mini-110-3500:~$
==============================================================
5) 특정 포트로 송수신되는 패킷 캡처하기 : tcp port 옵션 - 특정 포트로 송수신되는 패킷을 캡처하려면 'tcp port' 옵션을 사용 - 지정한 포트를 사용하지 않는다면 캡처되는 것이 없을 수도 있음 ============================================================== sjw@sjw-HP-Mini-110-3500:~$ sudo tcpdump -c 3 tcp port 22 and host 192.168.0.12tcpdump: WARNING: eth0: no IPv4 address assigned tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes ^C 0 packets captured 0 packets received by filter 0 packets dropped by kernel sjw@sjw-HP-Mini-110-3500:~$ sudo tcpdump -i wlan0 -c 3 tcp port 22 and host 192.168.0.12 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes ^C 0 packets captured 0 packets received by filter 0 packets dropped by kernel sjw@sjw-HP-Mini-110-3500:~$ ==============================================================
6) 캡처한 내용을 ASCII 로 보기 : -X 옵션 - 캡처한 내용을 ASCII 로 보려면 '-X' 옵션을 사용해야함 - '-q' 옵션은 일부 정보를 생략하고 출력 ============================================================== sjw@sjw-HP-Mini-110-3500:~$ sudo tcpdump -Xqr dump.out reading from file dump.out, link-type EN10MB (Ethernet) 12:44:44.671023 IP 192.168.0.16.mdns > 224.0.0.251.mdns: UDP, length 93 0x0000: 4500 0079 0000 4000 0111 d7c0 c0a8 0010 E..y..@......... 0x0010: e000 00fb 14e9 14e9 0065 43db 0000 0000 .........eC..... 0x0020: 0004 0000 0000 0000 095f 3044 3744 4242 ........._0D7DBB 0x0030: 3736 045f 7375 620b 5f67 6f6f 676c 6563 76._sub._googlec 0x0040: 6173 7404 5f74 6370 056c 6f63 616c 0000 ast._tcp.local.. 0x0050: 0c00 0109 5f35 4644 3043 4443 39c0 1600 ...._5FD0CDC9... 0x0060: 0c00 0109 5f43 4331 4144 3834 35c0 1600 ...._CC1AD845... 0x0070: 0c00 01c0 1b00 0c00 01 ......... 12:44:44.773199 IP 192.168.0.10.mdns > 224.0.0.251.mdns: UDP, length 64 0x0000: 4500 005c 91f4 0000 ff11 87ee c0a8 000a E..\............ 0x0010: e000 00fb 14e9 14e9 0048 dac9 0000 0000 .........H...... 0x0020: 0003 0000 0000 0000 055f 7261 6f70 045f ........._raop._ 0x0030: 7463 7005 6c6f 6361 6c00 000c 0001 085f tcp.local......_ 0x0040: 6169 7270 6c61 79c0 1200 0c00 0108 5f61 airplay......._a 0x0050: 6972 706f 7274 c012 000c 0001 irport...... 12:44:44.774810 IP6 fe80::7256:81ff:fea2:c04f.mdns > ff02::fb.mdns: UDP, length 64 0x0000: 6000 10d2 0048 11ff fe80 0000 0000 0000 `....H.......... 0x0010: 7256 81ff fea2 c04f ff02 0000 0000 0000 rV.....O........ 0x0020: 0000 0000 0000 00fb 14e9 14e9 0048 cab0 .............H.. 0x0030: 0000 0000 0003 0000 0000 0000 055f 7261 ............._ra 0x0040: 6f70 045f 7463 7005 6c6f 6361 6c00 000c op._tcp.local... 0x0050: 0001 085f 6169 7270 6c61 79c0 1200 0c00 ..._airplay..... 0x0060: 0108 5f61 6972 706f 7274 c012 000c 0001 .._airport...... sjw@sjw-HP-Mini-110-3500:~$
==============================================================
|