Bun venit pe SkullBox!

Bine ai venit, Vizitator. Trebuie să te autentifici sau să îţi creezi un cont.
Ai pierdut sau nu ai primit emailul care conţine codul de activare al contului?

Autentifică-te cu numele de utilizator, parola şi precizează durata sesiunii.
  Pagini: [1]
  Imprimă  
Anti-DDos Class v1.2[PHP]  (Vizualizari 628)
AnDrEwBoY
*

Deconectat Deconectat

Mesaje: 19

Anti-DDos Class v1.2[PHP], Iul 05, 2008, 11:08

Este o clasa care va reduce sansele de a lua ddos pe paginile unde va fi instalat!Este foarte usor de utilizat nu necesita prea multe cunostinte! O recomand in special persoanelor care detin situri cu banda limitata!

File : anti-ddos.php
Cod:
<?php

########################################
/* Name : Anti-DDos class
* &nbsp;Details : Protect your pages from ddos attack
* &nbsp;Creator : AnDrEwBoY 
* &nbsp;Contact : andrew_boy200664@yahoo.com
*/
########################################
class Anti_Ddos {

#################################################################
//Connection details
var $server ""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//database server
var $user  &nbsp; &nbsp;= ""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//database login name
var $pass ""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//database login password
var $tb_hist ""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//table history name
var $tb_ban &nbsp; &nbsp; = ""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//table list banned users
var $db &nbsp; &nbsp; &nbsp; &nbsp; = "anti_ddos"; &nbsp//database name

//Internal info
var $ip &nbsp; &nbsp; &nbsp; &nbsp; = ""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//client ip
var $Time &nbsp; &nbsp; &nbsp; = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp//curent time
var $status &nbsp; &nbsp; = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp//status client (-1 = was banned;0 = clean; 1 = banned;)
var $limit &nbsp; &nbsp; &nbsp;= 5; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp//how many requests accept in 2 seconds
var $reason &nbsp; &nbsp; = ""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//if banned show the reason
#################################################################
 &nbsp; &nbsp; &nbsp; &nbsp;
 &
nbsp; &nbsp;##################
#-# constructor() #-#
function __construct($server "",$user "",$pass "",$tb_hist "",$tb_ban "")
{
 &nbsp; &nbsp;$this->Time time(); //current time

 &nbsp; &nbsp;$this->tb_hist = ($tb_hist != "") ? $tb_hist "ddos_hist";
$this->tb_ban = ($tb_ban != "") ? $tb_ban "ddos_ban";

 &nbsp; &nbsp;$this->server = ($server != "") ? $server "localhost";
$this->user = ($user != "") ? $user "root";
$this->pass $pass;
 &nbsp; &nbsp;$this->Init_Con(); 

$this->ip $_SERVER['REMOTE_ADDR'];
 &nbsp; &nbsp;
$this->Ban_Check(); //ban current user or not
$this->Check_IS_Banned(); //check if is banned
$this->Save_Trace(); //save current request
$this->Clead_DB(); //clean db from rows older than 2h

}#-# constructor() #-#


################## Initializize new connection(mysql) ################## 
#-# Init_Con() #-#
function Init_Con()
{
 &nbsp; &nbsp;$con = @mysql_connect($this->server,$this->user,$this->pass) or die("Connection problem!"); //connect to server
mysql_select_db($this->db$con) or die("Database connection problem!"); //conect to database

}#-# Init_Con() #-#


