mrhappiness wrote:i don't see ne need for checking for drop, alter, delete, ...
why?
$sql = "SELECT user_id
FROM usertable
WHERE pass = MD5('".$_POST['pass']."') AND nick = '".$_POST['nick']."'";
will always be a SELECT which can not modify neither the database nor the tables nor the tables' content
if perhaps might become
SELECT user_id
FROM usertable
WHERE pass = MD5('something') AND nick = '1' OR '1' = '1'
which would allow logging in using wrong credentials but with the use uf mysql_real_escape_string it will be
SELECT user_id
FROM usertable
WHERE pass = MD5('something') AND nick = '1\' OR \'1\' = \'1'
which won't do any harm at all
so what do i miss?
@
you really have a hoster allowing you to create mutiple mysql users and granting different permissions to them?
I do aswell, I have a reseller account with mediacatch.com
===============new version of script====================
<?php
//********************************************************************************************
//
// Name: Suspect Filter
//
// Description: Searchs browser parameters for preset arrays containing all of php's program
// execution functions, aswell as the mysql_query function. If finds any of these functions it
// kills the script immediately. It also searches for mysql commands, on the chance it finds
// one, it will log the find, and on the third find it kills the script.
//
// IMPORTANT NOTE: You can insert the name of mysql tables you wish to protect into the
// $illegal_uri['keywords']
//
// Version: 2.1.0
// Scripted by: Timothy Hensley (TimTimTimma)
//
//*********************************************************************************************
$log_location = dirname(__FILE__)."/log.txt";
global $log_location;
$illegal_functions = array("truncate", "alter", "mysql_query(", "base64_encode(", "base64_decode(", "escapeshellarg(", "exec(", "passthru(", "proc_closes(", "proc_get_status(", "proc_nice", "proc_open(", "proc_terminate(", "shell_exec(", "system(");
$illegal_keywords = array("set", "drop", "where", "insert", "select", "table1", "table2", "table3");
$total_illegal_functions = count($illegal_functions);
$total_illegal_keywords = count($illegal_keywords);
$filter = array("$", "*", ";");
$browser_uri = str_replace($filter, "x", addslashes(strtolower($_SERVER['REQUEST_URI'])));
function log_suspect($suspect, $type = ""){
if(@file_exists($GLOBALS['log_location']) !== TRUE){
die("Either you gave the wrong location of the log file, or it does not exist.");
}
$hand = @fopen($GLOBALS['log_location'], "a");
if(isset($type)){
$suspected = "Suspicious Function: ".$suspect;
}else{
$suspected = "Suspicious Keyword: ".$suspect;
}
$log_content =
"
Date: ".date("F j, Y, g:i:s a")."
IP: ".$_SERVER['REMOTE_ADDR']."
".$suspected."
Action: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."
";
if(!@fwrite($hand, $log_content)){
die("There appears to be a file permission error. You must chmod the log file to 0602");
}
}
for($i = 0; $i <= $total_illegal_functions; $i++){
if(strpos($browser_uri, $illegal_functions[$i]) !== FALSE){
log_suspect($illegal_functions[$i], TRUE);
$suspects = 3;
}
}
for($i = 0; $i <= $total_illegal_keywords; $i++){
if(strpos($browser_uri, $illegal_keywords[$i]) !== FALSE){
log_suspect($illegal_keywords[$i]);
$suspects++;
}
}
if($suspects >= 3){
die("HACKING ATTEMPT!");
}
?>
You made it to the page, everyting seems AOK!
<br /><br />
<?
echo $browser_uri ." - ". $suspects;
?>
A close look at the log file revealed alittle bit of info about the attempts
Date: July 19, 2005, 4:23:01 pm
IP: 24.166.3.xxx
Suspicious Function: where
Action: phpublisher.net/test/test_security.php?find=delete%20from%20table1%20where%20this%20=%20that;
Date: July 19, 2005, 4:23:01 pm
IP: 24.166.3.xxx
Suspicious Function: table1
Action: phpublisher.net/test/test_security.php?find=delete%20from%20table1%20where%20this%20=%20that;
Date: July 19, 2005, 4:24:43 pm
IP: 24.166.3.xxx
Suspicious Function: where
Action: phpublisher.net/test/test_security.php?find=select%20*%20from%20table1%20where%20this%20=%20%27that%27
Date: July 19, 2005, 4:24:43 pm
IP: 24.166.3.xxx
Suspicious Function: select
Action: phpublisher.net/test/test_security.php?find=select%20*%20from%20table1%20where%20this%20=%20%27that%27
Date: July 19, 2005, 4:24:43 pm
IP: 24.166.3.xxx
Suspicious Function: table1
Action: phpublisher.net/test/test_security.php?find=select%20*%20from%20table1%20where%20this%20=%20%27that%27
Date: July 19, 2005, 4:26:00 pm
IP: 24.166.3.xxx
Suspicious Function: exec(
Action: phpublisher.net/test/test_security.php?find=exec(
I think this is MUCH better, another great thing about this, is that you can actually protect your tables with this method too, you can list specific tables you would like to protect. i think this is pretty sharp, anymore opinions?