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

简介:   命令执行漏洞:   保存为cmd.asp,提交链接: http://localhost/cmd.asp?ip=127.0.0.1 即可执行命令  利用方式: http://localhost/cmd.asp?ip=127.0.0.1|set   漏洞修复方式一: 把输入的值当作参数来执行,避免命令执行漏洞,可能会占用系统资源,不够优化。
+关注继续查看

 

 

命令执行漏洞:

 

保存为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

%>

  

 

目录
相关文章
|
5月前
|
开发框架 .NET Apache
301重定向代码合集(iis,asp,php,asp.net,apache)
301重定向代码合集(iis,asp,php,asp.net,apache)
186 0
相关产品
云迁移中心
推荐文章
更多