iptables string 을 이용한 차단...

vlzkcbcb의 이미지

PC(90.90.90.2)===Router====WAN 입니다.

라우터장비에서 NAT 도 해주면서 아래룰을 적용하여 DNS 쿼리가 막히는지 테스트해보았습니다.

iptables -I FORWARD -m string --string "nateon.nate.com" --algo kmp -j DROP

PC에서는 DNS 캐쉬를 삭제한 상태입니다. tcpdump 결과는 아래와 같았습니다.

00:00:09.389676 90.90.90.2.55907 > 168.126.63.1.53:  55400+ A? nateon.nate.com. (33)
00:00:09.397926 168.126.63.1.53 > 90.90.90.2.55907:  55400 1/3/3 A 211.234.239.58 (151)

네...아주 잘받아오네요 ㅡㅡ;; 받아오면 안되는데 말이죠...

그런데 iptables -L -v 했을때 DROP 부분에 패킷이 싸여있습니다.

어찌된일일까요? ㅠㅠ

그런데 아래룰로 할때는 쿼리를 받아오질 못하더군요.

iptables -I FORWARD -m string --string "nate" --algo kmp -j DROP

도움부탁드립니다.

bushi의 이미지

http://www.tcpipguide.com/free/t_DNSNameNotationandMessageCompressionTechnique.htm

[bushi@rose cts_math]$ sudo tcpdump -n -XX  -i eth0 udp port 53
...
	0x0000:  0025 6495 f452 0013 c389 d044 0800 4500  .%d..R.....D..E.
	0x0010:  004d 2579 0000 7911 df73 930b 3980 80e0  .M%y..y..s..9...
	0x0020:  ef47 0035 b498 0039 1ab0 da55 8180 0001  .G.5...9...U....
	0x0030:  0001 0000 0000 066e 6174 656f 6e04 6e61  .......nateon.na
	0x0040:  7465 0363 6f6d 0000 0100 01c0 0c00 0100  te.com..........
	0x0050:  0100 0001 cc00 04d3 eaef 3a              ..........:
...

0x06 nateon 0x04 nate 0x03 com 0x00
[bushi@rose cts_math]$ iptables -m string  --help
...
string match options:
--from                       Offset to start searching from
--to                         Offset to stop searching
--algo                       Algorithm
--icase                      Ignore case (default: 0)
[!] --string string          Match a string in a packet
[!] --hex-string string      Match a hex string in a packet

OTL

bushi의 이미지

agkrwyasym의 이미지

참고로, l7-filter는 세션 첫 10개 패캣 또는 2kB(최대64kB)만 검색합니다. 그 이후는 매칭이 안되죠.