Obfusc PHP,obfuscation examples
Obfuscation examples:
Initial code:
<?
//Example 1
echo “Example 1”;
class test_class
{
function test_class()
{
echo “hello”;
}
function factorial($i)
{
if($i<=1) return 1;
return factorial($i-1)*$i;
}
}
// class name in string
$classname=’test_class’;
$obj=new $classname;
?>
<?
//Example 2
$items = array(“one” => “item_one”, “two” => “item_two”);
function my_print($item, $key)
{
echo “$key. $item<br />\n”;
}
array_walk($items, ‘my_print’);
?>
<?
//Example 3
function my_print($message)
{
echo “parameter value = “.$message;
}
// function name used in simple string
call_user_func(‘my_print’, “hello”);
?>
<?
//Example 4
$name=’Hello’;
$string_variabile=’name’;
echo ” ${$string_variabile} “; //output Hello.
?>
<?
//example 5
function test_function5()
{
}
if(function_exist(‘test_function5’)) // or class_exist(‘some_class’)
{
echo ” ‘test_function5’ is defined “;
}
else
{
echo ” ‘test_function5’ is not defined “;
}
?>
<?
//example 6
function test_function6()
{
echo ” Hello “;
}
$function=’test_function6′;
$function();
?>
<?
//example 7
$var=1;
$code=’ $var=2; echo $var; ‘;
eval($code); //outputs 2
function test_function7($input)
{
echo $input;
}
//HINT: you can manually choose to obfuscate this too
eval(‘test_function7(“test”);’);
?>
<!– test_input has flag H
<form method=’get’><input type=’text’ name=’test_input’><input type=’submit’></form>
<?
//example 7
extract($_GET);//HINT: if register_globals is on, this line is not required,but have to check option 2
if($test_input)
{
echo “test_input=$test_input”;
}
else
{
echo “error”;
}
?>
Obfuscated code:
Notes:
- all comments are removed except HINT comments that are preserved (step 1 settings)
- also in step 1 you can decide the style of obfuscated identifier names and their length
- key and other identifiers are reserved function names and are not obfuscated even if are used as variables
- you can take manual decisions to increase the rate of obfuscation of special code
- for safest settingsĀ check all available checkboxes in step 1 or create a list with preserved names
<? echo “\105\x78\x61mp\x6ce 1”; class ORicgzPIaNj_2UF2 { function ORicgzPIaNj_2UF2() { echo “he\154\x6c\x6f”; }
function fYZ2g87NjIGLnXVg($rZJ3glaFcSAz0dZY) { if($rZJ3glaFcSAz0dZY<=1) return 1; return fYZ2g87NjIGLnXVg($rZJ3glaFcSAz0dZY-1)*$rZJ3glaFcSAz0dZY; } } $qVh0gqGnK20A4iOB=’ORicgzPIaNj_2UF2′; $BFPag8AG3Ar5cbVY=new $qVh0gqGnK20A4iOB;
?>
<? $jTt6gMMUE51b7niZ = array(“\157n\145” => “i\164\145m_one”, “\x74\167\157” => “\151t\145m_\x74wo”); function OdO8gEiBNdk8fsAT($fYU5g2UGEasDKPZ3, $key) { echo “$key. $fYU5g2UGEasDKPZ3<br />\n”; }
array_walk($jTt6gMMUE51b7niZ, ‘OdO8gEiBNdk8fsAT’); ?>
<? function OdO8gEiBNdk8fsAT($VcD7goLHHBBPcg4G) { echo “\x70a\162\141\155\145\x74\x65\x72 v\x61\x6c\x75\145 = “.$VcD7goLHHBBPcg4G; }
call_user_func(‘OdO8gEiBNdk8fsAT’, “\x68el\154o”); ?>
<? $Lbe9gOl9B609gcqp=’Hello’; $mEbbgi81OVaG1g6p=’Lbe9gOl9B609gcqp’; echo ” ${$mEbbgi81OVaG1g6p} “; ?>
<? function HVOdg72P0AMFNOMR()
{ } if(function_exist(‘HVOdg72P0AMFNOMR’)) { echo ” ‘HVOdg72P0AMFNOMR’ is \144\x65\146i\x6ee\x64 “; } else { echo ” ‘HVOdg72P0AMFNOMR’ \x69s \x6e\157\x74 \144e\146\x69\x6e\x65\x64 “;
} ?>
<? function Eosegq1ZA8M4kZta() { echo ” \x48\x65\154\x6c\x6f “; } $function=’Eosegq1ZA8M4kZta’; $function();
?>
<? $var=1; $agF1gTdKEBPd6CaJ=’ $var=2; echo $var; ‘; eval($agF1gTdKEBPd6CaJ); function OOCfg4tf2LEaSmFf($ekV4gb3DGH29YotI) {
echo $ekV4gb3DGH29YotI; } //HINT: you can manually choose to obfuscate this too
eval(‘OOCfg4tf2LEaSmFf(“test”);’); ?>
<!– test_input is flaged with H
<form method=’get’><input type=’text’ name=’test_input’><input type=’submit’></form>
<? extract($_GET);//HINT: if register_globals is on, this line is not required,but have to check option 2
if($rnb10g52GZ4coLO8)
{ echo “test_input=$rnb10g52GZ4coLO8”; } else { echo “\x65r\x72o\x72”; } ?>