리눅스, 자료실, 성경검색, 추억의게임, 고전게임, 오락실게임, rootman, http://www.rootman.co.kr
* 54.196.42.8 *
| Home | Profile | Linux | 자료실 | zabbix | Mysql 5.6 | 갤러리 | 성경검색 | 해피니스 | 자유게시판 | 게시물검색 | L | O | R |    

 
[Doc/Faq] mod_dosevasive 를 통한 apache 웹서버 Dos 막기
 작성자 : rootman
Date : 2003-12-07 23:58  |  Hit : 20,646  
--------------------------------------------------
* mod_dosevasive이란 무엇인가
--------------------------------------------------
이것은 HTTP Dos 또는 DDos 스택 또는 저돌적인 공격으로부터 아파치를 보호하는데 있습니다.
이것은 ipchains, 방화벽, 라우터등으로 쉽게 구성될 수 있도록 디자인 되었습니다.

탐지는 주소, URI의 IP 내부 동적 해쉬테이블을 생성함으로 수행되고, 각 아이피별로 거부됩니다.
- 초당 몇번 이상의 같은 페이지를 요청하는 경우
- 초당 같은 자식노드를 동시에 50번 이상 생성하는 경우
- 일시적으로 블러킹되는 동안 어떠한 요청을 생성하는 경우

--------------------------------------------------
1. mod_dosevasive 설치
--------------------------------------------------
다운로드 : http://www.rootman.co.kr/bbs/zboard.php?category=11&id=dataroom
http://www.nuclearelephant.com/projects/dosevasive/

