hello
voila juste pour la rigolade ^^ une classe qui vire les retours chariots, les tabulations, les commentaires et fait un md5 des variables.
On passe à la classe le dossier source et php s'occupe de tout ! (on espère en croisant les doigts

)
<?php
/*
class obf by telnes
allows obfuscation of php code
2011
*/
class obf {
private $salt;
private $destination;
private $excludeVariable;
//folder : string dir
//destination : string destination dir
public function __construct($folder,$destination='') {
$folderArray = array();
$this->salt = 'azerty12'; // use for concat in the md5 var creation
$this->destination = '_obf'; // destination folder
//add more !
$this->excludeVariable = array('$_ENV','$_SESSION','$_FILES','$_GLOBALS','$_POST','$_COOKIE','$_GET','$_SERVER','$_REQUEST','$this');
$GLOBALS['excludeVariable'] = $this->excludeVariable;
$GLOBALS['salt'] = $this->salt;
//if destination is empty use default destination
if(!empty($destination)){
$this->createDir($destination);
$this->destination = $destination;
}
else{
$this->createDir($this->destination);
}
if(is_dir($folder)){
$folderArray = $this->readFolderRecursive($folder);
foreach($folderArray as $fileOrDir){
$fileContents = '';
//if file > obfuscation
if(is_file($fileOrDir)){
//if php file /!\ phpx !!
if(substr($fileOrDir,-3,3) == 'php'){
echo 'file : '.htmlentities($fileOrDir)."<br />\n";
//delete comments and \n\r\t
$fileContents = $this->clearWhite($fileOrDir);
if(empty($fileContents)){
echo 'WARNING : file '.$fileOrDir.' empty'."<br />\n";
$fileContents = file_get_contents($fileOrDir);
}
//obfuscation with md5 value of var
$fileContents = $this->replaceVariable($fileContents);
//write the file
$this->writeFile($this->destination.'/'.$fileOrDir,$fileContents);
}
else{
echo 'copy of '.$fileOrDir. ': not php file'."<br \>\n";
copy($fileOrDir,$this->destination.'/'.$fileOrDir);
}
}
//else create dir
else{
echo 'folder : '.htmlentities($fileOrDir).'<br />';
$this->createDir($this->destination.'/'.$fileOrDir);
}
}
}
else{
exit(htmlentities($folder).' not a directory !');
}
}
//replace all variable withe an md5+salt value
private function replaceVariable($content){
// \$([a-zA-Z0-9_-]{1,})
return preg_replace_callback(
'@\$[a-zA-Z0-9_]{1,}@',
create_function(
'$matches',
'return (!in_array($matches[0],$GLOBALS[\'excludeVariable\']))?\'$_\'.md5($GLOBALS[\'salt\'].$matches[0]):$matches[0];'
),
$content);
}
private function replaceFunction(){
// function([ ]{0,})([a-zA-Z0-9]{1,})([ ]{0,})()
}
private function clearWhite($file){
return php_strip_whitespace($file);
}
//return an array of folders / files
private function readFolderRecursive($dir){
$path = '';
$stack[] = $dir;
while ($stack) {
$thisdir = array_pop($stack);
if ($dircont = scandir($thisdir)) {
$i=0;
while (isset($dircont[$i])) {
if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
$current_file = "{$thisdir}/{$dircont[$i]}";
if (is_file($current_file)) {
$path['file'][] = "{$thisdir}/{$dircont[$i]}";
} elseif (is_dir($current_file)) {
$path['dir'][] = "{$thisdir}/{$dircont[$i]}";
$stack[] = $current_file;
}
}
$i++;
}
}
}
return array_merge($path['dir'],$path['file']);
}
private function createDir($folder){
if(!is_dir($folder)){
if (!mkdir($folder,'0777',true)) {
echo 'WARNING : fail to create directory '.htmlentities($folder).'<br />';
}
}
else{
echo 'WARNING : directory '.htmlentities($folder).' already exist <br />';
}
}
private function writeFile($file,$content){
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
}
public function __destruct() {
}
}
?>
ce qui donne, si on passe cette classe à la moulinette
<?php
class obf { private $_28345e3d5632f4d45e73b4fae8c3973f; private $_c9e7d6069e1feebaf6bccdd4a4405746; private $_7ed951f79d7612868947d83832b81def; public function __construct($_e6a558eaad6e84cb12ecdab511b0b650,$_c9e7d6069e1feebaf6bccdd4a4405746='') { $_24aba973b4f5311906a6d6d07e0a004f = array(); $this->salt = 'azerty12'; $this->destination = '_obf'; $this->excludeVariable = array('$_ENV','$_SESSION','$_FILES','$GLOBALS','$_POST','$_COOKIE','$_GET','$_SERVER','$_REQUEST','$this'); $GLOBALS['excludeVariable'] = $this->excludeVariable; $GLOBALS['salt'] = $this->salt; if(!empty($_c9e7d6069e1feebaf6bccdd4a4405746)){ $this->createDir($_c9e7d6069e1feebaf6bccdd4a4405746); $this->destination = $_c9e7d6069e1feebaf6bccdd4a4405746; } else{ $this->createDir($this->destination); } if(is_dir($_e6a558eaad6e84cb12ecdab511b0b650)){ $_24aba973b4f5311906a6d6d07e0a004f = $this->readFolderRecursive($_e6a558eaad6e84cb12ecdab511b0b650); foreach($_24aba973b4f5311906a6d6d07e0a004f as $_a73d8d03e67e1c793b132a4ca6c79950){ $_76ff0955120a4b4e2076131813480c3f = ''; if(is_file($_a73d8d03e67e1c793b132a4ca6c79950)){ if(substr($_a73d8d03e67e1c793b132a4ca6c79950,-3,3) == 'php'){ echo 'file : '.htmlentities($_a73d8d03e67e1c793b132a4ca6c79950)."<br />\n"; $_76ff0955120a4b4e2076131813480c3f = $this->clearWhite($_a73d8d03e67e1c793b132a4ca6c79950); if(empty($_76ff0955120a4b4e2076131813480c3f)){ echo 'WARNING : file '.$_a73d8d03e67e1c793b132a4ca6c79950.' empty'."<br />\n"; $_76ff0955120a4b4e2076131813480c3f = file_get_contents($_a73d8d03e67e1c793b132a4ca6c79950); } $_76ff0955120a4b4e2076131813480c3f = $this->replaceVariable($_76ff0955120a4b4e2076131813480c3f); $this->writeFile($this->destination.'/'.$_a73d8d03e67e1c793b132a4ca6c79950,$_76ff0955120a4b4e2076131813480c3f); } else{ echo 'copy of '.$_a73d8d03e67e1c793b132a4ca6c79950. ': not php file'."<br \>\n"; copy($_a73d8d03e67e1c793b132a4ca6c79950,$this->destination.'/'.$_a73d8d03e67e1c793b132a4ca6c79950); } } else{ echo 'folder : '.htmlentities($_a73d8d03e67e1c793b132a4ca6c79950).'<br />'; $this->createDir($this->destination.'/'.$_a73d8d03e67e1c793b132a4ca6c79950); } } } else{ exit(htmlentities($_e6a558eaad6e84cb12ecdab511b0b650).' not a directory !'); } } private function replaceVariable($_e0d598363c77ae7497436ea0d0217703){ return preg_replace_callback( '@\$[a-zA-Z0-9_]{1,}@', create_function( '$_2e9ad0296af6084f37712caf3796fb5b', 'return (!in_array($_2e9ad0296af6084f37712caf3796fb5b[0],$GLOBALS[\'excludeVariable\']))?\'$_d4db6e508a499269444c224b2255e099\'.md5($GLOBALS[\'salt\'].$_2e9ad0296af6084f37712caf3796fb5b[0]):$_2e9ad0296af6084f37712caf3796fb5b[0];' ), $_e0d598363c77ae7497436ea0d0217703); } private function replaceFunction(){ } private function clearWhite($_826189c87813751b6bb27fe17be3f06c){ return php_strip_whitespace($_826189c87813751b6bb27fe17be3f06c); } private function readFolderRecursive($_67c3a450c461eaf60e6a656624352742){ $_d5cfedb026579d93e773975b3bdb51b0 = ''; $_dd575262a041d41f683707d03b93898b[] = $_67c3a450c461eaf60e6a656624352742; while ($_dd575262a041d41f683707d03b93898b) { $_f399d22c0fb72c37f331ba6e3642b28a = array_pop($_dd575262a041d41f683707d03b93898b); if ($_2b7aaf92cce4964c526db37fca95745b = scandir($_f399d22c0fb72c37f331ba6e3642b28a)) { $_cccb617c311af27e60db184e1e9c59ab=0; while (isset($_2b7aaf92cce4964c526db37fca95745b[$_cccb617c311af27e60db184e1e9c59ab])) { if ($_2b7aaf92cce4964c526db37fca95745b[$_cccb617c311af27e60db184e1e9c59ab] !== '.' && $_2b7aaf92cce4964c526db37fca95745b[$_cccb617c311af27e60db184e1e9c59ab] !== '..') { $_bc05decc23c7cf58fec4b8b77b6f86a8 = "{$_f399d22c0fb72c37f331ba6e3642b28a}/{$_2b7aaf92cce4964c526db37fca95745b[$_cccb617c311af27e60db184e1e9c59ab]}"; if (is_file($_bc05decc23c7cf58fec4b8b77b6f86a8)) { $_d5cfedb026579d93e773975b3bdb51b0['file'][] = "{$_f399d22c0fb72c37f331ba6e3642b28a}/{$_2b7aaf92cce4964c526db37fca95745b[$_cccb617c311af27e60db184e1e9c59ab]}"; } elseif (is_dir($_bc05decc23c7cf58fec4b8b77b6f86a8)) { $_d5cfedb026579d93e773975b3bdb51b0['dir'][] = "{$_f399d22c0fb72c37f331ba6e3642b28a}/{$_2b7aaf92cce4964c526db37fca95745b[$_cccb617c311af27e60db184e1e9c59ab]}"; $_dd575262a041d41f683707d03b93898b[] = $_bc05decc23c7cf58fec4b8b77b6f86a8; } } $_cccb617c311af27e60db184e1e9c59ab++; } } } return array_merge($_d5cfedb026579d93e773975b3bdb51b0['dir'],$_d5cfedb026579d93e773975b3bdb51b0['file']); } private function createDir($_e6a558eaad6e84cb12ecdab511b0b650){ if(!is_dir($_e6a558eaad6e84cb12ecdab511b0b650)){ if (!mkdir($_e6a558eaad6e84cb12ecdab511b0b650,'0777',true)) { echo 'WARNING : fail to create directory '.htmlentities($_e6a558eaad6e84cb12ecdab511b0b650).'<br />'; } } else{ echo 'WARNING : directory '.htmlentities($_e6a558eaad6e84cb12ecdab511b0b650).' already exist <br />'; } } private function writeFile($_826189c87813751b6bb27fe17be3f06c,$_e0d598363c77ae7497436ea0d0217703){ $_0c84fc90833311fe485c6647e15c4dbb = fopen($_826189c87813751b6bb27fe17be3f06c, 'w'); fwrite($_0c84fc90833311fe485c6647e15c4dbb, $_e0d598363c77ae7497436ea0d0217703); fclose($_0c84fc90833311fe485c6647e15c4dbb); } public function __destruct() { } } ?>
ce qui est bien crade
enjoy the veb