查看ASP源代码的方法

源代码

我们都知道asp这一类的服务器端处理的程序,其好处之一就是只向客户端输出
标准的Html流。因此可以起到向客户隐藏细节的作用。也就是说当我们在浏览器中
键入asp程序的网址后只能看见标准的Html文件,而不能看见asp的内容。但有时,
例如在一个asp的教学站点,我们有必要显示asp文件的内容,或者你愿意将你的原
代码与人享,通过一个程序将代码显示出来。
下面是我编写的一个asp程序,view_code.asp,它提供两种提交方式:一种是用
表格提交,即你知道了该源文件的物理地址(类似于:c:\asp_source\test.asp的
形式)。一种是采用get方式提交(类似于:<a href="view_code.asp?code_path=
<%=server.mappath(request.servervariables("PATH_INFO"))%>&cgi_type=asp">
点击此处查看原代码</a>)。另外它还支持两种cgi脚本,一种是asp,一种是php。

代码段:
<%
on error resume next
'忽略程序执行中的错误,在程序的最后统一处理。
%>
<%
function rt_min(num1,num2)
'该子程序用于返回两数中不等于零的最小数。
if num1=0 and num2=0 then
rt_min=-1
elseif num1=0 then
rt_min=num2
elseif num2=0 then
rt_min=num1
elseif num1<num2 then
rt_min=num1
else
rt_min=num2
end if
end function
%>
<%
function line_check(strline,cgi_type)
'该子程序用于检查输入段中是否包含有"<%、%>、<script或</script的特殊字符
dim cgi_flag
if cgi_type="php" then
cgi_flag="?"
else
cgi_flag="%"
end if
'定义的cgi_flag用于代表php和asp的不同标识符
line_check=0
itemp=0
ipos=instr(strline,"<"&cgi_flag)
if rt_min(ipos,itemp)=ipos then
itemp=ipos
line_check=1
end if
ipos=instr(strline,cgi_flag&">")
if rt_min(ipos,itemp)=ipos then
itemp=ipos
line_check=2
end if
ipos=instr(1,strline,"<"&"script",1)
if rt_min(ipos,itemp)=ipos then
itemp=ipos
line_check=3
end if
ipos=instr(1,strline,"<"&"/script",1)
if rt_min(ipos,itemp)=ipos then
itemp=ipos
line_check=4
end if
end function
%>
<%
sub printhtml(strline)
'该子过程用于打印不含有上述四种特殊标记的行
ispace=len(strline)-len(ltrim(strline))
i=1
while(mid(strline,i,1))=chr(9)
ispace=ispace+5
i=i+1
wend
'统计空白的数量
if ispace>0 then
for i=1 to ispace
response.write(" ")
next
end if
ipos=instr(strline,"<")
if ipos then
response.write(left(strline,ipos-1))
response.write("<")
'用<来替代<,使浏览器不解释<>中的标记
strline=right(strline,len(strline)-ipos)
call printhtml(strline)
'自调用,直到没有<的出现
else
response.write(strline)
end if
end sub
%>
<%
sub printline(strline,iflag,cgi_type)
'该自过程用于根据line_check的返回值分别处理
dim cgi_flag
if cgi_type="php" then
cgi_flag="?"
else
cgi_flag="%"
end if
select case iflag
case 0
call printhtml(strline)
case 1
ipos=instr(strline,"<"&cgi_flag)
call printhtml(left(strline,ipos-1))
response.write("<font color=#ff0000>")
response.write("<"&cgi_flag)
strline=right(strline,len(strline)-ipos-1)
call printline(strline,line_check(strline,cgi_type),cgi_type)
'自调用,直到没有四种特殊标记的出现
case 2
ipos=instr(strline,cgi_flag&">")
call printhtml(left(strline,ipos-1))
response.write(cgi_flag&">")
response.write("</font>")
strline=right(strline,len(strline)-ipos-1)
call printline(strline,line_check(strline,cgi_type),cgi_type)
case 3
ipos=instr(1,strline,"<"&"script",1)
call printhtml(left(strline,ipos-1))
response.write("<font color=#00ff00>")
response.write("<"&"script")
strline=right(strline,len(strline)-ipos-6)
call printline(strline,line_check(strline.cgi_type),cgi_type)
case 4
ipos=instr(1,strline,"<"&"/script>",1)
call printhtml(left(strline,ipos-1))
response.write("lt;"&"/script"&">")
response.write("</font>")
strline=right(strline,len(strline)-ipos-8)
call printline(strline,line_check(strline,cgi_type),cgi_type)
case else
response.write("error")
end select
end sub
%>
<html>
<head>
<title> view cgi_code(.asp or .php) </title>
</head>
<body>
<form action="view_code.asp" method="POST">
请输入路径:<input type=text name="code_path">
请选择类型:<select name="cgi_type&qu

