지정한 네트워크 인터페이스를 모니터링해 그 인터페이스에 도달한 데이터를 콘솔에 표시하는 패킷 캡쳐 도구
$ tcpdump <옵션> <조건식>
-i <인터페이스>: 모니터링할 인터페이스 지정-s <바이트수>: 패킷으로부터 가져올 바이트 크기 설정-A: 각각의 패킷을 ASCII 문자로 표시-X: 16진수와 ASCII 문자로 표시-n: IP 주소를 그대로 표시-nn: 포트번호를 그대로 표시-N: 호스트의 도메인명을 표시-l: 표준 출력을 버퍼링-t: 시간을 표시하지 않음-v: 상세 내용을 출력$ sudo /sbin/tcpdump -A 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
21:59:37.865817 IP 10.25.208.18.50181 > test-jongpak.ncl.nfra.io.http: Flags [P.], seq 3617735526:3617736086, ack 2000999801, win 2064, options [nop,nop,TS val 658996275 ecr 915023230], length 560: HTTP: GET /delay.php HTTP/1.1
[email protected].[.
...
q.a...P..CfwD.y...........
'G|36.%~GET /delay.php HTTP/1.1
Host: test-jongpak.ncl.nfra.io
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Accept-Encoding: gzip, deflate
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: dtck_first=20171225; PHPSESSID=5a737cbbbf143ea85496c2fab2958a99
21:59:40.866603 IP test-jongpak.ncl.nfra.io.http > 10.25.208.18.50181: Flags [P.], seq 1:178, ack 560, win 235, options [nop,nop,TS val 915026239 ecr 658996275], length 177: HTTP: HTTP/1.1 200 OK
E.....@[email protected].
q.a
....P..wD.y..E............
6.1?'G|3HTTP/1.1 200 OK
Date: Sun, 14 Apr 2019 12:59:37 GMT
Server: Apache
X-Powered-By: PHP/7.2.2
Content-Length: 2
Connection: close
Content-Type: text/html; charset=UTF-8
OK
^C
2 packets captured
3 packets received by filter
0 packets dropped by kernel
Matching HTTP data (exemple taken from tcpdump man page) :
# tcpdump -i eth1 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
==================================================================================================
IP header
---------
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version| IHL |Type of Service| Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live | Protocol | Header Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Destination Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding | <-- optional
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| DATA ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
TCP header
----------
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |C|E|U|A|P|R|S|F| |
| Offset| Res. |W|C|R|C|S|S|Y|I| Window |
| | |R|E|G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
==================================================================================================
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ip[2:2] = | Total Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+
ip[0] = |Version| IHL |
+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+
ip[0]&0xf = |# # # #| IHL | <-- that's right, we masked the version bits with 0xf or 00001111 in binary
+-+-+-+-+-+-+-+-+
+-+-+-+-+
| Data |
tcp[12] = | Offset|
| |
+-+-+-+-+
So what we are doing here is "(IP total length - IP header length - TCP header length) != 0"
We are matching any packet that contains data.