mephit has asked for the wisdom of the Perl Monks concerning the following question:
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';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI/DBI and placeholders, revisited.
by mpeppler (Vicar) on May 04, 2002 at 20:58 UTC | |
|
Re: CGI/DBI and placeholders, revisited.
by runrig (Abbot) on May 06, 2002 at 03:49 UTC | |
|
Re: CGI/DBI and placeholders, revisited.
by BUU (Prior) on May 04, 2002 at 20:29 UTC | |
by mpeppler (Vicar) on May 04, 2002 at 20:54 UTC | |
by mephit (Scribe) on May 05, 2002 at 04:10 UTC | |
by dws (Chancellor) on May 05, 2002 at 04:47 UTC | |
by mephit (Scribe) on May 05, 2002 at 19:02 UTC | |
|