Skip to content
Permalink
Browse files Browse the repository at this point in the history
Opdracht 4 | Fixed SQL injection 3x
Disabled fake prepares
Bindparams for dynamic contents
HEXing of values

This still is injectable on my USBWebserver BTW :/
  • Loading branch information
Miesvanderlippe committed Nov 24, 2014
1 parent 73e4c81 commit 82441e4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions opdracht4/index.php
Expand Up @@ -15,9 +15,9 @@ public function __construct($options = Null){
if(!isset($options)) {

$options = array(

PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
}

Expand All @@ -41,11 +41,15 @@ public function GetAnimal($where){

//Quickhand if decides wether to filter on name or id based on if the input is numeric.
//Have an animal with a numeric name? Too bad. You could solve this if it weren't for a school excercise.
$whereCondition = 'WHERE ' . (is_numeric($where) ? 'id=\''.$where.'\'' : 'naam=\''.$where.'\'');
$whereCondition = 'WHERE ' . (is_numeric($where) ? 'id=UNHEX(:where)' : 'naam=UNHEX(:where)');

$query = $query . $whereCondition . ' LIMIT 1';

$reponse = parent::prepare($query);
$where = bin2hex($where);

$reponse->bindParam(':where', $where);

$reponse->execute();
$result = $reponse->fetchAll(PDO::FETCH_ASSOC);

Expand Down

0 comments on commit 82441e4

Please sign in to comment.