简体   繁体   English

清理LDAP_bind查询

[英]Sanitize LDAP_bind query

I know that when I query a MySQL database in PHP from user entered data, the data should be sanitized. 我知道当我从用户输入的数据中查询PHP中的MySQL数据库时,应该对数据进行清理。 For a project that I am starting up, I will be authenticating against Active Directory for use login using the ldap_bind() function. 对于我正在启动的项目,我将使用ldap_bind()函数对Active Directory进行身份验证以便使用登录。

I've taken steps to check for a password to prevent an anonymous bind attempt, but I'm wondering if I need to take any other precautions like I would normally take when using user entered data. 我已经采取措施检查密码以防止匿名绑定尝试,但我想知道是否需要采取任何其他预防措施,就像我在使用用户输入的数据时通常采取的那样。 Or is this something that Active Directory will take care of itself? 或者这是Active Directory会自行处理的事情吗?

I'm an OpenLDAP kind of guy, but if I'm not mistaken there's no way to exploit this with special characters. 我是一个OpenLDAP类型的人,但如果我没有弄错,就没有办法利用特殊字符来利用它。

However, that doesn't mean it's not good practice to strip out things you know won't be there, particularly in user names or generated bind paths. 但是,这并不意味着剥离您知道不会存在的内容并不是一种好的做法,特别是在用户名或生成的绑定路径中。 For instance: 例如:

$myname = preg_replace( "/[^a-zA-Z0-9_\\ -]/", "", $myname ); $ myname = preg_replace(“/ [^ a-zA-Z0-9_ \\ - ] /”,“”,$ myname);

That would strip everything out except lowercase, uppercase, numbers, underscore, spaces and dash. 除了小写,大写,数字,下划线,空格和短划线之外,这样可以去除所有内容。 It's always more secure to use an "allow only this" logic rather than "reject something". 使用“仅允许此”逻辑而不是“拒绝某些东西”总是更安全。 You can never think of ALL things to reject. 你永远不会想到要拒绝的所有事情。

Be careful to validate that the password is not null. 请注意验证密码不为空。 Sounds silly, but according to the LDAP standard a bind with a username and no password is counted as an anonymous bind and will succeed. 听起来很傻,但根据LDAP标准,使用用户名和无密码的绑定被视为匿名绑定并将成功。

If you are using the success/failure of the bind attempt to validate the users credentials then a null password would be a nice way to fake it out. 如果您使用绑定尝试的成功/失败来验证用户凭据,那么空密码将是伪造它的好方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM