note 68879 deleted from function.preg-replace by nlopess
| From: | nlopess@php.net | Date: | Mon, 14 Aug 2006 19:56:45 +0000 |
| Subject: | note 68879 deleted from function.preg-replace by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115903@lists.php.net to get a copy of this message | ||
Note Submitter: Portugal
----
I'm doing a function/method to detect (My)SQL Injection Attacks and XSS and others, before they
reach the database or the site itself, not trying to fully avoid them without use general
techniques, but in a way that i can have a statistic page with attacks, and can ban the user that
tryed to attack my site.
the function is kind of:
--------------------------------
$tipo='SQL'
$variavel='String to check';
$fixed=$variavel;
for ($run=0;$run < count($this->mysql_pattern);$run++)
{
$fixed = preg_replace($this->mysql_pattern[$run], "", $fixed);
}
$sql_attack = strcmp($variavel,$fixed);
if ($sql_attack)
{
$this->registar_ataque($tipo,$ip);
die($tipo . ' ATAQUE');
}
--------------------------------
Perhaps you can tell me your opinion about it, or of ways of improve it. But what really brings me
here is:
I want to ask your opinion about the patterns that i'm using:
For XSS i'm using :
$xss_pattern= '@<script[^>]*?>.*?</script>@si'; // This one there was
posted here in php.net
For SQL I'm using: //Created by myself
mysql_pattern[0] = '/((OR)|(WHERE))\\s*.{1,3}\\s*=\\s*.{1,3}/';
mysql_pattern[1] = '/UNION((\\s*)|(\\s*ALL\\s*))SELECT/s';
mysql_pattern[2] = '/INSERT\\s*INTO/';
Thanks in advance