Ver Mensaje Individual
  #6 (permalink)  
Antiguo 10/07/2010, 16:21
Avatar de NUCKLEAR
NUCKLEAR
Moderador radioactivo
 
Fecha de Ingreso: octubre-2005
Ubicación: Cordoba-Argentina
Mensajes: 5.688
Antigüedad: 18 años, 6 meses
Puntos: 890
Respuesta: CrawlProtect, encripta Php?

Yo uso esta clase, no soy experto en seguridad, pero segun me dijeron es excelente el nivel de encriptación que da, de momento lo estoy usando(no me preocupa mucho la idea de tener que proteger el código eso si) pero funciona.

Código PHP:
Ver original
  1. <?php
  2. define("ENCODING_LEVEL", 9);
  3. /**
  4.  *
  5.   */
  6. Class PhpEncode {
  7.     private $fileName="";
  8.     private $obfuscatedFilePostfix="obfuscated";
  9.     private $obfuscateFileName="";
  10.     private $errors=array();
  11.  
  12.     /**
  13.      *
  14.      *
  15.      * @param string $obfuscatedFilePostfix
  16.      */
  17.     public function __construct($obfuscatedFilePostfix=""){
  18.         if (trim($obfuscatedFilePostfix)!="") {
  19.             $this->obfuscatedFilePostfix=$obfuscatedFilePostfix;
  20.         }
  21.     }
  22.  
  23.     /**
  24.      * encoding
  25.           * @param string $fileName
  26.      * @return
  27.      */
  28.     public function obfuscate($fileName) {
  29.         if (trim($fileName)=="") {
  30.             $this->errors[]="File Name cannot be blank in function: ".__FUNCTION__;
  31.             return false;
  32.         }
  33.         if (!is_readable($fileName)){
  34.             $this->errors[]="Failed to open file: $fileName in the function: ".__FUNCTION__;
  35.             return false;
  36.         }
  37.         $this->fileName=trim($fileName);
  38.  
  39.         $ext=end(explode(".",$this->fileName));
  40.         $pos=strrpos($this->fileName,".");
  41.         $fileName=substr($this->fileName,0,$pos);
  42.         $this->obfuscateFileName=$obfuscateFileName=$fileName.".".$this->obfuscatedFilePostfix.".".$ext;
  43.  
  44.         if(($fp=fopen($obfuscateFileName,"w+"))===false){
  45.             $this->errors[]="Failed to open file: $obfuscateFileName for writing in the function: ".__FUNCTION__;
  46.             return false;
  47.         }
  48.         else {
  49.             fwrite($fp,"<?php \r\n");
  50.             $line=file_get_contents($this->fileName);
  51.            
  52.             $line=str_replace("<?php","",$line);
  53.             $line=str_replace("<?","",$line);
  54.             $line=str_replace("?>","",$line);
  55.             $line=trim($line);
  56.             $line=$this->encodeString($line,ENCODING_LEVEL);
  57.             $line.="\r\n";
  58.             fwrite($fp,$line);
  59.             fwrite($fp,"?>");
  60.         }
  61.         fclose($fp);
  62.         return $obfuscateFileName;
  63.     }
  64.    
  65.     /**
  66.      * Function to encode the file content before writing it
  67.      *
  68.      * @param string $string
  69.      * @param [int $levels]
  70.      * @return string
  71.      */
  72.     private function encodeString($string, $levels=""){
  73.         if (trim($levels)=="") {
  74.             $levels=rand(1,9);
  75.         }
  76.         $levels=(int) $levels;
  77.         for ($i=0; $i<$levels;$i++){
  78.             $string=base64_encode($string);
  79.             $string='eval(base64_decode("'.$string.'"));';
  80.         }
  81.         return $string;
  82.     }
  83.    
  84.     /**
  85.      * Function to return all encountered errors
  86.      * @return array
  87.      */
  88.     public function getAllErrors(){
  89.         return $this->errors;
  90.     }
  91.  
  92.     /**
  93.      * Function to find if there were any errors
  94.      *
  95.      * @return boolean
  96.      */
  97.     public function hasErrors(){
  98.         if (count($this->errors)>0) {
  99.             return true;
  100.         }
  101.         else {
  102.             return false;
  103.         }
  104.     }
  105. }
  106. ?>

Obviamete el uso es muy simple

Código PHP:
Ver original
  1. <?php
  2. include_once("PhpObfuscator.inc.php");
  3.  
  4. $fileName="file.php";
  5.  
  6. $obfuscator=new PhpEncode();
  7. $obfuscatedFile=$obfuscator->obfuscate($fileName);
  8.  
  9. //debug mode
  10. if($obfuscator->hasErrors()){
  11.     $errors=$obfuscator->getAllErrors();
  12.     echo "<pre>";
  13.     print_r($errors);
  14. }
  15. else {
  16.     print("<p><u>$fileName</u> was successfully obfuscated as <a href='$obfuscatedFile'><strong>$obfuscatedFile</strong></a></p>");
  17. }
__________________
Drupal Argentina