首页 > 系统加固 > Other > Jsp万能密码漏洞修复
2014
03-06

Jsp万能密码漏洞修复

记录一下JSP万能密码漏洞修复方案,预编译其实就可以解决哇,无奈代码用Hibernate,太菜了,瞬间就不知道咋写预编译的了。只好用最笨的办法,记录之,漏洞代码如下:

  public String login()
  {
    String str1 = (String)getParamenterValue("username");
    String str2 = (String)getParamenterValue("password");
    List localList = this.entityManager.findByHQL("from AdminUser where username='" + str1 + "' and password='" + str2 + "'", false, -1, -1);
    if ((localList != null) && (localList.size() > 0))
    {
      HttpSession localHttpSession = getHttpSession();
      localHttpSession.setAttribute("adminuser", localList.get(0));
      setToJsp("/managers/index.jsp");
      return "toJsp";
    }
    setToJsp("/adminlogin.jsp");
    return "toJsp";
  }

修复之后的代码:

public String login()
  {
    String str1 = (String)getParamenterValue("username");
    String str2 = (String)getParamenterValue("password");
    List localList = this.entityManager.findByHQL("from AdminUser where username='" + str1 + "' and password='" + str2 + "'", false, -1, -1);
    if ((localList != null) && (localList.size() == 1))
    {
      //if size > 1, don't login.
      AdminUser loginUser = (AdminUser)localList.get(0);
      if(loginUser.getUsername().equals(str1) && loginUser.getPassword().equals(str2)){
    	  HttpSession localHttpSession = getHttpSession();
    	  localHttpSession.setAttribute("adminuser", localList.get(0));
    	  setToJsp("/managers/index.jsp");
      }else{
    	  setToJsp("/adminlogin.jsp");
      }
      return "toJsp";
    }
    setToJsp("/adminlogin.jsp");
    return "toJsp";
  }
最后编辑:
作者:admin
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据