3. 새로운 netfilter matches

이 절에서, 새로운 netfilter matches의 사용법을 설명할 것이다. 이 패치들은 알파벳 순서로 나타낼 것이다. 부가적으로, 영향을 미치는 다른 패치에 대한 설명은 없다. 이는 다음 버전 문서에 포함될 것이다.

일반적으로, 다음과 같이 하면 특별한 모듈로부터 힌트를 얻을 수 있다.

# iptables -m the_match_you_want --help
	

이는 보통의 iptables 도움말을 보여주고, 거기에 더해서 끝에 명시된 ``원하는 match''에 해당되는 도움말을 보여준다.

3.1. ah-esp patch

이 패치는 Yon Uriarte <yon@astaro.de>에 의해 작성되었고 다음의 2가지 새로운 matches를 한 것이다 :

이 패치는 SPI에 기초한 연결들을 구분짓고자 IPSEC을 사용하는 사람들에게 유용할 수 있다.

예를 들어, 다음과 같이 하면 500과 일치하는 SPI를 가지는 모든 AH 패킷을 드롭시킬수 있다.

# iptables -A INPUT -p 51 -m ah --ahspi 500 -j DROP

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       ipv6-auth--  anywhere             anywhere           ah spi:500
		

ah match가 지원하는 옵션은 다음과 같다 :

esp match도 똑같이 작용한다.

# iptables -A INPUT -p 50 -m esp --espspi 500 -j DROP
# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       ipv6-crypt--  anywhere             anywhere           esp spi:500 
		

esp match가 지원하는 옵션은 다음과 같다 :

ah 또는 esp match를 사용할때, 또는 명백한 이유로 룰 첨가를 중단하고자 할때, ``-p 50'' 또는 ``-p 51'' (esp & ah 각각)을 통해 적절한 프로토콜을 명시하는 것을 잊지 말아야 한다.

3.2. iplimit patch

이 패치는 Gerd Knorr <kraxel@bytesex.org>에 의해 작성되었으며, 특정 호스트나 네트워크로부터의 TCP 연결 갯수를 어떻게 제한하는지에 대한 새로운 match를 한 것이다.

예를 들어, 한 IP 주소에 의한 HTTP 연결 갯수롤 4개로 제한하려고 하면 :

# iptables -A INPUT -p tcp --syn --dport http -m iplimit --iplimit-above 4 -j REJECT

# iptables --list
Chain INPUT (policy ACCEPT)
target   prot opt source    destination         
REJECT   tcp  --  anywhere  anywhere     tcp dpt:http flags:SYN,RST,ACK/SYN #conn/32 > 4 reject-with icmp-port-unreachable
		

또는 예를 들어 class A 전체의 연결 갯수를 제한하기를 원한다면 :

# iptables -A INPUT -p tcp --syn --dport http -m iplimit --iplimit-mask 8 --iplimit-above 4 -j REJECT

# iptables --list
Chain INPUT (policy ACCEPT)
target   prot opt source    destination         
REJECT   tcp  --  anywhere  anywhere     tcp dpt:http flags:SYN,RST,ACK/SYN #conn/8 > 4 reject-with icmp-port-unreachable
		

iplimit patch가 지원하는 옵션은 다음과 같다 :

3.3. ipv4options patch

이 패치는 Fabrice MARIE <fabrice@celestix.com>에 의해 작성되었으며, 설정된 IP 옵션에 의해 패킷을 match할 수 있게 할 수 있도록 새로운 match를 한 것이다.

예를 들어, IP 옵션에 설정된 record-route 또는 timestamp를 가진 모든 패킷을 드롭하려면 다음과 같이 설정한다 :

# iptables -A INPUT -m ipv4options --rr -j DROP
# iptables -A INPUT -m ipv4options --ts -j DROP

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            IPV4OPTS RR
DROP       all  --  anywhere             anywhere            IPV4OPTS TS
		

ipv4options match가 지원하는 옵션은 다음과 같다 :

3.4. length patch

이 패치는 James Morris <jmorris@intercode.com.au>에 의해 작성되었으며, 길이에 기초한 패킷을 match할 수 있게 새로운 match를 한 것이다.

예를 들어, 85 바이트보다 큰 패킷 크기를 가진 모든 ping packet을 드롭하려면 다음과 같이 한다 :

# iptables -A INPUT -p icmp --icmp-type echo-request -m length --length 85:0xffff -j DROP

# ptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       icmp --  anywhere             anywhere           icmp echo-request length 85:65535
		

length match에 대한 부가적인 옵션은 다음과 같다 :

표현되지 않은 value의 범위는 내포되어 있을 것이다. 내포된 value는 최소 0, 최고 65535이다.

3.5. mport patch

