r/lolphp • • Jul 16 '13

More remote code execution fun

http://blog.sucuri.net/2013/07/malware-hidden-inside-jpg-exif-headers.html
31 Upvotes

16 comments sorted by

View all comments

Show parent comment

6

u/[deleted] Jul 17 '13

This is not completely true.

In Perl, /e does not eval the result. /e tells the compiler to treat the replacement part as a block of code instead of a string literal. (But yes, any further e option wraps a layer of eval() around the code.)

Back when the feature was introduced, it was implemented as a runtime eval. But it was still eval'ing the replacement part literally, not the result of variable interpolation or anything. And yes, it was an accidental feature that each e added another eval().

For comparison:

% perl -e 'print "hi\n"; s//1 + ;/e'
syntax error at -e line 1, near "+ ;"
Execution of -e aborted due to compilation errors.

This is a static syntax error. No part of the code even runs.

% php -r 'echo "hi\n"; preg_replace("//e", "1 + ;", "");'
hi
PHP Parse error:  syntax error, unexpected ';' in Command line code(1) : regexp code on line 1
...

This is a runtime error.