I have this (stripped down) Perl database query, and I wonder if this can be exploited in any way. This is from a challenge, so I know things could be done different, the task is to exploit this.
To my knowledge it uses prepared statements and is therefore considerable safe. However I could find this, regarding problems with quote and param.
if ('POST' eq request_method && param('username') && param('password')){
my $dbh = DBI->connect( "DBI:mysql:database_name","database_name", "<censored>", {'RaiseError' => 1});
my $query="Select * FROM users where username =".$dbh->quote(param('username')) . " and password =".$dbh->quote(param('password'));
my $sth = $dbh->prepare($query);
$sth->execute();
my $ver = $sth->fetch();
if ($ver){
print "win!<br>";
print "here is your result:<br>";
print @$ver;
}
else{
print "fail";
}
$sth->finish();
$dbh->disconnect();
}
prepare
. This does not use prepared statements, at least not in the sense that the statement gets prepared first with placeholders and then the parameters are given within execute. See bobby-tables.com/perl for information how you get proper prepared statements.?
prepared statements would be the way to go. I've updated my questions as I see I was not clear with my intent.quote
depends on the underlying database driver. You need to check what type of quoting it does. Specifically check the escaping behavior and handling of non-string types. Reading the quote docs would probably be a good start.