Some servers will execute .php.jpg as a php file – depends on configuration and version(?)
You can embed code in image metadata and PHP will still recognise it as a valid image, no matter what the extension. </li></ul>
So now we can execute our own code, what next? <ul><li>Our PHP can execute a reverse socket shell which will attempt to connect back to our own machine and forward STDIN/STDOUT to a socket server running on our local machine.
We can run netcat locally and wait for the connection.
We now have shell access. But we're only running as the apache user... but we can now easily extract all of the data from the database, search the server for other files, and look to see what software is running that'll allow us to escalate permissions.
There's plenty of information out there with databases of exploits (for example, http://www.exploit-db.com) </li></ul>
Local file inclusion (LFI) <ul><li>Get code onto the machine
Use local file inclusion to execute the code good example: require $_GET[“file”].”.php”;
But what about the .php? Surely that'll only open php files?
Using a null character strips off the end, for example: index.php?file=../../../../../../../../../../etc/passwd%00
But.. we need to get our code onto the machine first... </li></ul>
Inject to Apache logs <ul><li>We can inject code into apaches logs by causing an error message that contains our code. This will throw an error:
Now we need to include the apache logs. </li><ul><li>We can run through a list of obvious log paths
We can cycle through /proc/self/fd/[x] as one might be a symlink to our logs </li></ul></ul>
Inject to FTP logs <ul><li>We can just attempt to connect to the FTP using our code as the username
The handshake messages from the server will give us a clue to the location of the logs Status: Resolving address of www.mikeefranklin.co.uk Status: Connecting to 22.214.171.124:21... Status: Connection established, waiting for welcome message... Response: 220 (vsFTPd 2.2.2) Command: USER <?php phpinfo(); ?> -> logs likely to be at /var/log/vsftpd.log </li></ul>
Write to the database <ul><li>Another possibility is writing our code directly into a database. We can then attempt to include the database file to execute our code.
Knowing the database name will help us find the path to the database
..but we cant use LFI to read the database config, because the PHP get will executed.. … but we can use the php filter wrapper to help read it. index.php?file=php://filter/convert.base64-encode/resource=config.php This will output the file base64 encoded, which we can then decode.
If SQL injection is available, we can use it to retrieve the database path </li></ul>
Writing code using SQL injection <ul><li>If the database permissions allow, we can write our code using SQL injection and “outfile”. Select '<?php phpinfo(); ?>' into outfile '/tmp/myfile'
Now we can call.. index.php?file=../../../../../../../../tmp/myfile%00 </li></ul>
SQL Injection <ul><li>SQL Injection is common. Make sure all parameters are parsed
Can extract data we shouldn't be able to get to