x2Fusion

PHP Ghost

Sep 12th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.55 KB | None | 0 0
  1. <?php
  2.  
  3. define('ENCRYPTION_KEY', md5('Ghost'));
  4. Ghost::getInst();
  5.  
  6. class Ghost
  7. {
  8.     public $core = null;
  9.  
  10.     public static function getInst()
  11.     {
  12.         static $inst = null;
  13.         if ($inst === null)
  14.         {
  15.             $inst = new self;
  16.         }
  17.         return $inst;
  18.     }
  19.    
  20.     public function __construct()
  21.     {
  22.         $this->core = $this->encryptCore();
  23.         #echo $this->core . "\r\n";
  24.         $this->core = $this->decryptCore();
  25.         #echo $this->core . "\r\n";
  26.         eval($this->core);
  27.     }
  28.    
  29.     private function encryptCore()
  30.     {
  31.         $data = ($this->core!='')?$this->core:file_get_contents(__FILE__);
  32.         $lines = explode("\n", $data);
  33.         foreach($lines as $key => $line)
  34.         {
  35.             $first_char = substr($line, 0, 1);
  36.             if($first_char == '#')
  37.             {
  38.                 $line = substr($line, 1);
  39.                 $encrypt = serialize($line);
  40.                 $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM);
  41.                 $key = pack('H*', ENCRYPTION_KEY);
  42.                 $mac = hash_hmac('sha256', $encrypt, substr(bin2hex($key), -32));
  43.                 $passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $encrypt.$mac, MCRYPT_MODE_CBC, $iv);
  44.                 $encoded = base64_encode($passcrypt).'|'.base64_encode($iv);
  45.                
  46.                 $return[] = "#$encoded";
  47.             }
  48.         }
  49.         //print_r($return);
  50.         return implode("\n", $return);
  51.     }
  52.    
  53.     private function decryptCore()
  54.     {
  55.         $data = ($this->core!='')?$this->core:file_get_contents(__FILE__);
  56.         $lines = explode("\n", $data);
  57.         foreach($lines as $key => $line)
  58.         {
  59.             $first_char = substr($line, 0, 1);
  60.             if($first_char == '#')
  61.             {
  62.                 $line = substr($line, 1);
  63.                 $decrypt = explode('|', $line.'|');
  64.                 $decoded = base64_decode($decrypt[0]);
  65.                 $iv = base64_decode($decrypt[1]);
  66.                 if(strlen($iv)!==mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC)){ return false; }
  67.                 $key = pack('H*', ENCRYPTION_KEY);
  68.                 $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $decoded, MCRYPT_MODE_CBC, $iv));
  69.                 $mac = substr($decrypted, -64);
  70.                 $decrypted = substr($decrypted, 0, -64);
  71.                 $calcmac = hash_hmac('sha256', $decrypted, substr(bin2hex($key), -32));
  72.                 if($calcmac!==$mac){ return false; }
  73.                 $decrypted = unserialize($decrypted);
  74.                
  75.                 $return[] = "$decrypted";
  76.             }
  77.         }
  78.         //print_r($return);
  79.         return implode("\n", $return);
  80.     }
  81.    
  82. }
  83.  
  84. #GhostCore::getInst();
  85. #class GhostCore
  86. #{
  87. #   private $request = null;
  88. #   private $hostargs = null;
  89. #  
  90. #   public static function getInst()
  91. #   {
  92. #       static $inst = null;
  93. #       if ($inst === null)
  94. #       {
  95. #           $inst = new self;
  96. #       }
  97. #       return $inst;
  98. #   }
  99. #  
  100. #   public function __construct()
  101. #   {
  102. #       echo "GhostCore Init";
  103. #   }
  104. #}
Advertisement
Add Comment
Please, Sign In to add comment