-
Notifications
You must be signed in to change notification settings - Fork 47
/
index.php
58 lines (54 loc) · 1.65 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require 'vendor/autoload.php';
ini_set('xdebug.var_display_max_depth', -1);
ini_set('memory_limit', '512M');
ini_set('xdebug.max_nesting_level', 1000);
function deobfuscate($code, $filename, $dumpOrig) {
$deobf = new \PHPDeobfuscator\Deobfuscator($dumpOrig);
$cwd = '/var/www/html/';
$virtualPath = $cwd . basename($filename);
$deobf->getFilesystem()->write($virtualPath, $code);
$deobf->setCurrentFilename($virtualPath);
$tree = $deobf->parse($code);
$tree = $deobf->deobfuscate($tree);
$newCode = $deobf->prettyPrint($tree);
return array($tree, $newCode);
}
$nodeDumper = new PhpParser\NodeDumper();
if (php_sapi_name() == 'cli') {
$opts = getopt('tof:');
if (!isset($opts['f'])) {
die("Missing required parameter -f\n");
}
$filename = $opts['f'];
$orig = isset($opts['o']);
list($tree, $code) = deobfuscate(file_get_contents($filename), $filename, $orig);
echo $code, "\n";
if (isset($opts['t'])) {
echo $nodeDumper->dump($tree), "\n";
}
} else {
if (isset($_POST['phpdata'])) {
$orig = array_key_exists('orig', $_GET);
$php = $_POST['phpdata'];
header('Content-Type: text/plain');
list($tree, $code) = deobfuscate($php, 'input.php', $orig);
echo $code, "\n\n";
if (array_key_exists('tree', $_GET)) {
echo '======== Tree =======', "\n";
echo $nodeDumper->dump($tree), "\n";
}
} else {
echo <<<HTML
<html>
<body>
<form action="index.php" method="POST">
<textarea name="phpdata" rows=40 cols=180></textarea>
<br>
<input type="submit" value="Deobfuscate">
</form>
</body>
</html>
HTML;
}
}