使用eval读取加密文件
我有一个使用 mcrypt
加密的 php 文件,现在我们需要解密它。
解密如下:
abstract class Encryption_Abstract {
const CYPHER = 'blowfish';
const MODE = 'cfb';
protected $key;
public
function __construct($key) {
$this->key = $key;
}
public function encrypt($plaintext) {
return $plaintext;
}
public function decrypt($crypttext) {
return $crypttext;
}
}
//decryptor
class Decryption extends Encryption_Abstract {
function decrypt($crypttext) {
$plaintext = '';
$td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
$ivsize = mcrypt_enc_get_iv_size($td);
$iv = substr($crypttext, 0, $ivsize);
$crypttext = substr($crypttext, $ivsize);
if ($iv) {
mcrypt_generic_init($td, $this - > key, $iv);
$plaintext = mdecrypt_generic($td, $crypttext);
}
return $plaintext;
}
}
现在这就是我们实例化它然后使用它的方式:
$enc = new Decryption(KEYS::PROD); //KEYS::PROD is the decryption key
eval($enc->decrypt(file_get_contents("key_file.txt"))); //<--
有没有办法不使用eval
?或者这是我唯一的选择?
I have a php file which was encrypted using mcrypt
and now we need to decrypt it.
Here is the decryption:
abstract class Encryption_Abstract {
const CYPHER = 'blowfish';
const MODE = 'cfb';
protected $key;
public
function __construct($key) {
$this->key = $key;
}
public function encrypt($plaintext) {
return $plaintext;
}
public function decrypt($crypttext) {
return $crypttext;
}
}
//decryptor
class Decryption extends Encryption_Abstract {
function decrypt($crypttext) {
$plaintext = '';
$td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
$ivsize = mcrypt_enc_get_iv_size($td);
$iv = substr($crypttext, 0, $ivsize);
$crypttext = substr($crypttext, $ivsize);
if ($iv) {
mcrypt_generic_init($td, $this - > key, $iv);
$plaintext = mdecrypt_generic($td, $crypttext);
}
return $plaintext;
}
}
Now this is how we instantiate it and then use it:
$enc = new Decryption(KEYS::PROD); //KEYS::PROD is the decryption key
eval($enc->decrypt(file_get_contents("key_file.txt"))); //<--
Is there any way to not use eval
? or is it my only option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它是一个 PHP 文件并且您需要执行它,您可以将其通过管道传输到
php
cli.. 但它是相同的。但是你想如何在不执行 PHP 文件的情况下执行它呢?:)If it's a PHP file and you need to execute it, you can pipe it to a
php
cli.. but it would be the same. But how would you want to execute a PHP file without executing it?:)您可以将解密的内容存储在临时文件中,包含它并随后删除:
You could store decrypted contents in temporary file, include it and delete after that: