• ASP代码审计学习笔记 -4.命令执行漏洞


    命令执行漏洞:

    保存为cmd.asp,提交链接: http://localhost/cmd.asp?ip=127.0.0.1 即可执行命令

    <%ip=request("ip")
    response.write server.createobject("wscript.shell").exec("cmd.exe /c ping "&ip&"").stdout.readall
    %>

     利用方式:

    http://localhost/cmd.asp?ip=127.0.0.1|set

    漏洞修复方式一:

    把输入的值当作参数来执行,避免命令执行漏洞,可能会占用系统资源,不够优化。

    <%
     
    ip=request("ip")
    response.write server.createobject("wscript.shell").exec("cmd.exe /c ping """&ip&"""").stdout.readall
    
    %>
    

      

    漏洞修复方式二:

    利用正则匹配ip,不符合不执行,比较合理的解决方法。

    <%
    
    ip=request("ip")
    If RegExpTest(ip) then
    	response.write server.createobject("wscript.shell").exec("cmd.exe /c ping "&ip&"").stdout.readall
    else
    	response.write("bad ip")
    end if
    
    Function RegExpTest(strng) 
    	Dim regEx,retVal,patrn
    	Set regEx = New RegExp 
    	patrn="^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$"
    	regEx.Pattern = patrn 
    	regEx.IgnoreCase = False 
    	retVal = regEx.Test(strng) 
    	If retVal Then 
    	RegExpTest = True
    	Else 
    	RegExpTest = False
    	End If 
    End Function
    
    %>
    

      

    关于我:一个网络安全爱好者,致力于分享原创高质量干货,欢迎关注我的个人微信公众号:Bypass--,浏览更多精彩文章。

  • 相关阅读:
    border-radius
    border-style
    border-width
    border
    max-width
    min-width
    clip 语法
    left
    z-index
    position
  • 原文地址:https://www.cnblogs.com/xiaozi/p/5812896.html
Copyright © 2020-2023  润新知