【问题标题】:LDAP injection in LDAP query c#LDAP查询中的LDAP注入c#
【发布时间】:2017-05-07 02:00:26
【问题描述】:

这是我用于验证用户是否在 AD 组中的布尔连接。 我的代码中有一个安全标志。

    private bool testconnection(string user)
    {
        bool isInGroup = false;
        if (user.Length <= 7 && user.All(char.IsLetterOrDigit))
        {
            string groupName = "GroupName";
            DirectoryEntry de = new DirectoryEntry("LDAP://DC=mycompany,DC=com");
            DirectorySearcher searcher = new DirectorySearcher(de);
            searcher.Filter = "(&(objectClass=user)(|(cn=" + user + ")(sAMAccountName=" + user + ")))"; //When I'm concatenating the user name, here I got the security flag which is below.

            SearchResult result = searcher.FindOne();

            if (result != null)
            {

                DirectoryEntry person = result.GetDirectoryEntry();
                PropertyValueCollection groups = person.Properties["memberof"];

                foreach (string g in groups)
                {
                    if (g.Contains(groupName))
                    {
                        isInGroup = true;
                        break;
                    }
                }

            }
        }
        return isInGroup;
    }

我想知道,如何在 searcher.filter 中将用户名作为参数传递而不是“+user+”

安全标志:

说明

该软件没有充分清理 LDAP 查询或响应中使用的特殊元素,从而允许攻击者在执行 LDAP 查询之前修改其语法、内容或命令。 建议 验证所有用户提供的输入,以确保其符合预期的格式,并尽可能使用集中的数据验证例程。使用黑名单时,请确保清理例程执行足够次数的迭代以删除所有不允许字符的实例。 谢谢, 克里希纳

【问题讨论】:

    标签: c# security asp.net-web-api ldap


    【解决方案1】:

    根据LDAP Injection Prevention Cheat Sheet,在名为 .Net AntiXSS 的某种独立库中提供了一些类。

    【讨论】:

      猜你喜欢
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      • 1970-01-01
      相关资源
      最近更新 更多