TCP SYN_Flooding 공격의 원인과 해결책

Tags:

http://nix.ko21.com/bbs/view.php?id=unix&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=hit&desc=asc&no=104

원문이 한글이니 저절로 한글포스팅이 되는군요. 뭐…
사실 이만큼 잘 정리된 문서가 별로 없네요.

—————————-

[root@control src]# sysctl -a | grep syncookienet.ipv4.tcp_syncookies = 0

0으로 설정되어 있으므로 현재 syncookies는 적용되지 않는다. 따라서 다음과 같이 1을 설정하여 syncookies 기능을 활성화도록 한다.

[root@control src]# sysctl -w net.ipv4.tcp_syncookies=1

sysctl -w net.ipv4.icmp_destunereach_rate=1
# 1/100초 동안 받아들일 수 있는 “dest unreach (type 3) icmp”의 개수
sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1
# Broadcast로부터 오는 핑을 차단함(Smurt 공격을 차단함).
sysctl -w net.ipv4.icmp_echoreply_rate=1
# 1/100초에 반응하는 핑의 최대 숫자
sysctl -w net.ipv4.icmp_echo_ignore_all=1
# 모든 핑을 차단함
sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1
# IP 나 TCP 헤더가 깨진 bad icmp packet을 무시한다.
sysctl -w net.ipv4.icmp_paramprob_rate=1
# 1/100 초에 받아들이는 param probe packet의 수
sysctl -w net.ipv4.icmp_timeexceed_rate=1
# 1/100 초에 받아들이는 timeexceed 패킷의 수(traceroute와 관련)
sysctl -w net.ipv4.igmp_max_memberships=1
# 1/100초에 받아들이는 igmp “memberships”의 수
sysctl -w net.ipv4.ip_default_ttl=64
# 매우 복잡한 사이트에서는 이 값을 늘리는 것도 가능하지만 64로 두는 것이 적당하며 더 늘렸을 경우에는 큰 문제가 발생할 수도 있다.
sysctl -w net.ipv4.ip_forward=0
# 게이트웨이 서버가 아닌 이상 패킷을 포워딩 할 필요는 없다.
sysctl -w net.ipv4.ipfrag_time=15
# fragmented packet이 메모리에 존재하는 시간을 15초로 설정한다.
sysctl -w net.ipv4.tcp_syn_retries=3
# 일정한 시간과 IP별로 보내고 받는 SYN 재시도 횟수를 3회로 제한한다. 이 옵션은 스푸핑된(위조된) 주소로 오는 SYN 연결의 양을 줄여준다. 기본 값은 5이며 255를 넘지 않아야 한다.
sysctl -w net.ipv4.tcp_retries1=3
# 무언가 문제가 있을 때 연결을 위해 재시도 할 횟수, 최소 값과 기본 값은 3이다.
sysctl -w net.ipv4.tpc_retries2=7
# TCP 연결을 끊기 전에 재시도할 횟수.
sysctl -w net.ipv4.conf.eth0.rp_filter=2
sysctl -w net.ipv4.conf.lo.rp_filter=2
sysctl -w net.ipv4.conf.default.rp_filter=2
sysctl -w net.ipv4.conf.all.rp_filter=2
# 이 설정은 자신의 네트워크가 스푸핑된 공격지의 소스로 쓰이는 것을 차단한다. 모든 인터페이스에서 들어오는 패킷에 대해 reply를 하여 들어오는 인터페이스로 나가지 못하는 패킷을 거부한다.
sysctl -w net.ipv4.conf.eth0.accept_redirect=0
sysctl -w net.ipv4.conf.lo.accept_redirect=0
sysctl -w net.ipv4.conf.default.accept_redirect=0
sysctl -w net.ipv4.conf.all.accept_redirect=0
# icmp redirects를 허용하지 않는다. 만약 ICMP Redirect를 허용할 경우에는 공격자가 임의의 라우팅 테이블을 변경할 수 있게 되어 자신이 의도하지 않는 경로, 즉 공격자가 의도한 경로로 트래픽이 전달될 수 있는 위험이 있다.
sysctl -w net.ipv4.conf.eth0.accept_source_route=0
sysctl -w net.ipv4.conf.lo.accept_source_route=0
sysctl -w net.ipv4.conf.default.accept_source_route=0
sysctl -w net.ipv4.conf.all.accept_source_route=0
# 스푸핑을 막기 위해 source route 패킷을 허용하지 않는다. 소스 라우팅을 허용할 경우 악의적인 공격자가 IP 소스 라우팅을 사용해서 목적지의 경로를 지정할 수도 있고, 원래 위치로 돌아오는 경로도 지정할 수 있다. 이러한 소스 라우팅이 가능한 것을 이용해 공격자가 마치 신뢰받는 호스트나 클라이언트인 것처럼 위장할 수 있는 것이다.
sysctl -w net.ipv4.conf.eth0.bootp_relay=0
sysctl -w net.ipv4.conf.lo.bootp_relay=0
sysctl -w net.ipv4.conf.default.bootp_relay=0
sysctl -w net.ipv4.conf.all.bootp_relay=0
# bootp 패킷을 허용하지 않는다.
sysctl -w net.ipv4.conf.eth0.log_martians=0
sysctl -w net.ipv4.conf.lo.log_martians=0
sysctl -w net.ipv4.conf.default.log_martians=0
sysctl -w net.ipv4.conf.all.log_martians=0
# 스푸핑된 패킷이나 소스라우팅, Redirect 패킷에 대해 로그파일에 정보를 남긴다.
sysctl -w net.ipv4.conf.eth0.secure_redirects=0
sysctl -w net.ipv4.conf.lo.secure_redirects=0
sysctl -w net.ipv4.conf.default.secure_redirects=0
sysctl -w net.ipv4.conf.all.secure_redirects=0
# 게이트웨이로부터의 redirect를 허용하지 않음으로써 스푸핑을 막기 위해 설정한다.
sysctl -w net.ipv4.conf.eth0.send_redirects=0
sysctl -w net.ipv4.conf.lo.send_redirects=0
sysctl -w net.ipv4.conf.default.send_redirects=0
sysctl -w net.ipv4.conf.all.send_redirects=0
# icmp redirects를 보내지 않는다.
sysctl -w net.ipv4.conf.eth0.proxy_arp=0
sysctl -w net.ipv4.conf.lo.proxy_arp=0
sysctl -w net.ipv4.conf.default.proxy_arp=0
sysctl -w net.ipv4.conf.all.proxy_arp=0
# proxy arp를 설정하지 않는다. 이 값이 1로 설정되었을 경우 proxy_arp가 설정된 인터페이스에 대해 arp 질의가 들어왔을 때 모든 인터페이스가 반응하게 된다.
sysctl -w net.ipv4.tcp_keealive_time=30
# 이미 프로세스가 종료되어 불필요하게 남아 있는 연결을 끊는 시간을 줄이도록 한다.
sysctl -w net.ipv4.tcp_fin_timeout=30
# 연결을 종료시 소요되는 시간을 줄여준다(기본 설정값: 60).
sysctl -w net.ipv4.tcp_tw_buckets=720000
# 동시에 유지 가능한 timewait 소켓의 수이다. 만약 지정된 숫자를 초과하였을 경우에는 timewait 소켓이 없어지며 경고 메시지가 출력된다. 이 제한은 단순한 DoS 공격을 차단하기 위해 존재하는데, 임의로 이 값을 줄여서는 안되며 메모리가 충분하다면 적절하게 늘려주는 것이 좋은데, 64M 마다 180000으로 설정하면 된다. 따라서 256M일 경우에는 256/4=4 4*180000=720000
sysctl -w net.ipv4.tcp_keepalive_probes=2
sysctl -w net.ipv4.tcp_max_ka_probes=100
# 간단한 DoS 공격을 막아준다.

