微慑信息网

LDAP注入及其他

偶遇LDAP注入,之前只听过,照抄如下:

1、LDAP基础知识:

https://www.cnblogs.com/jjkv3/archive/2012/08/11/2633271.html

2、LDAP查询运算符:

使用过滤器框可以构建查询。下表列出了最常用的 LDAP 查询运算符。

&	逻辑与
|	逻辑或
!	逻辑非
=	等于
~=	约等于
>=	等于或大于
<=	小于或等于

例如,如果您要搜索名为 John 并且姓为 Smith 或 Jones 的所有用户,则过滤器类似于下面这种形式:

(&(objectClass=user)(givenName=John)(|(sn=Smith)(sn=Jones)))

符号 !(“逻辑非”运算符)可以应用于单个条件,如以下示例所示:

(&(objectClass=user)(sn=Jones)(!givenName=John)(!givenName=Jane)(!logonCount<=100))

上述过滤器可查找姓为 Jones,名既不是 John 也不是 Mary 并且登录次数不少于 101 次的用户。

查询还支持星号通配符。以下搜索将返回姓以字母 J 开头的所有用户:

(&(objectClass=user)(sn=j*))

LDP 实用工具搜索操作不区分大小写,您可以在开头和结尾使用星号(*字符串*)来查找值中间的子字符串。完成此类搜索所需的时间要长很多。如果可能,请在开头或结尾使用通配符,但不要同时使用。

您可以使用通配符自身来测试是否存在给定的属性。如果您要查找所有不具有 Exchange Server 邮箱的用户,您可以使用以下查询来进行查找,因为这些用户缺少 msExchHomeServerName 值:

(&(objectClass=user)(!msExchHomeServerName=*))

查询中的转义字符是反斜杠 (\)。它与 * ( ) 和 NUL 都是保留字符。要搜索作为属性值的一部分的保留字符,必须在这些保留字符前面放置转义字符以及下列与各个保留字符相对应的数字代码之一:

*     2a
(     28
)     29
\     5c
NUL   00

例如,如果您要搜索显示名称以右括号字符结尾的所有用户,可使用以下搜索:

(&(objectClass=user)(displayName=*\29))

如果您要查找主目录为 G:\Accounting 的用户,可使用以下搜索:

(&(objectClass=user)(home-directory=G:\5cACCOUNTING*))

在 LDAP 查询中,反斜杠始终表示转义字符,而永远不会是实际的反斜杠。

 

3、使用ldap_search函数查询时,为防止注入可以使用ldap_escspe ,但ldap_escspe 只是把\转义为\5c;

可参考“Uid with ‘+’ sign ?” http://www.openldap.org/lists/openldap-software/200503/msg00566.html

4、常用payload:

admin)(objectclass=*

admin)(&))  注:ldap貌似只支持两个过滤器,如该payload的构造,即便后边还有过滤器,则已经不会匹配,类似:((user=admin)(&))(pass=123456)

 

5、若在字符串中存在如下:

, “, #, +, ,, ;, <, =, >,

可在前添加\进行转义,避免被当做默认专用字符使用,另,若其他非字母数字的符号,如$,16进制为0x24,转义则为\24

参考:Escaping non special characters in string for LDAP query

I hope that I have titled this question appropriately. Bit of a mixed subject here.

I have created a function in C# that creates an Active Directory User. Using an LDAP string that needs to look like this:

userinfo.displayName = "Surname, Firstname"

CN=" + userinfo.displayName, "user"

The following exception message is passed back, because of the comma being in the string.

An invalid dn syntax has been specified.

The full dn after the string has been applied is as following

"CN=Surname**,** Lastname,OU=Users,DC="Foo",DC="net"

The comma in the common name CN= is the problem…

Is there a way that C# can ignore the comma out of the string? Effectively escaping it.

Escape invalid characters in a distinguished name is done with a leading slash (‘\’). For example, the distinguished name above should be:

"CN=Surname\, Lastname,OU=Users,DC=Foo,DC=net"

According to section 2.4 of See RFC 4514: Lightweight Directory Access Protocol (LDAP): String Representation of Distinguished Names, the characters , “, #, +, ,, ;, <, =, >, and \ can be escaped by a leading slash. Other non-alphanumeric characters should be shown in the form of \XX where XX are the hex digits of the UTF8 character encoding. See section 4 for examples.

Note that the X500DistinguishedName class (in System.Security Cryptography) does not appear to have a Parse or Escape method to help in this situation.

赞(0) 打赏
转载请附本站链接,未经允许不得转载,,谢谢:微慑信息网-VulSee.com » LDAP注入及其他

评论 抢沙发

微慑信息网 专注工匠精神

微慑信息网-VulSee.com-关注前沿安全态势,聚合网络安全漏洞信息,分享安全文档案例

访问我们联系我们

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册