• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

CHANGELOGH A D22-Feb-20171.3 KiB7342

LICENSEH A D22-Feb-201717.7 KiB14787

Makefile.tmplH A D22-Feb-2017470 1610

READMEH A D22-Feb-201713.9 KiB379271

mod_evasive.cH A D03-May-202218.9 KiB710497

mod_evasive20.cH A D03-May-202217.8 KiB700487

mod_evasiveNSAPI.cH A D03-May-202215.3 KiB609413

test.plH A D03-May-2022410 1912

README

1Apache Evasive Maneuvers Module
2For Apache 1.3 and 2.0
3Jonathan Zdziarski
4Version 1.10 [2005.0117]
5
6LICENSE
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; version 2
11of the License.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
22WHAT IS MOD_EVASIVE ?
23
24mod_evasive is an evasive maneuvers module for Apache to provide evasive
25action in the event of an HTTP DoS or DDoS attack or brute force attack.  It
26is also designed to be a detection tool, and can be easily configured to talk
27to ipchains, firewalls, routers, and etcetera.
28
29Detection is performed by creating an internal dynamic hash table of IP
30Addresses and URIs, and denying any single IP address from any of the following:
31
32- Requesting the same page more than a few times per second
33- Making more than 50 concurrent requests on the same child per second
34- Making any requests while temporarily blacklisted (on a blocking list)
35
36This method has worked well in both single-server script attacks as well
37as distributed attacks, but just like other evasive tools, is only as
38useful to the point of bandwidth and processor consumption (e.g. the
39amount of bandwidth and processor required to receive/process/respond
40to invalid requests), which is why it's a good idea to integrate this
41with your firewalls and routers.
42
43This module instantiates for each listener individually, and therefore has
44a built-in cleanup mechanism and scaling capabilities.  Because of this,
45legitimate requests are rarely ever compromised, only legitimate attacks.  Even
46a user repeatedly clicking on 'reload' should not be affected unless they do
47it maliciously.
48
49Three different module sources have been provided:
50
51Apache v1.3 API:	mod_evasive.c
52Apache v2.0 API:	mod_evasive20.c
53NSAPI (iPlanet):	mod_evasiveNSAPI.c *
54
55NOTE: mod_evasiveNSAPI is a port submitted by Reine Persson <reiper@rsv.se>
56      and is not officially supported as part of the mod_evasive project.
57
58HOW IT WORKS
59
60A web hit request comes in. The following steps take place:
61
62- The IP address of the requestor is looked up on the temporary blacklist
63- The IP address of the requestor and the URI are both hashed into a "key".
64  A lookup is performed in the listener's internal hash table to determine
65  if the same host has requested this page more than once within the past
66  1 second.
67- The IP address of the requestor is hashed into a "key".
68  A lookup is performed in the listerner's internal hash table to determine
69  if the same host has requested more than 50 objects within the past
70  second (from the same child).
71
72If any of the above are true, a 403 response is sent.  This conserves
73bandwidth and system resources in the event of a DoS attack.  Additionally,
74a system command and/or an email notification can also be triggered to block
75all the originating addresses of a DDoS attack.
76
77Once a single 403 incident occurs, mod_evasive now blocks the entire IP
78address for a period of 10 seconds (configurable).  If the host requests a
79page within this period, it is forced to wait even longer.  Since this is
80triggered from requesting the same URL multiple times per second, this
81again does not affect legitimate users.
82
83The blacklist can/should be configured to talk to your network's firewalls
84and/or routers to push the attack out to the front lines, but this is not
85required.
86
87mod_evasive also performs syslog reporting using daemon.alert.  Messages
88will look like this:
89
90Aug  6 17:41:49 elijah mod_evasive[23184]: [ID 801097 daemon.alert] Blacklisting address x.x.x.x: possible attack.
91
92WHAT IS THIS TOOL USEFUL FOR?
93
94This tool is *excellent* at fending off request-based DoS attacks or scripted
95attacks, and brute force attacks. When integrated with firewalls or IP filters,
96mod_evasive can stand up to even large attacks. Its features will prevent you
97from wasting bandwidth or having a few thousand CGI scripts running as a
98result of an attack.
99
100If you do not have an infrastructure capable of fending off any other types
101of DoS attacks, chances are this tool will only help you to the point of
102your total bandwidth or server capacity for sending 403's.  Without a solid
103infrastructure and address filtering tool in place, a heavy distributed DoS
104will most likely still take you offline.
105
106HOW TO INSTALL
107
108APACHE v1.3
109-----------
110
111Without DSO Support:
112
1131. Extract this archive into src/modules in the Apache source tree
114
1152. Run ./configure --add-module=src/modules/evasive/mod_evasive.c
116
1173. make, install
118
1194. Restart Apache
120
121With DSO Support, Ensim, or CPanel:
122
1231. $APACHE_ROOT/bin/apxs -iac mod_evasive.c
124
1252. Restart Apache
126
127APACHE v2.0
128-----------
129
1301. Extract this archive
131
1322. Run $APACHE_ROOT/bin/apxs -i -a -c mod_evasive20.c
133
1343. The module will be built and installed into $APACHE_ROOT/modules, and loaded into your httpd.conf
135
1364. Restart Apache
137
138NSAPI
139SunONE (iPlanet,netscape) Installation
140--------------------------------------
141
142Tested on:
143iPlanet 4.1sp12
144iPlanet 6.0sp5
145
146Edit compile script for your environment and compile mod_evasiveNSAPI.c
147to a shared library.
148
149CONFIGURATION
150
151mod_evasive has default options configured, but you may also add the
152following block to your httpd.conf:
153
154APACHE v1.3
155-----------
156
157<IfModule mod_evasive.c>
158    DOSHashTableSize    3097
159    DOSPageCount        2
160    DOSSiteCount        50
161    DOSPageInterval     1
162    DOSSiteInterval     1
163    DOSBlockingPeriod   10
164</IfModule>
165
166APACHE v2.0
167-----------
168<IfModule mod_evasive20.c>
169    DOSHashTableSize    3097
170    DOSPageCount        2
171    DOSSiteCount        50
172    DOSPageInterval     1
173    DOSSiteInterval     1
174    DOSBlockingPeriod   10
175</IfModule>
176
177Optionally you can also add the following directives:
178
179    DOSEmailNotify	you@yourdomain.com
180    DOSSystemCommand	"su - someuser -c '/sbin/... %s ...'"
181    DOSLogDir		"/var/lock/mod_evasive"
182
183You will also need to add this line if you are building with dynamic support:
184
185APACHE v1.3
186-----------
187
188AddModule	mod_evasive.c
189
190APACHE v2.0
191-----------
192
193LoadModule evasive20_module modules/mod_evasive20.so
194
195(This line is already added to your configuration by apxs)
196
197NSAPI
198SunONE (iPlanet,Netscape) Configuration
199--------------------------------------
200
201Configure iPlanet 4.1
202---------------------
203
204Edit obj.conf:
205
206Init fn="load-modules" funcs="mod_evasive_init,mod_evasive_check" shlib="/opt/ns-4.1/plugins/lib/mod_evasive.sl"
207
208Init fn="mod_evasive_init" DOSPageCount=2 DOSSiteCount=50 DOSPageInterval=1 DOSSiteInterval=1 DOSBlockingPeriod=10 DOSWhitelist="10.60.0.7,10.65.0.10"
209
210In the default object:
211PathCheck fn=mod_evasive_check
212
213Or an own object
214<Object name="evasive" ppath="/DoSProtectedArea*">
215NameTrans fn=mod_evasive_check
216</Object>
217
218
219Configure iPlanet 6.0
220---------------------
221
222Edit magnus.conf:
223
224Init fn="load-modules" funcs="mod_evasive_init,mod_evasive_check" shlib="/opt/iplanet-6.0/plugins/lib/mod_evasive.sl"
225
226Init fn="mod_evasive_init" DOSWhitelist="10.60.0.7,10.65.0.10"
227
228Edit obj.conf:
229In the default object:
230PathCheck fn=mod_evasive_check
231
232Or an own object
233<Object name="evasive" ppath="/DoSProtectedArea*">
234NameTrans fn=mod_evasive_check
235</Object>
236
237DOSHashTableSize
238----------------
239
240The hash table size defines the number of top-level nodes for each child's
241hash table.  Increasing this number will provide faster performance by
242decreasing the number of iterations required to get to the record, but
243consume more memory for table space.  You should increase this if you have
244a busy web server.  The value you specify will automatically be tiered up to
245the next prime number in the primes list (see mod_evasive.c for a list
246of primes used).
247
248DOSPageCount
249------------
250
251This is the threshhold for the number of requests for the same page (or URI)
252per page interval.  Once the threshhold for that interval has been exceeded,
253the IP address of the client will be added to the blocking list.
254
255DOSSiteCount
256------------
257
258This is the threshhold for the total number of requests for any object by
259the same client on the same listener per site interval.  Once the threshhold
260for that interval has been exceeded, the IP address of the client will be added
261to the blocking list.
262
263DOSPageInterval
264---------------
265
266The interval for the page count threshhold; defaults to 1 second intervals.
267
268DOSSiteInterval
269---------------
270
271The interval for the site count threshhold; defaults to 1 second intervals.
272
273DOSBlockingPeriod
274-----------------
275
276The blocking period is the amount of time (in seconds) that a client will be
277blocked for if they are added to the blocking list.  During this time, all
278subsequent requests from the client will result in a 403 (Forbidden) and
279the timer being reset (e.g. another 10 seconds).  Since the timer is reset
280for every subsequent request, it is not necessary to have a long blocking
281period; in the event of a DoS attack, this timer will keep getting reset.
282
283DOSEmailNotify
284--------------
285
286If this value is set, an email will be sent to the address specified
287whenever an IP address becomes blacklisted.  A locking mechanism using /tmp
288prevents continuous emails from being sent.
289
290NOTE: Be sure MAILER is set correctly in mod_evasive.c
291      (or mod_evasive20.c).  The default is "/bin/mail -t %s" where %s is
292      used to denote the destination email address set in the configuration.
293      If you are running on linux or some other operating system with a
294      different type of mailer, you'll need to change this.
295
296DOSSystemCommand
297----------------
298
299If this value is set, the system command specified will be executed
300whenever an IP address becomes blacklisted.  This is designed to enable
301system calls to ip filter or other tools.  A locking mechanism using /tmp
302prevents continuous system calls.  Use %s to denote the IP address of the
303blacklisted IP.
304
305DOSLogDir
306---------
307
308Choose an alternative temp directory
309
310By default "/tmp" will be used for locking mechanism, which opens some
311security issues if your system is open to shell users.
312
313  	http://security.lss.hr/index.php?page=details&ID=LSS-2005-01-01
314
315In the event you have nonprivileged shell users, you'll want to create a
316directory writable only to the user Apache is running as (usually root),
317then set this in your httpd.conf.
318
319WHITELISTING IP ADDRESSES
320
321IP addresses of trusted clients can be whitelisted to insure they are never
322denied.  The purpose of whitelisting is to protect software, scripts, local
323searchbots, or other automated tools from being denied for requesting large
324amounts of data from the server.  Whitelisting should *not* be used to add
325customer lists or anything of the sort, as this will open the server to abuse.
326This module is very difficult to trigger without performing some type of
327malicious attack, and for that reason it is more appropriate to allow the
328module to decide on its own whether or not an individual customer should be
329blocked.
330
331To whitelist an address (or range) add an entry to the Apache configuration
332in the following fashion:
333
334DOSWhitelist	127.0.0.1
335DOSWhitelist	127.0.0.*
336
337Wildcards can be used on up to the last 3 octets if necessary.  Multiple
338DOSWhitelist commands may be used in the configuration.
339
340TWEAKING APACHE
341
342The keep-alive settings for your children should be reasonable enough to
343keep each child up long enough to resist a DOS attack (or at least part of
344one).  Remember, it is the child processes that maintain their own internal
345IP address tables, and so when one exits, so does all of the IP information it
346had. For every child that exits, another 5-10 copies of the page may get
347through before putting the attacker back into '403 Land'.  With this said,
348you should have a very high MaxRequestsPerChild, but not unlimited as this
349will prevent cleanup.
350
351You'll want to have a MaxRequestsPerChild set to a non-zero value, as
352DosEvasive cleans up its internal hashes only on exit.  The default
353MaxRequestsPerChild is usually 10000.  This should suffice in only allowing
354a few requests per 10000 per child through in the event of an attack (although
355if you use DOSSystemCommand to firewall the IP address, a hole will no
356longer be open in between child cycles).
357
358TESTING
359
360Want to make sure it's working? Run test.pl, and view the response codes.
361It's best to run it several times on the same machine as the web server until
362you get 403 Forbidden messages. Some larger servers with high child counts
363may require more of a beating than smaller servers before blacklisting
364addresses.
365
366Please don't use this script to DoS others without their permission.
367
368KNOWN BUGS
369
370- This module appears to conflict with the Microsoft Frontpage Extensions.
371  Frontpage sucks anyway, so if you're using Frontpage I assume you're asking
372  for problems, and not really interested in conserving server resources anyway.
373
374FEEDBACK
375
376Please email me with questions, constructive comments, or feedback:
377  jonathan@nuclearelephant.com
378
379