I recently pawned a web server on a pentest I was doing. I was able to upload and execute a PHP reverse shell script that gave me a shell. The issue was that it would run as the www-data user, and when I tried to su to root, I got the following error:
“su : must be run from a terminal”
How do you fix that? No worries, here’s a solution using python. Simply execute the following commands from your shell if you have Python installed:
echo "import pty; pty.spawn('/bin/bash')" > /tmp/qwerty.py
After you do that, just apply the command:
python /tmp/qwerty.py
Basically, what you are doing here is spawning bin/bash into a python executable file inside the tmp folder. Then just run the program using python and voila!
I hope this helps. Cheers!
Dan D.