 &
nbsp; &nbsp;################## Check if this ip is banned or was banned! ################## 
#-# Check_IS_Banned() #-#
function Check_IS_Banned() 
{
 &nbsp; &nbsp; $sql "SELECT * FROM `".$this->tb_ban."` WHERE client_ip = '".$this->ip."' ORDER BY `client_time_start` DESC LIMIT 0,1";
$query mysql_query($sql);
if(mysql_num_rows($query) > 0)
{  &nbsp; &nbsp;
 &nbsp; &nbsp;$row mysql_fetch_array($query);
if($this->Time $row["client_time_start"] < 86400)
{//is banned
 &nbsp$this->status 1
 &nbsp$this->reason $row['client_reason'];
 &nbsp; die("<b>You have been banned!
Reason : <font color='#FF0000'>"
.$this->reason."</font></b>");
}
else
{//was banned 
 &nbsp$this->status = -1
}
}
}#-# Check_IS_Banned() #-#

################## Save into database this request! ################## 
#-# Save_Trace() #-#
function Save_Trace()
{
 &nbsp$sql "INSERT INTO `".$this->tb_hist."` (`client_ip`,`client_time`,`client_page`) VALUES ('".$this->ip."','".$this->Time."','".mysql_escape_string($_SERVER['PHP_SELF'])."')";
 &nbspmysql_query($sql);
}#-# Save_Trace() #-#

################## Check if current client have do more than limit request,if yes then ban it else do nothing! ################## 
#-# &nbsp;Ban_Check() #-#
function Ban_Check()
{
 &nbsp; &nbsp;$counter 0$reason "Too many requests in a short time!Banned for 24 h!";

 &nbsp; &nbsp;$sql "SELECT * FROM `".$this->tb_hist."` WHERE client_ip = '".$this->ip."' ORDER BY `client_time` DESC LIMIT 0 ,".$this->limit;
$query mysql_query($sql);

while($row mysql_fetch_array($query))
{
 &nbsp; &nbsp;if($this->Time $row['client_time'] < 3$counter++;
}
if($counter == $this->limit)
{
 &nbsp$sql "INSERT INTO `".$this->tb_ban."` (`client_ip`,`client_time_start`,`client_reason`) VALUES ('".$this->ip."','".$this->Time."','".$reason."')";
 &nbspmysql_query($sql);
}
}#-# &nbsp;Ban_Check() #-#

 &
nbsp; &nbsp; &nbsp;################## Clear DB from rows older than 2h! ################## 
#-# &nbsp;Clead_DB() #-#
function Clead_DB()
{
 &nbsp; &nbsp;$sql "DELETE FROM ".$this->tb_hist." WHERE client_time <= ".($this->Time 7200);
echo $sql."-".$this->Time;
mysql_query($sql);
}#-# &nbsp;Clead_DB() #-#
}//end class

?>
File:index.php
Cod:
<?php
include("anti-ddos.php");

$anti_ddos = new Anti_Ddos(); 
echo 
"Normal!";
?>
File : Test.php

Cod:
<?php

function curl($url$cookie "") {
 &
nbsp$rand rand(100000,400000);
 &
nbsp$agent "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/".$rand." Netscape/7.1 (ax)";
 &
nbsp$ch curl_init();
 &
nbspcurl_setopt($chCURLOPT_URL$url);
 &
nbspcurl_setopt($chCURLOPT_USERAGENT$agent);
 &
nbspcurl_setopt($chCURLOPT_RETURNTRANSFER1);
 &
nbspcurl_setopt($chCURLOPT_FOLLOWLOCATION1);
 &
nbspcurl_setopt($chCURLOPT_COOKIE$cookie);
 &
nbspcurl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
 &
nbsp$result curl_exec ($ch);
 &
nbsp; return $result;
 &
nbspcurl_close ($ch);
}

$x 0;
while(
$x 10)
{
$x++;
$string curl('http://localhost/OOP%20Programming/advance%20class/$Anti-DDos/');
}

?>
Sql Code
Cod:
-- phpMyAdmin SQL Dump
-- version 2.9.1.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 25, 2008 at 04:08 PM
-- Server version: 5.0.27
-- PHP Version: 5.2.0
--
-- Database: `anti_ddos`
--

-- --------------------------------------------------------

--
-- Table structure for table `ddos_ban`
--

CREATE TABLE `ddos_ban` (
 &nbsp;`client_id` int(11) NOT NULL auto_increment,
 &nbsp;`client_ip` char(100) NOT NULL,
 &nbsp;`client_time_start` int(11) NOT NULL,
 &nbsp;`client_reason` text NOT NULL,
 &nbsp;PRIMARY KEY &nbsp;(`client_id`)
) ENGINE=MyISAM &nbsp;DEFAULT CHARSET=latin1 AUTO_INCREMENT=28 ;

--
-- Dumping data for table `ddos_ban`
--


-- --------------------------------------------------------

--
-- Table structure for table `ddos_hist`
--

CREATE TABLE `ddos_hist` (
 &nbsp;`client_id` int(11) NOT NULL auto_increment,
 &nbsp;`client_ip` char(100) NOT NULL,
 &nbsp;`client_time` char(50) NOT NULL,
 &nbsp;`client_page` text NOT NULL,
 &nbsp;PRIMARY KEY &nbsp;(`client_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `ddos_hist`
--
Utilizare:
index.php reprezinta pagina pe care o vom proteja!
Test.php reprezinta flooderul!

Rulati pentru prima data index.php si va returna "Normal!",apoi rulati test.php(simulam un atac) si din nou index.php!
Ma voi gandi pentru viitor interzicerea accesului prin .htaccess....dar asta alta data!!Nu e cn stie ce dar sper sa va ajute!


Have fun!AnDrEwBoY Winking
« Ultima modificare: Dec 28, 2008, 04:35 de către Agkelos » Memorat
danieLs
*

Deconectat Deconectat

Mesaje: 423

WWW
Anti-DDos Class v1.2[PHP], Iul 05, 2008, 11:11

nu mai scrie cu galben, nu se intelege nimic
Memorat

The only valid measurement of code quality is: WTF's/minute

(\__/)
(+'.'+) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
AnDrEwBoY
*

Deconectat Deconectat

Mesaje: 19

Anti-DDos Class v1.2[PHP], Iul 05, 2008, 11:15

cu galben mi`am lasat semnatura..Winking asta te intereseaza pe tn sau scriptul in principiu?Smile
Memorat
tercot
*

Deconectat Deconectat

Mesaje: 1161

Anti-DDos Class v1.2[PHP], Iul 05, 2008, 13:43

^ nu va certati .. daniels a vazut o culoare galbena in loc de portocaliu fiindca nu erau inchise niste tag-uri. Si se pare ca cineva ti le-a inchis .
Ontopic: Felicitari pentru tutorial !
Memorat

Crezi in Dumnezeu si nu vei fi dezamagit.
danieLs
*

Deconectat Deconectat

Mesaje: 423

WWW
Anti-DDos Class v1.2[PHP], Iul 05, 2008, 18:08

Citat din mesajul lui: AnDrEwBoY
cu galben mi`am lasat semnatura..Winking asta te intereseaza pe tn sau scriptul in principiu?Smile
:lol: ce acidulat esti :lol:
ti-am facut o simpla observatie, nu era cazul sa te lezezi asa de usor
Memorat

The only valid measurement of code quality is: WTF's/minute

(\__/)
(+'.'+) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
AnDrEwBoY
*

Deconectat Deconectat

Mesaje: 19

Anti-DDos Class v1.2[PHP], Iul 06, 2008, 11:01

de ce credeti ca am zis`o cu ura sau altceva?Smile a fost pur si simplu ! oricum preferam sa fie o discutie legata de script ,nu una offtopic..Straight face
Memorat
danieLs
*

Deconectat Deconectat

Mesaje: 423

WWW
Anti-DDos Class v1.2[PHP], Iul 06, 2008, 14:11

oky, peace
doar ca nu intelegeam sa citesc atata tot, bafta
Memorat

The only valid measurement of code quality is: WTF's/minute

(\__/)
(+'.'+) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
AnDrEwBoY
*

Deconectat Deconectat

Mesaje: 19

Anti-DDos Class v1.2[PHP], Iul 06, 2008, 15:46

edit script: am rezolvat un posibil sql injection(thanks to vladii) si multumita lenii mele de a`l rezolva la timpul crearii scriptului! Laughing
Memorat
dragons
*

Deconectat Deconectat

Mesaje: 22

Răspuns: Anti-DDos Class v1.2[PHP], Oct 19, 2008, 22:13

super super ,,,, cand v-a veni vremea sal il folosesc ,sper sa ma ajute ... Bafta .
Memorat
SkullAds
Ecspert
ReclAmator
* * * * *
Google AdSense

Gen: Bărbat
Mesaje: Multe

Reclama AdSense,
 

 
   


Pagini: [1]
  Imprimă  
 
Schimbă forumul:  

Ethical hacking and programming community
Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC
Traducerea în limba română © 2006-2007 www.smf.ro