I am looking at a Linux-based perl web application containing an ubiquitous login handler
my $ sth = $ DB-> prepare ("SELECT password from passwords, where userid =" $ userid ") or die; $ sth-> execute or die; ...
where $ userid is initialized from the (insecure, unfiltered) web user input.
It is well known that the DBI documentation recommends changing this code to use the "?" instead of "$ userid" for security.
This code was isolated in a turned off network field, as is, to verify security. . Code like this on an Internet server will eventually be hacked, as there are now bots that scan for this vulnerability. Access control is also ineffective in protecting something important, because known injections can delete databases, insert bad data or new users, or bypass access control to allow writing to a web application.
Since the application can be configured to use PostgreSQL or MySQL, and questions were raised regarding the comparative vulnerability, I tried both databases and tested each configuration with some attempts to implement SQL.
In PostgreSQL, input '; do bad things here; and here; will crash the cgi login as expected and execute bad stuff.
What was unexpected was that MySQL resisted this attack. This made me wonder if there was some kind of setup for DBD :: MySQL or elsewhere that limited preparation for 1 statement per call or was MySQL resistant in some other way.
As far as I understand, MySQL is not resistant to SQL injection in general.
It is not a question solely of methods for eliminating SQL injection; for this, maybe see. How can I avoid SQL injection attacks? .
The question is that MySQL is somehow more resilient than PostgreSQL to SQL injection attack under PERL DBI and why can this be so?