[[email protected] root]# tar xvfz mod_dosevasive.1.8.tar.gz
[[email protected] root]# cd /usr/local/apache/bin
[[email protected] bin]# ./apxs -iac ../mod_dosevasive/mod_dosevasive.c
[[email protected] bin]# ./apxs -iac ../mod_dosevasive/mod_dosevasive.c
gcc -DLINUX=22 -DUSE_HSREGEX -fpic -DSHARED_CORE -DSHARED_MODULE -I/usr/local/apache/include -c ../mod_dosevasive/mod_dosevasive.c
gcc -shared -o ../mod_dosevasive/mod_dosevasive.so mod_dosevasive.o
[activating module `dosevasive' in /usr/local/apache/conf/httpd.conf]
cp ../mod_dosevasive/mod_dosevasive.so /usr/local/apache/libexec/mod_dosevasive.so
chmod 755 /usr/local/apache/libexec/mod_dosevasive.so
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak
cp /usr/local/apache/conf/httpd.conf.new /usr/local/apache/conf/httpd.conf
rm /usr/local/apache/conf/httpd.conf.new

[[email protected] root]# vi /usr/local/apache/conf/httpd.conf <--- 아래두줄이 추가되었나 확인한다.<BR> LoadModule dosevasive_module libexec/mod_dosevasive.so
AddModule mod_dosevasive.c

[[email protected] /root]# /usr/local/apache/bin/apachectl graceful <--- 아파치재가동시킨다.<BR>

--------------------------------------------------
2. httpd.conf에는 다음과 같이 설정을 추가한다.
--------------------------------------------------

DOSHashTableSize 3097
DOSPageCount 3
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 3600


----------------------------------------------
추가적으로 지시자를 추가하실 수 있습니다.
----------------------------------------------
DOSEmailNotify [email protected]
DOSSystemCommand "su - someuser -c '/sbin/... %s ...'"

- DOSHashTableSize 
각 자식 해쉬테이블 마다 탑레벨 노드의 수를 지정합니다.
수치가 높으면 높을수록 더 많은 퍼포먼스가 나타나지만 테이블스페이스에 메모리를 남기게 된다

접속량이 많으면 이 수치를 높혀도 된다.

- DOSPageCount
이것은 같은 페이지 또는 URI, 인터벌당 요청수에 대한 카운트 수이다.
지정된 값이 초과되면 클라이언트에 대한 IP 정보가 블러킹리스트에 추가된다.

- DOSSiteCount
지정된 시간동안 같은 페이지를 지정된 수 보다 초과될경우 IP 정보가 블러킹리스트에 추가된다.


- DOSPageInterval
페이지 카운트 시발점, 디폴트는 1초이다.

- DOSSiteInterval
사이트 카운트 시발점, 디폴트는 역시 1초이다.

- DOSBlockingPeriod
클라이언트가 블랙리스트에 추가되어 블러킹되는 총 시간.
이때 클라이언트는 403 (Forbidden) 에러를 출력하게 된다.

- DOSEmailNotify
이 값이 지정되면, IP가 블러킹될때마다 지정된 이메일로 발동된다.

주의 : 메일러는 mod_dosevasive.c 에 정확하게 지정되야 한다.
디폴트는 "/bin/mail -t %s" 이다.

- DOSSystemCommand
이 값이 지정되면, 시스템은 아이피가 블러킹될때마다 명령행을 실행한다.
이것은 아이피 필터링이나 다른 도구를 사용하도록 설계되었습니다.



--------------------------------------------------
3. 인가된 IP 주소 할당
--------------------------------------------------
버전 1.8에서는 아이피가 블러킹되더라도 인가된 클라이언트 아이피에 대해서는 적용되지 않습니다.
인가시키는 목적은 소프트웨어, 스크립트, 로컬서치로봇, 해당 서버로부터의 많은 요청인한 웹거부로 부터의 또다른 프로그램을 보호하는데 있습니다.

아파치에서 설정하는 방법은 다음과 같습니다.

DOSWhitelist 127.0.0.1
DOSWhitelist 127.0.0.*

와일드카드는(*) 필요하다면 최대 8진수(xxx.*.*.*)까지 사용할 수 있습니다.


--------------------------------------------------
4. 테스트 하기
--------------------------------------------------
[[email protected] mod_dosevasive]# perl test.pl
HTTP/1.1 200 OK
HTTP/1.1 403 Forbidden
HTTP/1.1 200 OK
HTTP/1.1 403 Forbidden
HTTP/1.1 403 Forbidden


--------------------------------------------------
5. 원문보기
--------------------------------------------------

Apache DoS Evasive Maneuvers Module
For Apache 1.3 and 2.0
Copyright (c) 2002 Network Dweebs Corporation
Version 1.8 [2003.0901.1845]


LICENSE

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


WHAT IS MOD_DOSEVASIVE ?

mod_dosevasive is an evasive maneuvers module for Apache to provide evasive action in the event of an HTTP DoS or DDoS attack or brute force attack.
It is also designed to be a detection tool, and can be easily configured to talk to ipchains, firewalls, routers, and etcetera.

Detection is performed by creating an internal dynamic hash table of IP Addresses and URIs, and denying any single IP address from any of the following:

- Requesting the same page more than a few times per second
- Making more than 50 concurrent requests on the same child per second
- Making any requests while temporarily blacklisted (on a blocking list)

This method has worked well in both single-server script attacks as well as distributed attacks, but just like other evasive tools, is only as
useful to the point of bandwidth and processor consumption (e.g. the amount of bandwidth and processor required to receive/process/respond
to invalid requests), which is why it's a good idea to integrate this with your firewalls and routers.

This module instantiates for each listener individually, and therefore has a built-in cleanup mechanism and scaling capabilities. Because of this,
legitimate requests are never compromised but only scripted attacks.
Even a user repeatedly clicking on 'reload' should not be affected unless they do it maliciously.

Two different module sources have been provided:

Apache v1.3 API: mod_dosevasive.c
Apache v2.0 API: mod_dosevasive20.c


HOW IT WORKS

A web hit request comes in. The following steps take place:

- The IP address of the requestor is looked up on the temporary blacklist
- The IP address of the requestor and the URI are both hashed into a "key".
A lookup is performed in the listener's internal hash table to determine
if the same host has requested this page more than once within the past 1 second.
- The IP address of the requestor is hashed into a "key".
A lookup is performed in the listerner's internal hash table to determine
if the same host has requested more than 50 objects within the past second (from the same child).

If any of the above are true, a 403 response is sent.
This conserves bandwidth and system resources in the event of a DoS attack.
Additionally, a system command and/or an email notification can also be triggered to block all the originating addresses of a DDoS attack.

Once a single 403 incident occurs, mod_dosevasive now blocks the entire IP address for a period of 10 seconds (configurable).
If the host requests a
page within this period, it is forced to wait even longer.
Since this is triggered from requesting the same URL multiple times per second, this again does not affect legitimate users.

The blacklist can/should be configured to talk to your network's firewalls and/or routers to push the attack out to the front lines, but this is not required.

mod_dosevasive also performs syslog reporting using daemon.alert. Messages
will look like this:

Aug 6 17:41:49 elijah mod_dosevasive[23184]: [ID 801097 daemon.alert] Blacklisting address x.x.x.x: possible DoS attack.


WHAT IS THIS TOOL USEFUL FOR?

This tool is *excellent* at fending off small to medium-sized request-based DoS attacks or script attacks and brute force attacks.
Its features will prevent you from wasting bandwidth or having a few thousand CGI scripts running as a result of an attack.
When used in conjunction with other preventative measures such as router blackholing, this tool is very effective against larger DDoS attacks as well.

If you do not have an infrastructure capable of fending off any other types of DoS attacks, chances are this tool will only help you to the point of
your total bandwidth or server capacity for sending 403's.
Without a solid infrastructure and DoS evasion plan in place, a heavy distributed DoS will most likely still take you offline.


HOW TO INSTALL

APACHE v1.3
-----------

Without DSO Support:

1. Extract this archive into src/modules in the Apache source tree
2. Run ./configure --add-module=src/modules/dosevasive/mod_dosevasive.c
3. make, install
4. Restart Apache


With DSO Support, Ensim, or CPanel:

1. $APACHE_ROOT/bin/apxs -iac mod_dosevasive.c
2. Restart Apache


APACHE v2.0
-----------

1. Extract this archive
2. Run $APACHE_ROOT/bin/apxs -i -a -c mod_dosevasive20.c
3. The module will be built and installed into $APACHE_ROOT/modules, and loaded into your httpd.conf
4. Restart Apache


CONFIGURATION

mod_dosevasive has default options configured, but you may also add the following block to your httpd.conf:


APACHE v1.3
-----------


DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10


APACHE v2.0
-----------

DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10


Optionally you can also add the following directives:

DOSEmailNotify [email protected]
DOSSystemCommand "su - someuser -c '/sbin/... %s ...'"

You will also need to add this line if you are building with dynamic support:

APACHE v1.3
-----------
AddModule mod_dosevasive.c


APACHE v2.0
-----------
LoadModule dosevasive20_module modules/mod_dosevasive20.so

(This line is already added to your configuration by apxs)


DOSHashTableSize
----------------
The hash table size defines the number of top-level nodes for each child's hash table.
Increasing this number will provide faster performance by decreasing the number of iterations required to get to the record, but consume more memory for table space.
You should increase this if you have a busy web server.
The value you specify will automatically be tiered up to the next prime number in the primes list (see mod_dosevasive.c for a list of primes used).


DOSPageCount
------------
This is the threshhold for the number of requests for the same page (or URI) per page interval.
Once the threshhold for that interval has been exceeded, the IP address of the client will be added to the blocking list.


DOSSiteCount
------------
This is the threshhold for the total number of requests for any object by the same client on the same listener per site interval.
Once the threshhold
for that interval has been exceeded, the IP address of the client will be added to the blocking list.


DOSPageInterval
---------------
The interval for the page count threshhold; defaults to 1 second intervals.


DOSSiteInterval
---------------
The interval for the site count threshhold; defaults to 1 second intervals.


DOSBlockingPeriod
-----------------
The blocking period is the amount of time (in seconds) that a client will be blocked for if they are added to the blocking list.
During this time, all subsequent requests from the client will result in a 403 (Forbidden) and the timer being reset (e.g. another 10 seconds).
Since the timer is reset for every subsequent request, it is not necessary to have a long blocking period; in the event of a DoS attack, this timer will keep getting reset.


DOSEmailNotify
--------------

If this value is set, an email will be sent to the address specified
whenever an IP address becomes blacklisted. A locking mechanism using /tmp
prevents continuous emails from being sent.

NOTE: Be sure MAILER is set correctly in mod_dosevasive.c
(or mod_dosevasive20.c). The default is "/bin/mail -t %s" where %s is
used to denote the destination email address set in the configuration.
If you are running on linux or some other operating system with a
different type of mailer, you'll need to change this.


DOSSystemCommand
----------------
If this value is set, the system command specified will be executed whenever an IP address becomes blacklisted.
This is designed to enable system calls to ip filter or other tools.
A locking mechanism using /tmp prevents continuous system calls.
Use %s to denote the IP address of the blacklisted IP.


WHITELISTING IP ADDRESSES

As of version 1.8, IP addresses of trusted clients can be whitelisted to insure they are never denied.
The purpose of whitelisting is to protect software, scripts, local searchbots, or other automated tools from being denied for requesting large amounts of data from the server.
Whitelisting should *not* be used to add customer lists or anything of the sort, as this will open the server to abuse.
This module is very difficult to trigger without performing some type of malicious attack, and for that reason it is more appropriate to allow the module to decide on its own whether or not an individual customer should be blocked.

To whitelist an address (or range) add an entry to the Apache configuration
in the following fashion:

DOSWhitelist 127.0.0.1
DOSWhitelist 127.0.0.*


Wildcards can be used on up to the last 3 octets if necessary.
Multiple DOSWhitelist commands may be used in the configuration.


TWEAKING APACHE

The keep-alive settings for your children should be reasonable enough to keep each child up long enough to resist a DOS attack (or at least part of one).
For every child that exits, another 5-10 copies of the page may get through before putting the attacker back into '403 Land'.
With this said,
you should have a very high MaxRequestsPerChild, but not unlimited as this will prevent cleanup.

You'll want to have a MaxRequestsPerChild set to a non-zero value, as DosEvasive cleans up its internal hashes only on exit.
The default MaxRequestsPerChild is usually 10000.
This should suffice in only allowing a few requests per 10000 per child through in the event of an attack (although if you use DOSSystemCommand to firewall the IP address, a hole will no longer be open in between child cycles).


TESTING

Want to make sure it's working? Run test.pl, and view the response codes.
If the target machine is not localhost, be sure to change it in the script first.
You should receive 403 responses after the first 25-50 requests, depending on your server configuration.
Please don't use this script to DoS others without their permission.


KNOWN BUGS

- This module appears to conflict with the Microsoft Frontpage Extensions


FEEDBACK

Please email me with questions, constructive comments, or feedback:
[email protected]


 
 

Total. 645
번호 분류 제목 작성자 등록일 조회수
645 기초강좌 NFS server unable to open connection to tcp6/udp6 networks rootman 09-27 2080
644 php [php] mssql ms-sql 한글 변환 끄적임.. 정리 rootman 03-29 3015
643 기초강좌 java vim 에서 자바 환경 만들기 rootman 02-16 2335
642 삭제예정 [xencenter] xenserver tool 설치 rootman 08-24 3277
641 mysql [mysql] Creating a File-Per-Table Tablespace Outside the Dat… rootman 08-03 3447
640 기초강좌 Centos Xwindow 설치 rootman 06-16 4305
639 php [php] highlight 함수 rootman 04-01 4162
638 qmail [qmail] qmail-scanner에 filtering 된 이메일 처리 rootman 02-14 4602
637 Shell [날짜] awk를 이용하여 unixtime의 시간 차 구하기 rootman 01-27 5348
636 기초강좌 centos에 그놈(gnome) 설치하기 rootman 01-10 5224
635 쉘(awk) [awk] shell 변수 사용하기 rootman 12-27 5091
634 기초강좌 서버 캐시 메모리 초기화하기 (drop_caches) rootman 12-11 5943
633 windows tips 그리드 제거 배치 스크립트 rootman 11-28 5660
632 기초강좌 패스워드 lockgin control rootman 09-06 4
631 windows tips win7 자동 로그인 설정하기 rootman 08-18 5320
 1  2  3  4  5  6  7  8  9  10    
AND OR