From 3ad972807dfceca464574e0ce7cfc1ffe1e70013 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Thu, 27 Mar 2008 12:29:53 +0000 Subject: [PATCH] proxyscan to check (and deny) proxy connections --- web/Obj/brisk.phh | 9 +- web/Obj/proxyscan.phh | 198 ++++++++++++++++++++++++++++++++++++++ web/briskin5/index.php | 10 +- web/briskin5/index_rd.php | 7 ++ web/briskin5/index_wr.php | 7 ++ web/index.php | 6 ++ web/index_rd.php | 6 ++ web/index_wr.php | 8 ++ 8 files changed, 248 insertions(+), 3 deletions(-) create mode 100644 web/Obj/proxyscan.phh diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index b68d316..5e92d00 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -1257,8 +1257,13 @@ class Room { else { $user_cur = &$this->user[$table->player[$i]]; } - if ($only_you && $user_cur != $user) - continue; + + if ($only_you) { + if ($user_cur != $user) + continue; + else + $user_mesg = "== chat ban =="; + } $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; "; $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s","%s");', diff --git a/web/Obj/proxyscan.phh b/web/Obj/proxyscan.phh new file mode 100644 index 0000000..1e9376b --- /dev/null +++ b/web/Obj/proxyscan.phh @@ -0,0 +1,198 @@ +config = array(); + $this->lastLog = ""; + + //set default headers + $this->scan_headers = array( + 'HTTP_VIA', + 'HTTP_X_FORWARDED_FOR', + 'HTTP_FORWARDED_FOR', + 'HTTP_X_FORWARDED', + 'HTTP_FORWARDED', + 'HTTP_CLIENT_IP', + 'HTTP_FORWARDED_FOR_IP', + 'VIA', + 'X_FORWARDED_FOR', + 'FORWARDED_FOR', + 'X_FORWARDED', + 'FORWARDED', + 'CLIENT_IP', + 'FORWARDED_FOR_IP', + 'HTTP_PROXY_CONNECTION' + ); + } + + function exists_in_rbl($remote) { + $rbls = array('http.dnsbl.sorbs.net', 'misc.dnsbl.sorbs.net'); + // $remote = $_SERVER['REMOTE_ADDR']; + // $remote = '213.134.170.206'; + // $remote = '64.34.166.71'; + + if (preg_match("/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/", + $remote, $matches)) { + foreach ($rbls as $rbl) { + $rblhost = $matches[4] . "." . $matches[3] . "." . + $matches[2] . "." . $matches[1] . "." . $rbl; + + $resolved = gethostbyname($rblhost); + // echo "RBL ".$rblhost."
"; + if ($resolved != $rblhost) { + return true; + } + } + } + return false; + } + + /** + * VOID setHeader( STRING $trigger ) + * Set new header trigger... + */ + function setHeader($trigger){ + $this->scan_headers[] = $trigger; + } + + + /** + * ARRAY $triggers = getHeaders( VOID ) + * Get all triggers in one array + */ + function getHeaders(){ + return $this->scan_headers; + } + + + /** + * VOID setConfig( STRING $key, STRING $value) + * Set config line... + */ + function setConfig($key,$value){ + $this->config[$key] = $value; + } + + + /** + * MIXED $config = getConfig( [STRING $key] ) + * Get all config in one array, or only one config value as a string. + */ + function getConfig($key=''){ + if($key) + return $this->config[$key]; + else + return $this->config; + } + + + /** + * STRING $log = getLog( VOID ) + * Get last logged information. Only works AFTER calling detect()! + */ + function getLog(){ + return $this->lastLog; + } + + + /** + * BOOL $proxy = detect( VOID ) + * Start detection and return true if a proxy server is detected... + */ + function detect(){ + $log = ""; + + + if ($this->exists_in_rbl($_SERVER['REMOTE_ADDR']) == TRUE) + return (TRUE); + + //scan all headers + foreach($this->scan_headers as $i){ + //proxy detected? lets log... + if($_SERVER[$i]) + $log.= "trigger $i: ".$_SERVER[$i]."\n"; + } + + //let's do something... + if($log){ + $log = $this->lastLog = date("Y-m-d H:i:s")."\nDetected proxy server: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])." ({$_SERVER['REMOTE_ADDR']})\n".$log; + + //mail message + if($this->getConfig('MAIL_ALERT_TO')) + mail($this->getConfig('MAIL_ALERT_TO'),"Proxy detected at {$_SERVER['REQUEST_URI']}",$log); + + //write to file + $f = $this->getConfig('LOG_FILE'); + if($f){ + if(is_writable($f)){ + $fp = fopen($f,'a'); + fwrite($fp,"$log\n"); + fclose($fp); + }else{ + die("Fatal Error: Couldn't write to file: '$f'
Please check if the path exists and is writable for the webserver or php..."); + } + } + + //done + return true; + } + + //nope, no proxy was logged... + return false; + } +} + +//init class +function is_proxy() +{ + $proxy = new proxy_detector(); + + //start detect + if(!$proxy->detect()) { + //returned true, lets die... + echo "

Proxy detected



"; + echo "Please disable your proxy server in your browser preferences or internet settings, and try again.

"; + + //parse logged info + echo nl2br($proxy->getLog()); + + //some credits... + // echo "
proxy detector v0.1 - ©2006 daantje.nl"; + + //and do nothing anymore! (but not in my example) + return (TRUE); + } + else + return (FALSE); +} + +?> \ No newline at end of file diff --git a/web/briskin5/index.php b/web/briskin5/index.php index ef3d0ec..1e2b39f 100644 --- a/web/briskin5/index.php +++ b/web/briskin5/index.php @@ -20,6 +20,15 @@ * $Id$ * */ + +require_once("../Obj/brisk.phh"); +require_once("../Obj/proxyscan.phh"); + +// Use of proxies isn't allowed. +if (is_proxy()) { + exit; +} + ?> @@ -49,7 +58,6 @@ var area_ptr; var gst = new globst(); gst.st =