이 패치는 Andreas Ferber <af@devcon.net>에 의해 작성되었으며, TCP, UDP 연결에 대해 단일포트와 포트범위를 조합해서 포트를 명시할수 있도록 새로운 match를 한 것이다.

예를 들어, 한 라인에서 ftp, ssh, telnet, http를 막기를 원한다면, 다음과 같이 할 수 있다 :

# iptables -A INPUT -p tcp -m mport --ports 20:23,80 -j DROP

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       tcp  --  anywhere             anywhere           mport ports ftp-data:telnet,http
		

mport match에 대한 부가적인 옵션은 다음과 같다 :

3.6. nth patch

이 패치는 Fabrice MARIE <fabrice@celestix.com>에 의해 작성되었으며, 룰에 의해 받은 특정 N번째 패킷을 match할 수 있도록 새로운 match를 한 것이다.

예를 들어, 매 2번째 핑 패킷을 드롭하길 원한다면, 다음과 같이 할 수 있다 :

# iptables -A INPUT -p icmp --icmp-type echo-request -m nth --every 2 -j DROP

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       icmp --  anywhere             anywhere           icmp echo-request every 2th 
		

이 패치는 Richard Wagner <rwagner@cloudnet.com>에 의해 확장되었는데, 이는 inbound와 outbound 연결에 대한 로드 밸런싱을 제공하는 쉽고 빠른 방법을 만들 수 있게 해준다.

예를 들어, 10.0.0.5, 10.0.0.6, 10.0.0.7의 3개 주소에 대한 로드 밸런싱을 원한다면, 다음과 같이 할 수 있다 :

# iptables -t nat -A POSTROUTING -o eth0 -m nth --counter 7 --every 3 --packet 0 -j SNAT --to-source 10.0.0.5
# iptables -t nat -A POSTROUTING -o eth0 -m nth --counter 7 --every 3 --packet 1 -j SNAT --to-source 10.0.0.6
# iptables -t nat -A POSTROUTING -o eth0 -m nth --counter 7 --every 3 --packet 2 -j SNAT --to-source 10.0.0.7

# iptables -t nat --list
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
SNAT       all  --  anywhere             anywhere           every 3th packet #0 to:10.0.0.5 
SNAT       all  --  anywhere             anywhere           every 3th packet #1 to:10.0.0.6 
SNAT       all  --  anywhere             anywhere           every 3th packet #2 to:10.0.0.7 
		

nth match가 지원하는 옵션은 다음과 같다 :

3.7. pkttype patch

이 패치는 Michal Ludvig <michal@logix.cz>에 의해 작성되었으며, 호스트/브로드캐스트/멀티캐스트 등 그 타입에 기초한 패킷을 match할 수 있도록 새로운 match를 한 것이다.

예를 들어, 모든 브로드캐스트 패킷을 조용히 드롭시키길 원한다면 :

# iptables -A INPUT -m pkttype --pkt-type broadcast -j DROP

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere           PKTTYPE = broadcast 
		

pkttype match가 지원하는 옵션은 다음과 같다 :

3.8. pool patch

Patrick Schaaf <bof@bof.de>.에 의해 패치되었고, Joakim Axelsson and Patrick에 의해 재작성중에 있다. 그러므로 이 부분은 곧 바뀔 것이다.

3.9. psd patch

이 패치는 Dennis Koslowski <dkoslowski@astaro.de>에 의해 작성되었으며, 포트 스캔을 탐지하는데 관한 새로운 match이다.

가장 간단한 형태로, psd match는 다음과 같이 사용될 수 있다 :

# iptables -A INPUT -m psd -j DROP

# iptables --list
Chain INPUT (policy ACCEPT)
target  prot opt source    destination         
DROP    all  --  anywhere  anywhere    psd weight-threshold: 21 delay-threshold: 300 lo-ports-weight: 3 hi-ports-weight: 1
		

psd match가 제공하는 옵션은 다음과 같다 :

3.10. random patch

이 패치는 Fabrice MARIE <fabrice@celestix.com>에 의해 작성되었으며, 주어진 확률에 기초한 패킷을 랜덤하게 계산할 수 있도록 하는 새로운 match이다.

예를 들어, 50%의 핑 패킷을 랜덤하게 드롭하기를 원한다면, 다음과 같이 할 수 있다 :

# iptables -A INPUT -p icmp --icmp-type echo-request -m random --average 50 -j DROP

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source       destination         
DROP       icmp --  anywhere     anywhere        icmp echo-request  random 50% 
		

random patch가 지원하는 옵션은 다음과 같다 :

3.11. realm patch

