我正在寻找realpath()的常量时间实现,有这样的实现吗?
我所处的情况是,恶意攻击者可能控制realpath()的参数,并且理论上可以使用计时攻击来推断realpath()是否指向实际文件。
发布于 2019-10-28 15:29:13
这应该行得通
function realpath_constant_time(string $path, float $target_seconds, bool &$constant_time_success = null){
$start_time=microtime(true);
$ret=realpath($path);
$constant_time_success = @time_sleep_until($start_time+$target_seconds);
return $ret;
}例如,始终使用1毫秒的实时(对于基于SSD的服务器来说应该已经足够了,也许基于旋转硬盘的服务器可能需要更接近10毫秒的时间,我不知道):
realpath_constant_time("/path/to/../to/file.txt",0.001,$constant_time_success);您可以使用$constant_time_success来检查它是否实际上是常量时间,或者是否需要设置一个更高的值。
https://stackoverflow.com/questions/58586904
复制相似问题