I know this topic was insured to death, but I would like to receive community feedback regarding security in our web application.
We have a standard LAMP stack web application that contains a large number of database queries that are executed using mysqli_query . These requests are not parameterized at the moment, but there is a naive screening of inputs using addslashes .
I was given the task of making this system more secure, since we will pass penetration testing very quickly. The forces described above know that parameterized queries are a way to make the system more secure, but they don’t want to invest time and effort into rewriting all the queries in the application, as well as changing the structure that we have to do for everyone to work correctly.
So basically, I ask, what are my options?
I ran mysqli_real_escape_string on inputs. I installed a filter that does not allow the transmission of words such as SELECT, WHERE, UNION, in which I think this makes it more secure. I know that mysqli_query allows only one query to be run immediately so that there is some protection (from concatenating updates to the end of the selection).
Do I have any other options?
Edit: I should probably add that if someone can provide an example of an attack that is absolutely inevitable without parameterized queries, which will also be useful. We have a query that looks like this:
SELECT pl.created p.LoginName, pl.username_entered, pl.ip_address FROM loginattempts pl LEFT JOIN people p ON p.PersonnelId = pl.personnel_id WHERE p.personnelid = $id AND pl.created > $date1 AND pl.created < $date2
I replaced the UNION query with the object $ id UNION SELECT * FROM p WHERE 1 = 1 , and I can prevent this by not allowing SELECT / UNION, but then I am sure that there are many other types of attacks that I cannot think of. Can anyone suggest a few more?
Update
I convinced the forces that are above me that we need to rewrite the queries for parameterized statements. According to their estimates, it will take several months, but it needs to be done. To win. I think?
Update2
Unfortunately, I was not able to convince that we needed to rewrite all our queries into parameterized ones. The strategy we came up with is to test each entry as follows:
If the user set the input is_int, then it should be discarded. The same goes for real numbers. Run mysqli_real_escape_string over character data. Change all parameters in queries for quotation marks ie
WHERE staffName = ' . $blah . '
According to this answer, we are 100% safe, since we do not change the character set at any time, and we use PHP5.5 with the latin1 character set for the whole time.
Update 3
This question was marked as a duplicate, however, in my opinion, the issue is still not being respected. According to update # 2, we found some conviction that the mysqli_real_escape string function can prevent attacks and is apparently “100% safe”. Since then, no good counter argument has been received (i.e. Demonstration of an attack that can defeat it if used correctly).