gpt4 book ai didi

php - 如何防止 LDAP 注入(inject)

转载 作者:可可西里 更新时间:2023-11-01 12:31:07 27 4
gpt4 key购买 nike

我们正在构建一个通过 php 使用 LDAP 的应用程序,我开始思考是否可以通过注入(inject) LDAP 来做任何事情,更好的是如何防止 LDAP 注入(inject)?

最佳答案

构建 LDAP 过滤器时,您必须确保根据 RFC2254 处理过滤器值:

Any control characters with an ACII code < 32 as well as the characters with special meaning in LDAP filters "*", "(", ")", and "\" (the backslash) are converted into the representation of a backslash followed by two hex digits representing the hexadecimal value of the character.

Zend_Ldap 例如使用以下例程

//[...]
$val = str_replace(array('\\', '*', '(', ')'), array('\5c', '\2a', '\28', '\29'), $val);
for ($i = 0; $i<strlen($val); $i++) {
$char = substr($val, $i, 1);
if (ord($char)<32) {
$hex = dechex(ord($char));
if (strlen($hex) == 1) $hex = '0' . $hex;
$val = str_replace($char, '\\' . $hex, $val);
}
}
//[...]

关于php - 如何防止 LDAP 注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3515432/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com