Jump to content

mysql_real_escape_string() Question


Startses

Recommended Posts

I made the following function to validate info being sent to my database:

 

function valid($text){
$text = str_replace(" ","", $text);
	if (empty($text))
		return false;

$text = eregi_replace("([a-z0-9]+)","",$text);

if (empty($text))
	return true;
else
	return false;
}

 

would this be enough or would I still need to use mysql_real_escape_string() for some reason?

It only allows lowercase and numbers, unless I'm missing something?

Link to comment
https://forums.phpfreaks.com/topic/169436-mysql_real_escape_string-question/
Share on other sites

Unfortunately, hexadecimal encoded characters can be used to inject sql (you can inject things like single-quotes without supplying actual single-quotes by using hexadecimal), so things like the following (harmless examples) would get past the eregi_replace code that was posted  -

 

0x274d7953514c27

0x275061756c27

 

Unfortunately, hexadecimal encoded characters can be used to inject sql (you can inject things like single-quotes without supplying actual single-quotes by using hexadecimal), so things like the following (harmless examples) would get past the eregi_replace code that was posted  -

 

0x274d7953514c27

0x275061756c27

 

 

Yeah, but even:

 

INSERT INTO foo (bar) VALUES ('0x275061756c27');

 

Wouldn't work (from an attacker's point of view). If you've made sure that your string only contains alphanumeric characters and you delimit the string in quotes there is no way any SQL injection vulnerability would be possible.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.