加载由blenc加密的页面时出错(C和PHP代码)
当我在Web服务器中加载以前使用BLENC加密的页面时,显示:
Severity: Warning Message: blenc_compile: Validation of script 'pathtofileR2k_Controller.php' failed. MD5_FILE: 3f6958c4bee8ba0d4cb3a0e67e0e2bde MD5_CALC: 02998505e69466a2f7f3af5d4555a352 Severity: Error Message: blenc_compile: Validation of script 'pathtofileR2k_Controller.php' failed,cannot execute. 使用: > PHP 5.6.14 x64 NTS 这是我加密的代码: $oDir = NULL; if(PHP_SAPI === 'cli'){ $path = $argv[1]; $path2 = ''; if(count($argv)>1){ $oDir = new RecDir($path,false); while (false !== ($archivo = $oDir->read())) { if(strstr($archivo,".php") !== FALSE){ $path2=substr_replace($archivo,$path,strpos($archivo,$path),strlen($path)); $source_code = file_get_contents($path2); blenc_encrypt($source_code,$argv[2] . $path2,$FKEY); echo($archivo . " >>> " . $argv[2] . $path2 . PHP_EOL); } } $oDir->close(); file_put_contents( $argv[2] ."blenc.key_file",$FKEY."n"); //,FILE_APPEND } else{ echo("Error: parametos incorrectos" . PHP_EOL); } } else{ echo("<html><head>Error</head><body>Acceso denegado!</body></html>"); } 我该怎么解决这个问题? 编辑 检查blenc的存储库我发现了这个 for (zend_hash_internal_pointer_reset(php_bl_keys); zend_hash_get_current_data(php_bl_keys,(void **)&key) == SUCCESS; zend_hash_move_forward(php_bl_keys)) { decoded = php_blenc_decode(encoded,*key,script_len - sizeof(blenc_header),&decoded_len TSRMLS_CC); md5 = emalloc(33); php_blenc_make_md5(md5,decoded,decoded_len TSRMLS_CC); if(!strncmp(md5,header->md5,32)) { validated = TRUE; efree(md5); break; } zend_error(E_WARNING,"blenc_compile: Validation of script '%s' failed. MD5_FILE: %s MD5_CALC: %sn",file_handle->filename,md5); efree(md5); md5 = NULL; efree(decoded); decoded_len = 0; } static void php_blenc_make_md5(char *result,void *data,unsigned int data_len TSRMLS_DC) { PHP_MD5_CTX context; unsigned char digest[16]; PHP_MD5Init(&context); PHP_MD5Update(&context,data,data_len); PHP_MD5Final(digest,&context); make_digest(result,digest); } b_byte *php_blenc_decode(void *input,unsigned char *key,int in_len,int *out_len TSRMLS_DC) { BLOWFISH_CTX ctx; unsigned long hi,low; int i; b_byte *retval; Blowfish_Init (&ctx,(unsigned char*)key,strlen(key)); if(in_len % 8) { zend_error(E_WARNING,"Attempted to decode non-blenc encrytped file."); return estrdup(""); } else { retval = emalloc(in_len + 1); } memset(retval,' ',sizeof(retval)); hi = 0x0L; low = 0x0L; for(i = 0; i < in_len; i+=8) { hi |= (unsigned int)((char *)input)[i] & 0xFF; hi = hi << 8; hi |= (unsigned int)((char *)input)[i+1] & 0xFF; hi = hi << 8; hi |= (unsigned int)((char *)input)[i+2] & 0xFF; hi = hi << 8; hi |= (unsigned int)((char *)input)[i+3] & 0xFF; low |= (unsigned int)((char *)input)[i+4] & 0xFF; low = low << 8; low |= (unsigned int)((char *)input)[i+5] & 0xFF; low = low << 8; low |= (unsigned int)((char *)input)[i+6] & 0xFF; low = low << 8; low |= (unsigned int)((char *)input)[i+7] & 0xFF; Blowfish_Decrypt(&ctx,&hi,&low); retval[i] = hi >> 24; retval[i+1] = hi >> 16; retval[i+2] = hi >> 8; retval[i+3] = hi; retval[i+4] = low >> 24; retval[i+5] = low >> 16; retval[i+6] = low >> 8; retval[i+7] = low; hi = 0x0L; low = 0x0L; } retval[in_len] = ' '; *out_len = strlen(retval); return retval; } 有谁能解释这里发生的事情? 解决方法
问题是你没有将正确的内容放入你的blenc.key_file中.
blenc_encrypt()解释说它返回一个必须保存在密钥文件中的可再发行密钥.这不是您传递给blenc_encrypt()以加密代码的$encryption_key.它是用于允许blenc解密代码以便可以运行的密钥. 在您的代码中,您调用blenc_encrypt(),而不是保存它返回的可再发行组件密钥.然后,您将加密密钥附加到密钥文件,这是不正确的. 你需要做的是: $oDir = NULL; if(PHP_SAPI === 'cli'){ $path = $argv[1]; $path2 = ''; if(count($argv)>1){ $oDir = new RecDir($path,strlen($path)); $source_code = file_get_contents($path2); // Save $redistributable_key and save it to the key file $redistributable_key = blenc_encrypt($source_code,$FKEY); file_put_contents($argv[2] . "blenc.key_file",$redistributable_key . "n",FILE_APPEND); echo($archivo . " >>> " . $argv[2] . $path2 . PHP_EOL); } } $oDir->close(); } else{ echo("Error: parametos incorrectos" . PHP_EOL); } } else{ echo("<html><head>Error</head><body>Acceso denegado!</body></html>"); } 然后,您需要确保生成的blenc.key_file的内容包含在blenc.key_file ini指令指定的文件中. 完成后,您的加密文件应在Web服务器中正确加载.然后,您可以将加密文件和blenc.key_file分发给客户. 您编辑中包含的C代码是blenc解密引擎的一部分.第一部分是blenc_compile()的主循环,它接受一个文件,解码它,并且(如果成功)将它传递给Zend引擎进行编译.后两个函数只是生成MD5摘要和驱动实际Blowfish解密的助手.完全理解这些是非常复杂的,没有必要理解和解决问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |