View difference between Paste ID: 2yQn7uzQ and HYvV2uFS
SHOW: | | - or go back to the newest paste.
1
<?php
2
3-
/*
3+
 $ Ad_ddos_query = 10, / /   number of requests per second to detect DDOS attacks 
4-
CHMOD /iplog/ to 777
4+
 $ Ad_check_file = 'check.txt'; / / file to write the current state during the monitoring 
5-
Create and CHMOD /iplog/iplogfile.dat to 666
5+
 $ Ad_temp_file = 'all_ip.txt'; / / temporary file 
6-
add the following line in any important .php file in the same directory as your anti_dos.php file so it can check IPs when that file is loaded, best example is index.php if you have it.
6+
 $ Ad_black_file = 'black_ip.txt'; / / will be entered into a zombie machine ip 
7-
include("anti_dos.php"); //anti-DoS, prevents rapid accessing
7+
 $ Ad_white_file = 'white_ip.txt'; / / ip logged visitors 
8
 $ Ad_dir = 'anti_ddos'; / / directory with scripts 
9-
if you have a known cookie on your site, 
9+
 $ Ad_num_query = 0, / /   current number of requests per second from a file $ check_file 
10-
you can use this, otherwise just ignore this, it will set a different limit 
10+
 $ Ad_sec_query = 0, / /   second from a file $ check_file 
11-
for people with this cookie
11+
 $ Ad_end_defense = 0, / /   end while protecting the file $ check_file 
12
 $ Ad_sec = date ("s"); / / current second 
13-
I use yourothercookie as the cookie ID for the forum, my forum uses ID 
13+
 $ Ad_date = date ("mdHis"); / / current time 
14-
greater than 0 for all members and -1 for guests and members who have logged out, 
14+
 $ Ad_defense_time = 10000 / / ddos   attack detection time in seconds at which stops monitoring 
15-
so making it match greater than zero means members will get better access and 
15+
16-
guests with or without cookies won't
16+
17
18-
Also I use these cookies in the "flood alert" emails to make sure an important user didn't get banned. Someone could fake a cookie, so always be suspicious. Tez
18+
 if (! file_exists ("{$ ad_dir} / {$ ad_check_file}") or! file_exists ("{$ ad_dir} / {$ ad_temp_file}") or! file_exists ("{$ ad_dir} / {$ ad_black_file}") or ! file_exists ("{$ ad_dir} / {$ ad_white_file}") or! file_exists ("{$ ad_dir} / anti_ddos.php")) { 
19-
*/
19+
 die ("Not enough files."); 
20-
$cookie = $_COOKIE['cookie1'];
20+
 } 
21-
$othercookie = $_COOKIE['cookie2'];
21+
22
 require ("{$ ad_dir} / {$ ad_check_file}"); 
23
24-
if($cookie && $othercookie > 0) $iptime = 10;  // Minimum number of seconds between visits for users with certain cookie
24+
 if ($ ad_end_defense and $ ad_end_defense> $ ad_date) { 
25-
else $iptime = 10; // Minimum number of seconds between visits for everyone else
25+
 require ("{$ ad_dir} / anti_ddos.php"); 
26
 } Else { 
27
 if ($ ad_sec == $ ad_sec_query) { 
28-
$ippenalty = 60; // Seconds before visitor is allowed back
28+
 $ Ad_num_query + +; 
29
 } Else { 
30
 $ Ad_num_query = '1 '; 
31-
if($cookie && $othercookie > 0)$ipmaxvisit = 30; // Maximum visits, per $iptime segment
31+
 } 
32-
else $ipmaxvisit = 15; // Maximum visits per $iptime segment
32+
33
 if ($ ad_num_query> = $ ad_ddos_query) { 
34
 $ Ad_file = fopen ("{$ ad_dir} / {$ ad_check_file}", "w"); 
35-
$iplogdir = "./iplog";
35+
 $ Ad_end_defense = $ ad_date + $ ad_defense_time; 
36-
$iplogfile = "iplog.dat";
36+
 $ Ad_string = '<? Php $ ad_end_defense ='. $ Ad_end_defense. ';?>'; 
37
 fputs ($ ad_file, $ ad_string); 
38-
$ipfile = substr(md5($_SERVER["REMOTE_ADDR"]), -2);
38+
 fclose ($ ad_fp); 
39-
$oldtime = 0;
39+
 } Else { 
40-
if (file_exists($iplogdir.$ipfile)) $oldtime = filemtime($iplogdir.$ipfile);
40+
 $ Ad_file = fopen ("{$ ad_dir} / {$ ad_check_file}", "w"); 
41
 $ Ad_string = '<? Php $ ad_num_query ='. $ Ad_num_query. '; $ Ad_sec_query ='. $ Ad_sec. ';?>'; 
42-
$time = time();
42+
 fputs ($ ad_file, $ ad_string); 
43-
if ($oldtime < $time) $oldtime = $time;
43+
 fclose ($ ad_fp); 
44-
$newtime = $oldtime + $iptime;
44+
 } 
45
 } 
46-
if ($newtime >= $time + $iptime*$ipmaxvisit)
46+
 ?>