【发布时间】: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