zoukankan      html  css  js  c++  java
  • AppScan漏洞扫描:已解密的登录请求的解决方案

    1、AppScan简介
    Rational AppScan(简称 AppScan)其实是一个产品家族,包括众多的应用安全扫描产品,从开发阶段的源代码扫描的 AppScan source edition,到针对 Web 应用进行快速扫描的 AppScan standard edition,以及进行安全管理和汇总整合的 AppScan enterprise Edition 等。我们经常说的 AppScan 就是指的桌面版本的 AppScan,即 AppScan standard edition。其安装在 Windows 操作系统上,可以对网站等 Web 应用进行自动化的应用安全扫描和测试。
    AppScan 是对网站等 Web 应用进行安全攻击来检查网站是否存在安全漏洞;既然是攻击,需要有明确的攻击对象吧,比如北约现在的对象就是卡扎菲上校还有他的军队。对网站来说,一个网站存在的页面,可能成千上万。每个页面也都可能存在多个字段(参数),比如一个登陆界面,至少要输入用户名和密码吧,这就是一个页面存在两个字段,你提交了用户名密码等登陆信息,网站总要有地方接受并且检查是否正确吧,这就可能存在一个新的检查页面。这里的每个页面的每个参数都可能存在安全漏洞,所有都是被攻击对象,都需要来检查。

    2、AppScan安全扫描出现已解密的登录请求漏洞问题及解决思路

     2.1、问题如下图所示:

              

      2.2、解决方案

       (1)修改前的form表单(重点密码输入框处的代码!!!)

     (2)修改后的form表单(重点:多添加了一行密码输入框,设置type=“text”)

       

    密码输入框在使用type="password"类型的input输入框情况下(style="dispay:none;"先把这个input输入框设置隐藏),再多添加一个type="text"类型的input输入框(这个输入框显式出来,让用户通过这个input输入框输入密码),然后写个js函数把显示的那个input输入框的密码加密之后再赋值给隐藏的密码输入框(type="password"类型的input输入框,之所以这样,是因为form表单提交时以name属性的字段提交的,我提交的用户名和密码是j_username和j_password),如下如加密赋值:

     下面是我公司以前某个系统的登录页面完整的js,有兴趣的可以看看整个登录流程,写的有点复杂(我自己都觉得--||)

    页面整个js如下:
    <script type="text/javascript">
    //Powered By smvv @hi.baidu.com/smvv21
    
    $(function(){          
        console.log(document.getElementById("bodyTemp").background);
        console.log("屏幕高度:"+window.screen.height);//获取屏幕分辨率
        console.log("屏幕宽度:"+window.screen.width);//获取屏幕分辨率
        console.log("网页高度:"+document.body.clientHeight);//获取网页分辨率
        console.log("网页宽度:"+document.body.clientWidth);//获取网页分辨率
        var chromeWidth = document.body.clientWidth;
        if(chromeWidth>1930){
            var imgs = "resources/images/login/backgroundmore.png";//背景
            var chassisImag = "${pageContext.request.contextPath}/resources/images/login/chassismore.png";//底部盘
            var earthImg = "${pageContext.request.contextPath}/resources/images/login/earthmore.png";//地球
            document.body.style.background = "url("+imgs+") no-repeat 0 50%";
            /*底部盘*/
            document.getElementById("chassis").style.background = "url("+chassisImag+") no-repeat";
            document.getElementById("chassis").style.width = "3600px";
            console.log(document.getElementById("chassis").style);
            
            /*地球*/
            document.getElementById("earth").style.background = "url("+earthImg+") no-repeat";
            document.getElementById("earth").style.width = "877px";
            document.getElementById("earth").style.height = "590px";
            document.getElementById("earth").style.top = "183px";
            document.getElementById("earth").style.left = "705px";
            
            /*标题*/
            document.getElementById("sysTitle").style.left = "1460px";
            document.getElementById("loginBg").style.left = "66%"; 
        }
           //updateCaptcha();    
           createCode();
          //判断浏览器是否支持placeholder属性
          supportPlaceholder='placeholder'in document.createElement('input'),
         
          placeholder=function(input){
         
            var text = input.attr('placeholder'),
            defaultValue = input.defaultValue;
         
            if(!defaultValue){
         
              input.val(text).addClass("phcolor");
            }
         
            input.focus(function(){
         
              if(input.val() == text){
           
                $(this).val("");
              }
            });
         
          
            input.blur(function(){
         
              if(input.val() == ""){
               
                $(this).val(text).addClass("phcolor");
              }
            });
         
            //输入的字符不为灰色
            input.keydown(function(){
          
              $(this).removeClass("phcolor");
            });
          };
         
          //当浏览器不支持placeholder属性时,调用placeholder函数
          if(!supportPlaceholder){
         
            $('input').each(function(){
         
              text = $(this).attr("placeholder");
         
              if($(this).attr("type") == "text"){
         
                placeholder($(this));
              }
            });
          }
         
        });
    
    
    //获取浏览器
    function getBrowserInfo()
    {
        var agent = navigator.userAgent.toLowerCase() ;
        var regStr_ie = /msie [d.]+;/gi ;
        var regStr_chrome = /chrome/[d.]+/gi ;
        //IE
        if(agent.indexOf("msie") > 0)
        {
            if(parseInt((agent.match(regStr_ie)+"").replace(/[^0-9.]/ig,""))>8){
                return true;
            }else{
                return false;
            }
        }
        //Chrome
        /* if(agent.indexOf("chrome") > 0)
        {
           return true;
        } */
        //IE10以上版本
        if("ActiveXObject" in window){
            return true;
        }
        return false;
    }
    function isIE() { //ie?
        if (!!window.ActiveXObject || "ActiveXObject" in window)
            return true;
        else
            return false;
    }
    function setCookie(name,value)//两个参数,一个是cookie的名子,一个是值
    {
        var Days = 30; //此 cookie 将被保存 30 天
        var exp  = new Date();    //new Date("December 31, 9998");
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
    }
    function getCookie(name)//取cookies函数        
    {
        var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
         if(arr != null) return unescape(arr[2]); return null;
    
    }
    function delCookie(name)//删除cookie
    {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval=getCookie(name);
        if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
    }
    $(document).ready(function() {
        if (top != window){
              top.location.href = window.location.href;   
        }   
    /*     //如果来宾用户按钮被点击
        $("#login1").click(function(){
            $("#j_username").attr("value", "guest");
            $("#j_password").attr("value", "123");
            login();    
        }); */
        
    });
    function init(){
         $("#login").click(function(){
                if($('#j_username').val()=='请输入用户名'&&$('#j_password').val()==''){
                    /* $("#j_username").attr("value", "guest");
                    $("#j_password").attr("value", "123");
                    login();     */
                }    
            }); 
            if(getCookie("remember_me") == "true") {
                document.getElementById("remember_me").checked = true;
                $("#j_username").attr("value", getCookie("j_username"));
                //$("#j_password").attr("value", getCookie("j_password"));
            }
    
            $('#j_username').focus();
            $("#j_username").keypress(function(e){
                var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
                if(key == 13){
                    $("#j_password").focus();
                    return false;
                }
                return this;
            });
            $("#j_password").keypress(function(e){
                var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
                if(key == 13){
                    login();
                    return false;
                }
                return this;
            });
    }
    function login(){
            var pass=encode64($("#j_password").val());
            $("#j_password2").val(pass);
             var validator = $('#f').validate();
            if(validator.form()){
                //为用户名加后缀登录,admin除外
                var username=$("#j_username").val();
                $("#j_username2").val(username);
                 //注意ie8和高版本的firefox不支持jquery 对checked的选择器  
                //var s=$('input[type="checkbox"][name="xxx"][checked]');获取不到选定的元素  
                var d=document.getElementById("remember_me");
                    if(document.getElementById("remember_me").checked == true) {
                        setCookie("j_username",$("#j_username").val());
                        //setCookie("j_password",$("#j_password").val());
                        setCookie("remember_me","true");
                    } else {
                        delCookie("j_username");
                        //delCookie("j_password");
                        delCookie("remember_me");
                    }
                $('#f').submit();
            } 
    }
    
    function checkCode(){
        var check=false;
        var captcha=$("#captcha").val().toUpperCase();
        var code=$("#code").text();
        if(captcha==null || captcha==""){
            //alert("请输入验证码!");
            $("#tips").html("请输入验证码");
        }else{
            if(code==captcha){
                check=true;
            }else{
                //alert("请输入正确的验证码!");
                $("#tips").html("请输入正确的验证码");            
                $("#captcha").val("");
                createCode();
            }
        }
        return check;
    }
    
    
    jQuery( function(){
        
        formValidation();
    
        // 打开页面,用户名获得焦点
        $('#j_username').focus().addClass("inputIng");
        
        
        $("#captcha").focus(function(){
             if($("#captcha").val().trim() == "请输入验证码")
            $("#captcha").val("");
        })
        
        $("#captcha").blur(function(){
            if($("#captcha").val().trim() == "")
            $("#captcha").val("请输入验证码");
        })
        
        $("#j_username").focus(function(){
             if($("#j_username").val().trim() == "请输入账号")
            $("#j_username").val("");
        })
        
        $("#j_username").blur(function(){
            if($("#j_username").val().trim() == "")
            $("#j_username").val("请输入账号");
        })
    
    } );
    
    function formValidation(){
        var loginForm = $("#login-form"),
                userName = $("#j_username"),
                userPw = $("#j_password"),
                loginTips = $( '.login-tips' ),
                showUserPw = $("#user-pw2"), 
                userNameVal = userName.val(),
                userPwVal = userPw.val();
    
        userName.on({
             keydown: function(e){
                if( $(this).val() == '请输入用户名' ){
                    $(this).val('');
                }
            }, 
            click: function(){
                if($(this).val() == userNameVal){
                    //$(this).val("").addClass("inputIng");
                    $(this).addClass("inputIng");
                }else{
                    $(this).addClass("inputIng");
                }
            },
            blur: function(){
                if($(this).val()){
                    return;
                }else{
                    //$(this).val(userNameVal);
                    $(this).removeClass("inputIng");
                }
            }
        });
        showUserPw.focus(function() {
            $(this).hide();
            userPw.show().focus();
        });
        userPw.on({
               keydown: function(e){
                   if( $(this).val() == '请输入密码' ){
                       $(this).val('');
                   }
               }, 
            blur: function(){
                if($(this).val()){
                    return;
                }else{
                    $(this).hide();
                    showUserPw.show();
                }
            },
            keyup: function(e){
    
                var postNameVal = userName.val(),
                        postPwVal = userPw.val();
                
                 if(e.keyCode == 13) {
                    if( postNameVal == "" || postNameVal == userNameVal ) {
                        userName.focus();
                        loginTips.text( '请输入用户名' );
                        
                       return;
                    }
                    if( postPwVal == "" ){
                        showUserPw.focus();
                        loginTips.text( '请输入密码' );
                        
                        return;
                    }
                    //loginForm.submit();
                    login();
                } 
            }
        });
         $(".login-btns button").on({
            mouseenter: function(){
                $(this).addClass("state-hover");
            },
            mouseleave: function(){
                $(this).removeClass("state-hover");
            },
            click: function(e){
                if( $(e.target).attr( "id" ) == "login" ){
                    login();
                }
            }
        }); 
    
    };
    document.onkeydown=function(event){//快速查询按钮绑定回车键
        var isFocus=$("#j_username").is(":focus");//焦点是否在输入用户名框中  
        if(isFocus){//是,禁止表单提交 
             var target, code, tag;
             if (!event) {    
                 event = window.event; //针对ie浏览器    
                 target = event.srcElement;    
                 code = event.keyCode;    
                 if (code == 13) {    
                     tag = target.tagName;    
                     if (tag == "TEXTAREA") { return true; }    
                     else { return false; }    
                 }    
             }    
             else {    
                 target = event.target; //针对遵循w3c标准的浏览器,如Firefox    
                 code = event.keyCode;    
                 if (code == 13) {    
                     tag = target.tagName;    
                     if (tag == "INPUT") { return false; }    
                     else { return true; }    
                 }    
             } 
        }
    };
    window.onload=function(){
        var pw_width=$("#j_password").width();
        if(pw_width<250){
            $("#user-pw2").addClass('password');
            $("#j_username").addClass('password');
            $("#j_password").addClass('password');
        }
        $("#j_username").val(getCookie("j_username"));
        if($("#j_username").val()){
            $("#user-pw2").focus();
        }
    <c:if test="${not empty param.login_error}">
        $("#tips").html("账号或密码错误,请重新输入"+'${sessionScope.LOGIN_ERR_MESSAGE}');
        <c:if test="${not empty  sessionScope.LOGIN_ERR_MESSAGE}">
        $("#tips").html('${sessionScope.LOGIN_ERR_MESSAGE}');
        </c:if>
    </c:if>
    
        $('.login_bottom_icon3').click(function(){
            window.location.href='${pageContext.request.contextPath}/操作手册.doc';
        });
        $('#ie32').click(function(){
            window.location.href='${pageContext.request.contextPath}/IE9_Windows7_x86_chs_XiaZaiBa.zip';
        });
        $('#ie64').click(function(){
            window.location.href='${pageContext.request.contextPath}/IE9_Windows7_x64_chs_XiaZaiBa.zip';
        });
        $('#firefox').click(function(){
            window.location.href='${pageContext.request.contextPath}/firefox.zip';
        });
        $('#chrome').click(function(){
            window.location.href='${pageContext.request.contextPath}/Chrome48.zip';
        });    
    }
    function downFileByFileName(fileName){
          var url="${pageContext.request.contextPath}/biz/loginBefore.do?action=downFileByFileName&fileName="+fileName;
          url=encodeURI(url);
          window.location.href=url;
    };
    
    
    //base64加密开始
    var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv"
            + "wxyz0123456789+/" + "=";
    
    function encode64(input) {
    
        var output = "";
        var chr1, chr2, chr3 = "";
        var enc1, enc2, enc3, enc4 = "";
        var i = 0;
        do {
            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);
            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
            output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2)
                    + keyStr.charAt(enc3) + keyStr.charAt(enc4);
            chr1 = chr2 = chr3 = "";
            enc1 = enc2 = enc3 = enc4 = "";
        } while (i < input.length);
    
        return output;
    }
    
    /*
     * 更新验证码
     */
    /* function updateCaptcha() {
        $('#captcha_img').attr('src',"${pageContext.request.contextPath}/biz/loginBefore.do?action=getCode");
    }
    
         function changeImg() {   
             var imgSrc = $("#captcha_img");    
             var src = imgSrc.attr("src");        
             imgSrc.attr("src", chgUrl(src));
         }
         
         // 时间戳
         // 为了使每次生成图片不一致,即不让浏览器读缓存,所以需要加上时间戳
         function chgUrl(url) {
            var timestamp = (new Date()).valueOf();
             url = url.substring(0, 20);
             if ((url.indexOf("&") >= 0)) {
                 url = url + "×tamp=" + timestamp;
             } else {
                 url = url + "?timestamp=" + timestamp;
             }
             return url;
        } */
         
        var code='';
        
        function createCode(){
            code=''
                var codes= [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R', 'S','T','U','V','W','X','Y','Z'];
                var codeLg=4;
                for (var i=0;i<codeLg;i++) {
                    var newCode=Math.floor(Math.random()*codes.length)//随机返回1-36之间的数字
                    code=code+codes[newCode]; 
                }
                document.getElementById('code').innerText=code;
        }
      
        
    </script>
  • 相关阅读:
    算法图解-散列表
    算法图解-笔记
    ERROR:cannot read property 'getAttribute' of null 报错处理
    Error: Cannot find module 'node-sass' 报错处理
    一、Spring Cloud概述
    十、ActiveMQ多节点集群
    九、ActiveMQ的消息存储和持久化
    八、ActiveMQ的传输协议
    七、SpringBoot整合ActiveMQ
    六、Spring整合ActiveMQ
  • 原文地址:https://www.cnblogs.com/4AMLJW/p/appscan_loudong20210604110755.html
Copyright © 2011-2022 走看看