0

我正在寻找 realpath() 的恒定时间实现,是否存在?

我处于恶意行为者可能控制 realpath() 的参数的情况,并且理论上可以使用定时攻击来推断 realpath() 是否指向真实文件。

4

1 回答 1

0

这应该工作,

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 来检查它是否实际上是恒定时间,或者您是否需要设置更高的值..

于 2019-10-28T07:29:12.700 回答