이 패치는 Sampsa Ranta <sampsa@netsonic.fi>에 의해 작성되었으며, 패킷 분류자에 나타나는 키와 유사한 기준과 일치하는 것으로써 라우팅 영역 키를 사용할 수 있도록 하는 새로운 match이다.

예를 들어, 10개의 영역에서 외부로 향하는 패킷을 모두 로그에 기록하려면, 다음과 같이 할 수 있다 :

# iptables -A OUTPUT -m realm --realm 10 -j LOG

# iptables --list
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
LOG        all  --  anywhere             anywhere           REALM match 0xa LOG level warning
		

realm match가 지원하는 옵션은 다음과 같다 :

3.12. record-rpc patch

이 패치는 Marcelo Barbosa Lima <marcelo.lima@dcc.unicamp.br>에 의해 작성되었으며, 효과적인 RPC 필터링을 허용하기 위해 패킷 소스가 이전에 portmapper를 통해 포트를 요청했을 경우, 또는 portmapper에 대한 새로운 GET 요청일 경우 match하는 데 대한 새로운 match이다.

RPC 연결 추적 정보를 match하기 위해, 간단히 다음과 같이 할 수 있다 :

# iptables -A INPUT -m record_rpc -j ACCEPT

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination 
ACCEPT     all  --  anywhere             anywhere
		

record_rpc match는 어떠한 옵션도 가지지 않는다.

match 정보가 없다고 염려할 것은 없다. 이 match에 대한 print() function이 비어있기 때문에 이는 간단하다.

/* Prints out the union ipt_matchinfo. */
static void
print(const struct ipt_ip *ip,
	const struct ipt_entry_match *match,
	int numeric)
{
}
		

3.13. string patch

이 패치는 Emmanuel Roger <winfield@freegates.be>에 의해 작성되었으며, 패킷의 한 문자열을 match하는 것에 대한 새로운 match이다.

예를 들어, ``cmd.exe'' 문자열을 포함하고 있는 패킷을 match하고 userland IDS로 보내려면, 다음과 같이 할 수 있다 :

# iptables -A INPUT -m string --string 'cmd.exe' -j QUEUE

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
QUEUE      all  --  anywhere             anywhere           STRING match cmd.exe 
		

조심스럽게 이 match를 사용해야 한다. 많은 사람들이 DROP taget에 따라서 웜 바이러스를 멈추기 위해 이 match를 사용하길 원한다. 이는 중요한 실수이다. 특정 IDS 침입 방법은 이를 무력화할수 있다.

유사한 경향으로, 많은 사람들은 POST 문자열을 포함하는 HTTP 패킷을 드롭함으로써 POST나 GET같은 HTTP의 특정 기능을 멈추기 위한 수단으로 이 match를 사용하기를 원했었다. 이러한 작업은 proxy를 필터링하는 것이 더 좋은 방법임을 이해하라. 부가적으로 POST란 단어를 가지고 있는 HTML content는 이전 방법(설정)에 의해 드롭될 것이다. 이 match는 더 좋은 분석을 위해 유저영역의 관심있는 패킷을 큐잉할수 있게 하기 위해 설계되었다. 이것이 전부이다. 이 방법에 의해 패킷을 드롭하는 것은 특정 IDS 침입 방법에 의해 무력화될 수 있다.

string match가 지원하는 옵션은 다음과 같다 :

3.14. time patch

이 패치는 Fabrice MARIE <fabrice@celestix.com>에 의해 작성되었으며, 출발 혹은 도착 (로컬에서 생성된 패킷) 시간에 기초한 패킷을 match할 수 있도록 하는 새로운 match이다.

예를 들어, 월요일부터 금요일까지 8:00부터 18:00까지 도착 시간을 가진 패킷을 허용하려면 다음과 같이 할 수 있다 :

# iptables -A INPUT -m time --timestart 8:00 --timestop 18:00 --days Mon,Tue,Wed,Thu,Fri -j ACCEPT

# iptables --list 
Chain INPUT (policy ACCEPT)
target     prot opt source           destination
ACCEPT     all  --  anywhere         anywhere        TIME from 8:0 to 18:0 on Mon,Tue,Wed,Thu,Fri 
		

time match가 지원하는 옵션은 다음과 같다 :

3.15. ttl patch

이 패치는 Harald Welte <laforge@gnumonks.org>에 의해 작성되었으며, TTL에 기초한 패킷을 match할 수 있도록 하는 새로운 match이다.

예를 들어, TTL이 5보다 적은 패킷을 로그에 기록하려면, 당신은 다음과 같이 할 수 있다 :

# iptables -A INPUT -m ttl --ttl-lt 5 -j LOG

# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
LOG        all  --  anywhere             anywhere           TTL match TTL < 5 LOG level warning
		

ttl match가 지원하는 옵션은 다음과 같다.