Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP eval() is this exploitable in my code? (dynamic arguments)
    primarykey
    data
    text
    <p><strong>EDIT:</strong> after reading all the input from the other users, i decided, to use what @chris suggested <strong>call_user_func_array()</strong> one more reason not to use <strong>eval()</strong> its slower than <strong>call_user_func_array()</strong>, but so far, nobody was able to exploit it my way, if you find a way, please post it as answer or comment :). So everybody can learn from it. Merry XMAS to all!</p> <p><strong>---EDIT END---</strong> </p> <p>Ok i needed to make a dynamic code:</p> <p>I get user input like <strong>$_POST['a'], $_POST['b'];</strong> // Depends on each query how many user input.</p> <pre><code>$sql = "SELECT 1, 2, 3 FROM x WHERE b = ? AND a = ? LIMIT 10"; // SQL STATEMENT $input = array($_POST['a'], $_POST['b']); $output = 3; // Number of variables need for 1, 2, 3 $data = readDB2($sql, $input, $output); var_dump($data); </code></pre> <p>this input, gets passed to mysqli->prepared statements</p> <p>cause the number of variables is dynamic ($input and $output);</p> <p>i used the php function eval(); Now my question can this be exploited, in my code?</p> <p>Just look in my function readDB2 to see how i used the eval() function (used it 3x times).</p> <pre><code>public function readDB2($sql, $input, $output1) { $stmt = $this-&gt;mysqli-&gt;prepare($sql); if(!empty($input) &amp;&amp; is_array($input)) { $sp = ""; $data = ""; $inputn = count($input) - 1; for($i = 0; $i &lt;= $inputn; $i++) { if($i !== $inputn) { $data .= '$input[' . $i . "],"; } else { $data .= '$input[' . $i . "]"; } $sp .= "s"; } $bind = '$stmt-&gt;bind_param(\''. $sp . '\',' . $data . ');'; eval("return $bind"); } if (!$stmt) {throw new Exception($this-&gt;mysqli-&gt;error);} $stmt-&gt;execute(); if (!$stmt) {throw new Exception($this-&gt;mysqli-&gt;error);} $stmt-&gt;store_result(); $checker = $stmt-&gt;num_rows; if($checker !== 0) { if(!empty($output1)) { $out = ""; for($i = 1; $i &lt;= $output1; $i++) { if($i !== $output1) { $out .= '$out' . $i . ","; } else { $out .= '$out' . $i; } } $res = '$stmt-&gt;bind_result(' . $out . ');'; eval("return $res"); $vars = "array(" . $out . ");"; while ($stmt-&gt;fetch()) { $results[] = eval("return $vars"); } } } else { $results = "NO RESULTS"; } $stmt-&gt;fetch(); $stmt-&gt;close(); $this-&gt;results = array('num_rows' =&gt; $checker, $results); return $this-&gt;results; } </code></pre> <p>EDIT FOR meagar</p> <pre><code>$bind = '$stmt-&gt;bind_param(\''. $sp . '\',' . $data . ');'; == $bind = '$stmt-&gt;bind_param('ss', $input[0], $input[1]);); OR and so on $bind = '$stmt-&gt;bind_param('sss', $input[0], $input[1], $input[2]);); </code></pre> <p>EDIT FOR Incognito:</p> <pre><code>$input = array($_POST['pwnd']); $data = readDB2($sql, $input, $output) { public function readDB2($sql, $input, $output) { ... $inputn = count($input) - 1; for($i = 0; $i &lt;= $inputn; $i++) { if($i !== $inputn) { $data .= '$input[' . $i . "],"; } else { $data .= '$input[' . $i . "]"; } $sp .= "s"; } $bind = '$stmt-&gt;bind_param(\''. $sp . '\',' . $data . ');'; eval("return $bind"); ... } </code></pre> <p>in my result </p> <pre><code>$bind = '$stmt-&gt;bind_param(\''. $sp . '\',' . $data . ');'; </code></pre> <p>gets </p> <pre><code>eval("return $bind"); </code></pre> <p>gets</p> <pre><code>$stmt-&gt;bind_param('s', $input[0]); </code></pre> <p>not what you said.</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