Last active
April 25, 2021 10:07
-
-
Save phith0n/64e4d5c1d777b5811709436bf608a21c to your computer and use it in GitHub Desktop.
SQL injection in the update field key.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$db = new PDO('sqlite::memory:'); | |
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
$db->exec("CREATE TABLE user (id int, username string, password string);"); | |
$db->exec("INSERT INTO user VALUES(1, 'admin', 'admin');"); | |
$db->exec("INSERT INTO user VALUES(2, 'demo', 'demo');"); | |
$summary = $_REQUEST['field']; | |
$bind_vals = []; | |
$sql_set = ' '; | |
foreach ($summary as $key => $value) { | |
if (!empty($value)) { | |
$bind_vals[':' . $key] = $value; | |
$sql_set = $sql_set . $key . ' = :' . $key; | |
} | |
} | |
$bind_vals[':id'] = 2; | |
$sql="update user set " . $sql_set . " where id = :id"; | |
var_dump($sql); | |
$stmt = $db->prepare($sql); | |
var_dump($bind_vals); | |
$r = $stmt->execute($bind_vals); | |
var_dump($r); | |
// $res = $db->query("SELECT * FROM user WHERE id = 1"); | |
// var_dump($res->fetchAll()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment