Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I demonstrate a Second Order SQL Injection?
    primarykey
    data
    text
    <p>So I've been trying to replicate a second order SQL Injection. Here's an example template of two php based sites that I've prepared. Let's just call it a voter registration form. A user can register and then you can check if you're a registered voter or not.</p> <p>insert.php</p> <pre><code>&lt;?php $db_selected = mysql_select_db('canada',$conn); if (!db_selected) die("can't use mysql: ". mysql_error()); $sql_statement = "INSERT into canada (UserID,FirstName,LastName,Age,State,Town) values ('".mysql_real_escape_string($_REQUEST["UserID"])."', '".mysql_real_escape_string($_REQUEST["FirstName"])."', '".mysql_real_escape_string($_REQUEST["LastName"])."', ".intval($_REQUEST["Age"]).", '".mysql_real_escape_string($_REQUEST["State"])."', '".mysql_real_escape_string($_REQUEST["Town"])."')"; echo "You ran the sql query=".$sql_statement."&lt;br/&gt;"; $qry = mysql_query($sql_statement,$conn) || die (mysql_error()); mysql_close($conn); Echo "Data inserted successfully"; } ?&gt; </code></pre> <p>select.php</p> <pre><code>&lt;?php $db_selected = mysql_select_db('canada', $conn); if(!db_selected) die('Can\'t use mysql:' . mysql_error()); $sql = "SELECT * FROM canada WHERE UserID='".addslashes($_POST["UserID"])."'"; echo "You ran the sql query=".$sql."&lt;br/&gt;"; $result = mysql_query($sql,$conn); $row=mysql_fetch_row($result); $sql1 = "SELECT * FROM canada WHERE FirstName = '".$row[1]."'"; echo "The web application ran the sql query internally=" .$sql1. "&lt;br/&gt;"; $result1 = mysql_query($sql1, $conn); $row1 = mysql_fetch_row($result1); mysql_close($conn); echo "&lt;br&gt;&lt;b&gt;&lt;center&gt;Database Output&lt;/center&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;"; echo "&lt;br&gt;$row1[1] $row1[2] , you are a voter! &lt;br&gt;"; echo "&lt;b&gt;VoterID: $row[0]&lt;/b&gt;&lt;br&gt;First Name: $row[1]&lt;br&gt;Last Name: $row[2] &lt;br&gt;Age: $row[3]&lt;br&gt;Town: $row[4]&lt;br&gt;State: $row[5]&lt;br&gt;&lt;hr&gt;&lt;br&gt;"; } ?&gt; </code></pre> <p>So I purposely made this vulnerable to show how second order SQL Injection works, a user can type in a code into the first name section (where I am currently stuck, I've tried many different ways but it seems that I can't get it to do anything). Then when a person wants to activate the code that he has inserted in the first name section, all he needs to do is just type in the userID and the code will be inserted.</p> <p>For example: I will type into the insert.php page as: userid = 17</p> <p>firstname = (I need to inject something here)</p> <p>lastname = ..</p> <p>age = ..</p> <p>town = ..</p> <p>state = ..</p> <p>Then when I check for my details, and type in 17, the SQL script injected will be activated. Can I get few examples on what sort of vulnerabilities I can show through this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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