I am executing an AJAX request using jQuery as such:
$.get({
url: 'run_program.php',
data: 'action=run&number=' + $('#number').val(),
success: function (j) {
alert(j);
}
runprogram.php is as such:
<?php
if(isset($_GET['action']) && !empty($_GET['action'])) {
run($_GET['number']);
}
function run($number) {
echo shell_exec('program.exe $number');
}
?>
The response I get from the server is always 0. I am running this locally by the way, so there are no security problems. The program is simply coded to square the number passed in as input. It works perfectly fine in cmd. When I echo $number, it correctly gives the value that I passed in using jQuery. What is the problem in my code?
runprogram.php?number=0;cat%20/etc/passwdprogram.exe $numberto the shell. You need to change the single quotes to double quotes:"program.exe $number"or move the variable outside the string:'program.exe '.$number