Gaining remote shell with LFI2RCE
I explored methods to gain a remote shell on the machine. The following methods can be used (with the VRFY or RCPT TO: command with SMTP explored before) to run remote commands to establish the shell.
The link below contains all the reverse shell payload we will be using:
For each of the methods, we need to start a TCP listener on a certain port to catch the shell:
1. PHP shell
a. Download the PHP shell from the link above, and load the content into a file such as shell.php (remember to update the host and port values):
Start a web server from the same directory as the shell
b. Include the address of the web server to load the PHP shell (using RCE we have found earlier):
2. Python shell
a. Identify if Python is available
b. If available, we can invoke a Python reverse shell:
Replace the
<host>and<port>with the appropriate values
3. Perl shell
a. Identify if Perl is available:
b. If available, we can invoke a Perl shell:
Replace the
<host>and<port>with the appropriate values
4. Socat stable shell
a. Check if Socat is available. However, chances are that it will not be available. We can install the Socat binary and host it from a web server on our machine, and have the target retrieve it.
First, download the Socat binary and host it from the local machine:
Next, we can send the payload to the target:
In this payload, a few things are happening:
Retrieve the Socat binary and save it to a temporary directory
/tmp/socatAdd execute permission on the binary
Invoke a Socat reverse shell from the target to our machine
Note that this shell is considered to be more stable as compared to the other options discussed before
Last updated