时间: 2024-09-12 09:58:16

查看ASP源代码的方法的相关文章

php查看网页源代码的方法

 这篇文章主要介绍了php查看网页源代码的方法,涉及php读取网页文件的技巧,具有一定参考借鉴价值,需要的朋友可以参考下     本文实例讲述了php查看网页源代码的方法.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 <?php $url = "http://www.jb51.net"; $fp = @fopen($url, 'r') or die("Cannot Open $url via Get method"); wh

用火狐浏览器查看网页源代码的方法

  用火狐浏览器查看网页源代码的方法 火狐浏览器 用火狐浏览器查看网页源代码的方法: 1.下载并安装火狐浏览器,打开火狐浏览器; 2.用火狐浏览器打开指定网页; 3.对着网页鼠标右键,就会有一个查看源码; 源代码 4.点击进去就是这个网页的源码了.

php查看网页源代码的方法_php技巧

本文实例讲述了php查看网页源代码的方法.分享给大家供大家参考.具体实现方法如下: <?php $url = "http://www.jb51.net"; $fp = @fopen($url, 'r') or die("Cannot Open $url via Get method"); while ($line = @fgets($fp, 1024)) { $contents .= $line; } fclose($fp); ?> 希望本文所述对大家的

20种看ASP源代码的方法及工具

众所周知windows平台漏洞百出,补丁一个接一个,但总是补也补不净.我把我所知道的20种看asp源码的方法总结了一下,并且用c#写了个应用程序来扫描这些漏洞,发现虽然大部分的方法已经不起做用,但还是有一些漏网之鱼的:),结果这两天真看到不少站的源代码,包括数据库密码,如果用access的可以把库下载下来,而用sql server的如果不是用udl,dsn等来连接的话,也可以通过tcp/ip网络库连接到数据库,为所欲为呀.先面把这20种方法列在下面:.%81::DATA%2e%2e%41sp+.

【转】ASP网站源代码修改方法

一.怎么样去除默认的管理员(joekoe) 先用joekoe这个管理员进入后台,找到一个配置管理asp源代码,点基本信息配置,可以修改超级管理员,就是现在的joekoe点用户管理里的某一用户asp.net,可以进行类型修改,可改成管理员.当你添加了别的管理员后,就可以点权限管理,再点某一管理员,就可以设置他的权限了,只要选中就行了.点击确定. 二.如何添加新的菜单和新的页面 添加新的菜单的格式如下:abc:新的菜单那么新建个.asp文件:abc.asp文件内容可以有两种形式:第一种是直接转到你的

JS禁止查看网页源代码的实现方法_javascript技巧

先给大家分享下三种查看路径的方法: 1.直接按F12 2.Ctrl+Shift+I查看 3.鼠标点击右键查看 把以上三种状态都屏蔽掉就可以了,document有onkeydown(键盘按键事件),该事件里面找到对应的keycode并处理就可以,document也有oncontextmenu鼠标右键事件,屏蔽即可. JS撸码如下: window.onload=function(){ document.onkeydown=function(){ var e=window.event||argumen

让别人看不到我的网页源代码的方法汇总

网页|源代码 1.将以下代码加入到HEML的<body></body>之间 <SCRIPT language=javascript> function click() {if (event.button==2) {alert('不许你偷看!');}}document.onmousedown=click </SCRIPT> ................................................................. 2.禁

虚拟web目录容易泄露ASP源代码 (MS,缺陷)

web|源代码 涉及程序: Microsoft Internet Information Server/Index Server 描述: 震撼安全发现:新的漏洞允许查看web服务器上任何文件包括ASP源码 详细: IIS4.0上有一个应用程序映射htw--->webhits.dll,这是用于Index Server的点击功能的.尽管你不运行Index Server,该映射仍然有效.这个应用程序映射存在漏洞,允许入侵者读取本地硬盘上的文件,数据库文件,和ASP源代码!有两种方法来实现,第一,如果你

把存储在SQL7的image字段的文件下载到客户端的ASP源代码

客户端|下载|源代码 把存储在SQL7的image字段的文件下载到客户端的ASP源代码 文 件 名:download.asp 使用方法:download.asp?fid=xxx说 明:把SQL7的image字段存储的文件下载到客户端数据库结构:[表名]tabimage {fid int not null;filename varchar(100) not null;filecontent image not null}fid:文件id [PK]:filename:文件名:filecontent: