OK, I've been reading here on the Monestary and elsewhere that it's a Good Idea to use placeholders in an SQL query where information for the query is derived from CGI form input, in case someone were to enter "; drop table foo;" or some such. So I'll go rewrite bits of my code using placeholders. No problems there.
What I want to do is write "bad" code and submit "bad" data so that I can see for myself the effects of using bad code, and its fix. But, in this instance, I can't do it.
From what I've heard, the DBI->prepare() method will only take a single statement, as will the DBI->do() method. So, how can these be exploited? I keep getting SQL syntax errors, even though the resulting multiple-statement string works just fine when entered directly into MySQL. (For instance, if I end up passing "select object_id, object_title from testac where object_title = 'test'; insert into testad values (49, 'blarg');" to do() or prepare(), it complains.) I just can't quite figure out what exactly *not* to do, and how such a badly-written script can be exploited.
So, can anybody write some "bad" code for me, and explain just how it can be taken advantage of? I have the following test code, assuming the form has already been submitted, and left untainted:
What comes next? Thanks for any replies, folks.my $data = $cgi->param('userdata'); my $sql = 'select col1, col2 from tablename';
In reply to CGI/DBI and placeholders, revisited. by mephit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |