المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : كيف تحمى web من dos attack


KingDraGonS
26-09-2012, 04:05 PM
بسم الله الرحمن الرحيم
اول حجه انا عملت file ياضر يحمى الويب بتعك من dos attack
ده اول شغل اعملو فى Security web انا لسه بتعلم
طريقه العمل: file ده بيخلك ميدخلش cookies للويب علشان فى ناس بتستغل cookies و تعمل به hack
تقدر تتحكم فى عدد الناس لى يدخلو الويب و حجات تنيه كتر
ملحوظه لو فى حد بيفهم فى Security web و لئ حجه غلط يقلى علشان اعدلها
<?php

/*
CHMOD /iplog/ to 777
Create and CHMOD /iplog/iplogfile.dat to 666
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.
include("anti_dos.php"); //anti-DoS, prevents rapid accessing

if you have a known cookie on your site,
you can use this, otherwise just ignore this, it will set a different limit
for people with this cookie

I use yourothercookie as the cookie ID for the forum, my forum uses ID
greater than 0 for all members and -1 for guests and members who have logged out,
so making it match greater than zero means members will get better access and
guests with or without cookies won't

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
*/
$cookie = $_COOKIE['yourcookie'];
$othercookie = $_COOKIE['yourothercookie'];


if($cookie && $othercookie > 0) $iptime = 20; // Minimum number of seconds between visits for users with certain cookie By KingDraGonS
else $iptime = 10; // Minimum number of seconds between visits for everyone else By Far3on


$ippenalty = 60; // Seconds before visitor is allowed back By Far3on


if($cookie && $othercookie > 0)$ipmaxvisit = 30; // Maximum visits, per $iptime segment
else $ipmaxvisit = 20; // Maximum visits per $iptime segment By Far3on


$iplogdir = "./iplog/";
$iplogfile = "iplog.dat";

$ipfile = substr(md5($_SERVER["REMOTE_ADDR"]), -2);
$oldtime = 0;
if (file_exists($iplogdir.$ipfile)) $oldtime = filemtime($iplogdir.$ipfile);

$time = time();
if ($oldtime < $time) $oldtime = $time;
$newtime = $oldtime + $iptime;

if ($newtime >= $time + $iptime*$ipmaxvisit)
{
touch($iplogdir.$ipfile, $time + $iptime*($ipmaxvisit-1) + $ippenalty);
$oldref = $_SERVER['HTTP_REFERER'];
header("HTTP/1.0 503 Service Temporarily Unavailable");
header("Connection: close");
header("Content-Type: text/html");
echo "<html><body bgcolor=#999999 text=#ffffff link=#ffff00>
<font face='Verdana, Arial'><p><b>
<h1>Temporary denial of access</h1>Page views very fast IP address (more que ".$ipmaxvisit." visitas en ".$iptime." second By Far3on Team).</b>
";
echo "<br />por favor espere".$ippenalty." segundos y vuelva a cargar.</p></font></body></html>";
touch($iplogdir.$iplogfile); //create if not existing
$fp = fopen($iplogdir.$iplogfile, "a");
$yourdomain = $_SERVER['HTTP_HOST'];
if ($fp)
{
$useragent = "<unknown user agent>";
if (isset($_SERVER["HTTP_USER_AGENT"])) $useragent = $_SERVER["HTTP_USER_AGENT"];
fputs($fp, $_SERVER["REMOTE_ADDR"]." ".date("d/m/Y H:i:s")." ".$useragent."\n");
fclose($fp);
$yourdomain = $_SERVER['HTTP_HOST'];

//the @ symbol before @mail means 'supress errors' so you wont see errors on the page if email fails.
if($_SESSION['reportedflood'] < 1 && ($newtime < $time + $iptime + $iptime*$ipmaxvisit))
@mail('flood_alert@'.$yourdomain, 'site flooded by '.$cookie.' '
.$_SERVER['REMOTE_ADDR'],'http://'.$yourdomain.' rapid website access flood occured and ban for IP '.$_SERVER['REMOTE_ADDR'].' at http://'.$yourdomain.$_SERVER['REQUEST_URI'].' from '.$oldref.' agent '.$_SERVER['HTTP_USER_AGENT'].' '
.$cookie.' '.$othercookie, "From: ".$yourdomain."\n");
$_SESSION['reportedflood'] = 1;
}
exit();
}
else $_SESSION['reportedflood'] = 0;

//echo("loaded ".$cookie.$iplogdir.$iplogfile.$ipfile.$newtime);
touch($iplogdir.$ipfile, $newtime); //this just updates the IP file access date or creates a new file if it doesn't exist in /iplog
//////This page coded BY Far3on & KingDraGonS\\\\\\
?>
طريقه وضه فى الويب بتعك
1- حتخده copy وتحته فى file .php وليكن مثل anti_dos.php
2- تفتح index بتعت الويب بتعك و تكتب كده بين <?php و ?> : include("anti_dos.php");
و كده اكون خلصت
عيز ردود حلوه وتشجع

darkman_1
26-09-2012, 04:14 PM
تمام ها جرب وارد عليك

Mr Z!dane
26-09-2012, 05:58 PM
بلتوفيق

firewave
26-09-2012, 07:56 PM
مشكور عل المساعده :mf_popcorn:

ღ♥_iMoRy_♥ღ
26-09-2012, 08:03 PM
ان شاء الله لما ربنا بنفخ فى صورتى واعمل السيرفير ابقا اعملها
مشكور على مجهودك
:holiday:

™Anas™
26-09-2012, 08:03 PM
مشكور يا برنس ده لو شغاله يبقا حنا أول ناس عملينها لأن الأجانب عارفين إنها بفلوس

KingDraGonS
26-09-2012, 09:00 PM
متشكرين على الردود الحلوه و اول لما اتعلم اى حجه ححتها

Last_Fiddler
26-09-2012, 11:31 PM
شكراا يا غالى بس ممكن تعرفنا ازاى اعرف انها شغاله ولا غلاط

KingDraGonS
27-09-2012, 08:16 AM
بس انت لما حتحته حتحس ان الويب بطء سنه صغيره و كمان لما يدخل ناس اكتر من لى متحدد فى فيل حيجبلهم الويب مغلق او حيفتح بح حيكون بطء عندهم اوى
مثل انا عمل فى فيل اقصى عدد 20 لو 21 جه يدخل ييوله الويب مغلق او لو دخل حيكون بطء اوى
و كمان انت مثل افلت الويب وعيز ترجع حترجع بس بعد 60 ثانيه يعنى هيفضل يحمل مده 60 ثانيه من ساعت لما سبت الويب وده حلوه علشان فى ناس رخمه بتعد تطلع و تدخل فممكن يحصل زى بج او local server يتلخم مع لى بيطلع و يدخل فيبى سهل يتهاك

MR ! HЄRO
27-09-2012, 10:11 AM
شكرا معني مجربتش