iptables -A INPUT -s 10.0.0./8 -j DROP
iptables -A INPUT -s 172.0.0./12 -j DROP
iptables -A INPUT -s 192.0.0./24 -j DROP
# 사설 IP를 차단한다. /8, /16 등은 CIDR이라 하며 /8은 A Class, /16은 B Class를 뜻한다.
iptables -A INPUT -s 255.255.255.255/32 -j DROP
iptables -A INPUT -s 127.0.0./8 -j DROP
# 일반적으로 라우팅이 되지 않는 IP 대역을 차단한다.
iptables -A INPUT -s 240.0.0.0/5 -j DROP
# IANA에 예약된 주소를 차단한다.
iptables -A INPUT -s 211.2.3.4 -j DROP
# 아울러 자기 자신의 IP를 소스로 하는 패킷도 필터링한다(211.2.3.4 대신 자신의 IP입력). 자신의 IP를 소스로 해서 패킷이 들어올 수는 없다.
0.0.0.0/8 – Historical Broadcast
10.0.0.0/8 – RFC 1918에 의한 내부 네트워크
127.0.0.0/8 – Loopback
169.254.0.0/16 – Link Local Networks
172.16.0.0/16 – RFC 1918에 의한 내부 네트워크
192.0.2.0/24 – TEST-NET
192.168.0.0/16 – RFC 1918에 의한 내부 네트워크
224.0.0.0/4 – Multicast D Class
240.0.0.0/5 – 예약된 E Class
248.0.0.0/5 – 미할당
255.255.255.255/32 – 브로트캐스트

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *