Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-11-2006, 11:28 AM
Todi Todi is offline
 
Join Date: Apr 2005
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Include php file before database connection is made, vB3.5.4

I need to include a php file in all my vBulletin files before any database connection is made, in order to prevent ddos'ing of my site which results in all the db connections being busy. Where would be a good place to include a php file without disturbing the rest of vBulletin? global.php?

The included file will mainly be creating files on the server, and if it detects abuse, will send out a error 403 page.
Reply With Quote
  #2  
Old 05-13-2006, 02:50 PM
scsa20's Avatar
scsa20 scsa20 is offline
 
Join Date: Mar 2002
Location: Mars
Posts: 458
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well... in this case, global.php would be a better choice as all the files calls for that file. Just put the include code at the very top.
Reply With Quote
  #3  
Old 05-13-2006, 03:03 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Um, before any database connection is made?

What code exactly are you wanting to place?
Reply With Quote
  #4  
Old 05-13-2006, 04:26 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

DDOS attack should be blocked at the outerborders of your DC or host.

If that is not possible it should be blocked on network or webserver level. If you are really under a DDS, then you won't be able to stop it if the attack can get as far as your forum (or any other page on your server).
Reply With Quote
  #5  
Old 05-17-2006, 05:54 AM
Todi Todi is offline
 
Join Date: Apr 2005
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I phrased myself badly.

My problems are most likely the case of a denial of service attack, but it is hard to know for certain. My host is cheap and crappy, but i have not yet become annoyed enough at these attacks that i've deemed it time to change to a better one, since they usually happen late at night. It could also simply be a case of a crappy, overloaded host, but the regularity in which these dos 's happen make that unlikely. In any way, i'm doing this more as a way to confirm what is happening than as an effective way of stopping it, although that may be possible as well.

This is the script that i want to include. The "faked header" thing could be changed i guess if i can't get it to execute before headers are already sent. I did not write this script myself.

PHP Code:
<?php

//   ENGLISH-LANGUAGE VERSION:
/*
Notes...

* $itime is the minimum number of seconds between visits _on average_ over
$itime*$imaxvisit seconds.  So in the example, a visitor isn't blocked
if it  visits the script multiple times in the first 5 seconds, as long
as it doesn't visit more than 60 times within 300 seconds (5 minutes).

* If the limit is reached, $ipenalty is the number of seconds a visitor
has to wait before being allowed back.
An MD5 hash is made of each visitor's IP address, and the last 3 hex digits of that hash are used to generate one of a possible 4096 filenames.  If it is a new visitor, or a visitor who hasn't been seen for a while, the timestamp of the file is set to the then-current time; otherwise, it must be a recent visitor, and the time stamp is increased by $itime.
If the visitor starts loading the timer script more rapidly than $itime seconds per visit,the time stamp on the IP-hashed filename will be increasing faster than the actual time is increasing.  If the time stamp gets too far ahead of the current time, the visitor is branded a bad visitor and the penalty is applied by increasing the time stamp on its file even further.
4096 separate hash files is enough that it's very unlikely you'll get two visitors at exactly the same time with the same hash, but not so many that you need to keep tidying up the files.
(Even if you do get more than one visitor with the same hash file at the same time, it's no great disaster: they'll just approach the throttle limit a little faster, which in most cases won't matter, as the limits in the example--5/60/60--are quite generous.)
This script can be simply included in each appropriate php script with this:
 //   Spam-Block:
include('timer.inc');
*/

// INITIALIZATIONS:
//   Constants:
//     Fixed:

$crlf=chr(13).chr(10);

$itime=5;  // minimum number of seconds between one-visitor visits

$imaxvisit=30;  // maximum visits in $itime x $imaxvisits seconds

$ipenalty=180;  // seconds before visitor is allowed back

$iplogdir="logs/";

$iplogfile="ErrantIPs.Log";

//     Language-dependent:

$spammer1='The Server is momentarily under heavy load.<br /><br />';
$spammer2='Please wait ';
$spammer3=' seconds and try again.';

// OPERATION:
// Make Check:
// Get file time:

$ipfile=substr(md5($_SERVER["REMOTE_ADDR"]),-3);  // -3 means 4096 possible files
$oldtime=0;

if (
file_exists($iplogdir.$ipfile)) 
{
    
$oldtime=filemtime($iplogdir.$ipfile);
}

// Update times:
$time=time();

if (
$oldtime<$time
{
    
$oldtime=$time;
}

$newtime=$oldtime+$itime;

// Stop overuser:
if ($newtime>=$time+$itime*$imaxvisit)
{
    
//     block visitor:
    
touch($iplogdir.$ipfile,$time+$itime*($imaxvisit-1)+$ipenalty);
    
header("HTTP/1.0 503 Service Temporarily Unavailable");
    
header("Connection: close");
    
header("Content-Type: text/html");
    echo 
'<html><head><title>Overload Warning</title></head><body><br /><br /><br /><p align="center"><strong>'.$spammer1.'</strong>'.$br;
    echo 
$spammer2.$ipenalty.$spammer3.'</p></body></html>'.$crlf;
    
    
//     log occurrence:
    
@$fp=fopen($iplogdir.$iplogfile,"a") or die("Could not save to file.");
    
    if (
$fp!==FALSE)
    {
      
$useragent='<unknown user agent>';
      if (isset(
$_SERVER["HTTP_USER_AGENT"])) $useragent=$_SERVER["HTTP_USER_AGENT"];
        @
fputs($fp,$_SERVER["REMOTE_ADDR"].' on '.date("D, d M Y, H:i:s").' as '.$useragent.' at '.$_SERVER["PHP_SELF"].$crlf);
      }
      @
fclose($fp);
      exit();
}

//     Modify file time:
touch($iplogdir.$ipfile,$newtime);

?>
Reply With Quote
  #6  
Old 05-17-2006, 06:50 AM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'd guess config.php is the file you'd want to go for. It will be used first before anything else happens.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:29 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07214 seconds
  • Memory Usage 2,241KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete