標籤:
命令執行漏洞:
儲存為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) thenresponse.write server.createobject("wscript.shell").exec("cmd.exe /c ping "&ip&"").stdout.readallelseresponse.write("bad ip")end ifFunction RegExpTest(strng) Dim regEx,retVal,patrnSet 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 = TrueElse RegExpTest = FalseEnd If End Function%>
ASP代碼審計 -4.命令執行漏洞總結