Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What is there to demonstrate?</p> <p>Second order SQL injection is nothing more than SQL injection, but the unsafe code isn't the first line.</p> <p>So, to demonstrate:</p> <p>1) Create a SQL injection string that would do something unwanted when executed without escaping.</p> <p>2) Store that string safely in your DB (with escaping).</p> <p>3) Let some other piece of your code FETCH that string, and use it elsewhere without escaping.</p> <p>EDIT: Added some examplecode:</p> <p>A table:</p> <pre><code>CREATE TABLE tblUsers ( userId serial PRIMARY KEY, firstName TEXT ) </code></pre> <p>Suppose you have some SAFE code like this, receiving firstname from a form:</p> <pre><code>$firstname = someEscapeFunction($_POST["firstname"]); $SQL = "INSERT INTO tblUsers (firstname) VALUES ('{$firstname }');"; someConnection-&gt;execute($SQL); </code></pre> <p>So far, so good, assuming that someEscapeFunction() does a fine job. It isn't possible to inject SQL.</p> <p>If I would send as a value for firstname the following line, you wouldn't mind:</p> <p>bla'); DELETE FROM tblUsers; //</p> <p>Now, suppose somebody on the same system wants to transport firstName from tblUsers to tblWhatever, and does that like this:</p> <pre><code>$userid = 42; $SQL = "SELECT firstname FROM tblUsers WHERE (userId={$userid})"; $RS = con-&gt;fetchAll($SQL); $firstName = $RS[0]["firstName"]; </code></pre> <p>And then inserts it into tblWhatever without escaping:</p> <pre><code>$SQL = "INSERT INTO tblWhatever (firstName) VALUES ('{$firstName}');"; </code></pre> <p>Now, if firstname contains some deletecommand it will still be executed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload