gpt4 book ai didi

java - 查找代码中的安全漏洞 - LDAP 搜索

转载 作者:行者123 更新时间:2023-12-02 03:10:07 24 4
gpt4 key购买 nike

如何在此处找到我的代码中的漏洞。我的任务是要求我不使用任何程序来查找漏洞,因此没有发现漏洞等。是否有任何网站和/或提示可供我查找漏洞。这是我的代码

我曾尝试通过 Google 进行搜索,但很难找到可靠的网站或文档来查找或帮助我查找漏洞。

LDAP 目录中的用户搜索:

public class LsiLDAPUsers
{
private void searchRecord( String userSN, String userPassword ) throws NamingException
{
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

try
{
DirContext dctx = new InitialDirContext(env);

SearchControls sc = new SearchControls();
String[] attributeFilter = { "cn", "mail" };
sc.setReturningAttributes(attributeFilter);
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
String base = "dc=lsi,dc=com";

String filter = "(&(sn=" + userSN + ")(userPassword=" + userPassword + "))";

NamingEnumeration<?> results = dctx.search(base, filter, sc);
while (results.hasMore())
{
SearchResult sr = (SearchResult) results.next();
Attributes attrs = (Attributes) sr.getAttributes();
Attribute attr = (Attribute) attrs.get("cn");
System.out.println(attr);
attr = (Attribute) attrs.get("mail");
System.out.println(attr);
}
dctx.close();
}
catch (NamingException e)
{
// Forward to handler
}
}
}

我基本上需要使代码更加安全。这是我的代码之一。但我在其他方面还有很多工作要做。我只需要从中得到一个好的例子和/或提示,谢谢!!

最佳答案

一些提示:

  • 安全编码的一个主要支柱是对用户输入的正确验证。这是大多数黑客攻击的主要入口点。
  • 目前默认使用 SSL 或 TLS 进行网络连接
  • 当今大多数系统都禁用匿名搜索

关于java - 查找代码中的安全漏洞 - LDAP 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57000371/

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