php - How to prevent SQL (mySQL) Injection through plain escaping (not using prepared statements) -


this question has answer here:

first of all, let's 1 thing straight, while im sure it's not solution sql injections, prepared statements better , more secure... that's granted.

so let's not debate anymore, needed explore escaping options , target user inputs rather statement..

(a bit of story) have huge application w/ lots of basic sql statements need make "safer" in short period of time. converting statements pdo monster of task requires resources not available situation.

but thing there's hook in application incoming $_get/$_post passes through function before making available plain variable in scripts... ( eg.globalize($_post) )

so i'm looking target function instead , focus on "cleaning" user input ...

i pretty got grasp of sql injection techniques, , of concept, such as: 1) whenever there user input involved in statement, that's when attacker has opportunity 2) main mission break statement's quoting simple single or double quotes string, or character codes, in attacker's input.. 3) escaping @ preventing sql injections except situation when database character encoding able ready multibyte representations of nasty illegal strings , script based escaping misses it.

based on above premise, if:

1) sql statements follow standard user input quoted using single quotes always, therefore there no guess work me anymore on type of quote need escape (single quotes)

2) user inputs (post / get) go through function (eg. globalize() ) addslashes() , globalizes each variable

3) intranet application , scripts can made aware of database encoding support.

question: threats available in above situation , how can handle them?

...i looking adding routines globalize() function similar mysql_real_escape_string() .. or go far "tweaking" sql statements use mysql_real_escape_string() lot easier/faster programming statements on each sql query..

ps of course script may never secure prepared statements, need make hard enough attackers (not looking 100% bullet proof not worth it)

using

mysql_real_escape_string($link,$non_escaped_string); 

see here: http://php.net/manual/en/mysqli.real-escape-string.php


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -