First of all, let's get one thing straight, while im sure it's not the ONLY solution to sql injections, PREPARED STATEMENTS ARE BETTER and MORE SECURE... that's granted.
So let's not debate it anymore, as I just needed to explore the escaping options and target the user inputs rather than the statement..
(a bit of back story) I have a huge application w/ lots of basic SQL statements which i need to make "safer" in a short period of time. Converting all statements to PDO is a monster of a task which requires resources not available to this situation.
But good thing is that there's a hook in the application where ALL incoming $_GET/$_POST passes through a function before making available as plain variable in the scripts... ( eg.globalize($_POST) )
So i'm looking to target that function instead and focus on "cleaning" user input ...
I pretty much got a good grasp of SQL injection techniques, and basically much of its concept, such as: 1) Whenever there is user input involved in a statement, that's when the attacker has an opportunity 2) The main mission is to break your statement's quoting by simple single or double quotes as string, or character codes, in the attacker's input.. 3) Escaping is good at preventing SQL injections except for that situation when the DATABASE character encoding is able to ready multibyte representations of those nasty illegal strings and the script based escaping misses it.
Based on the above premise, what if:
1) All my SQL Statements follow a standard where user input is quoted using single quotes ALWAYS, therefore there is no guess work for me anymore on what type of quote i need to escape (single quotes)
2) all user inputs (POST / GET) go through a function (eg. globalize() ) that basically addslashes() and globalizes each variable
3) This is an intranet application and the scripts can be made aware of the database encoding support.
QUESTION: What are the threats currently available in the above situation and how can we handle them?
...i personally was looking into simply adding routines to the globalize() function similar to mysql_real_escape_string() .. or go as far as "tweaking" the SQL statements to use mysql_real_escape_string() as that is a lot easier/faster to do than programming statements on each sql query..
PS Of course this script may never be as secure as prepared statements, but i just need to make it hard enough for most attackers (not looking to 100% bullet proof it as it is not that worth it)