Microsoft로 로그인
로그인하거나 계정을 만듭니다.
안녕하세요.
다른 계정을 선택합니다.
계정이 여러 개 있음
로그인할 계정을 선택합니다.

소개

Microsoft는 원격 코드 실행 문제를 야기할 수 있는 Microsoft SQL Server의 취약성에 대한 보안 권고를 발표했습니다. 보안 권고에는 추가 보안 관련 정보가 들어 있습니다. 보안 권고를 보려면 다음 Microsoft 웹 사이트를 방문하십시오.

http://www.microsoft.com/korea/technet/security/advisory/961040.mspx이 문서에는 로컬 컴퓨터에서 실행되는 모든 SQL Server 인스턴스에 해결 방법을 적용하는 데 사용할 수 있는 VB 스크립트가 포함되어 있습니다.

해결 방법 적용을 위해 사용할 수 있는 VB 스크립트의 예

이 VB 스크립트를 사용하여 로컬 컴퓨터에서 실행되는 모든 영향 받는 SQL Server 버전에서 sp_replwritetovarbin 확장 저장 프로시저에 대한 공용 역할의 실행 권한을 거부할 수 있습니다.

Microsoft는 모든 보증(상품, 특정 목적에의 적합성에 대한 묵시적인 보증을 포함하며 이에 제한되지 않음)을 배제하며 예를 보여주기 위한 목적으로만 이 프로그래밍 예제를 제공합니다. 본 문서의 내용은 프로시저를 작성하고 디버깅하는 데 사용되는 도구 및 여기서 설명하는 프로그래밍 언어에 익숙한 사용자를 대상으로 합니다. Microsoft 지원 담당자는 사용자에게 도움이 되도록 특정 프로시저에 대한 기능을 설명할 수 있지만 사용자의 특정 요구 사항에 맞도록 예제를 수정하여 추가 기능을 제공하거나 프로시저를 구성하지는 않습니다.


이 코드를 텍스트 파일에 복사하고 .vbs 파일 이름 확장명을 사용하여 저장한 후 CScript.exe를 사용하여 스크립트 파일을 실행합니다. 이 스크립트는 로컬 컴퓨터에서 실행하는 SQL Server 인스턴스 전체에 대해 반복 수행되며 영향받는 버전에 해결 방법을 적용합니다. 이 해결 방법을 적용하려면 모든 SQL Server 인스턴스에서 sysadmin 역할의 구성원이어야 합니다. SQL Server가 실행되는 모든 영향받는 서버에서 sysadmin 역할의 구성원인 Windows 계정이 없는 경우 여러 계정에서 이 스크립트를 실행해야 할 수 있습니다. Windows Server 2008 및 Windows Vista에서 sysadmin 역할의 구성원인 Windows 관리자 계정을 사용하는 경우, “권한이 승격된” 명령 프롬프트에서 이 스크립트를 실행해야 합니다.

'*************************************************************************************
'Description: This script iterates through all the running instances of SQL Server
' and denies execute permission on sp_replwritetovarbin to public on all
' the affected versions.
' THIS IS PROVIDED AS A WORKAROUND AND SHOULD NOT BE USED IN THE EVENT THAT
' A SECURITY UPDATE IS PROVIDED AND INSTALLED.
'*************************************************************************************

OPTION EXPLICIT
ON ERROR RESUME NEXT

' Constant values
CONST EXIT_SUCCESS = 0
CONST EXIT_FAILURE = 1
CONST EXIT_NOINSTANCES = -1
CONST DEFAULTNAMESPACE = "root\default"
CONST STDREGPROV = "stdregprov"
CONST HKEY_LOCAL_MACHINE = &H80000002
CONST REG_MULTI_SZ = 7
CONST REG_SZ = 1
CONST adCmdText = 1


Call VBMain()

Function VBMain()
Err.Clear
ON ERROR RESUME NEXT

Dim sInstances(), strInstance, i, TotalCount
VBMain = EXIT_SUCCESS
If GetInstances(sInstances, TotalCount) = FALSE Then
WScript.Quit EXIT_FAILURE
End If

If IsEmptyNull(sInstances) Then
WScript.Echo "정보: 인스턴스가 없습니다."
VBMain = EXIT_NOINSTANCES
Exit Function
End If

For i = 0 To TotalCount-1
strInstance = sInstances(i,0)
GetFullInstance strInstance, sInstances(i,1)
If ApplyFix(sInstances(i,0), strInstance) = FALSE Then
WScript.Echo "오류: " + sInstances(i,0) + "에 해결 방법을 적용할 수 없습니다." + vbCRLF
VBMain = EXIT_FAILURE
End If
Next

WScript.Echo "정보: 실행 중인 모든 SQL 인스턴스의 처리가 완료되었습니다."
End Function

Function GetInstances(ByRef sInstances, ByRef TotalCount)
Err.Clear
ON ERROR RESUME NEXT

Dim sInstances1, sInstances2, i
Dim instCount1, instCount2
GetInstances = FALSE

If NOT GetRegValue ("", HKEY_LOCAL_MACHINE, "Software\Microsoft\Microsoft SQL Server", "InstalledInstances", sInstances1, REG_MULTI_SZ, TRUE) Then
WScript.Echo "오류:시스템에 설치된 SQL 인스턴스를 읽지 못했습니다."
Exit Function
End If

sInstances2 = NULL
If IsOs64Bit() = TRUE Then
If NOT GetRegValue ("", HKEY_LOCAL_MACHINE, "Software\Microsoft\Microsoft SQL Server", "InstalledInstances", sInstances2, REG_MULTI_SZ, FALSE) Then
WScript.Echo "오류:시스템에 설치된 SQL 인스턴스를 읽지 못했습니다."
Exit Function
End If
End If

If IsEmptyNull(sInstances1) AND IsEmptyNull(sInstances2) Then
WScript.Echo "정보: 인스턴스가 없습니다."
WScript.Quit EXIT_SUCCESS
End If

instCount1 = 0
instCount2 = 0
TotalCount = 0
If IsEmptyNull(sInstances1) = FALSE Then
instCount1 = UBound(sInstances1) + 1
TotalCount = instCount1
End If

If IsEmptyNull(sInstances2) = FALSE Then
instCount2 = UBound(sInstances2) + 1
TotalCount = TotalCount + instCount2
End If

ReDim PRESERVE sInstances(TotalCount,1)
if instCount1 > 0 Then
For i = 0 To UBound(sInstances1)
sInstances(i,0) = sInstances1(i)
sInstances(i,1) = True
Next
End If
If instCount2 >0 Then
For i = 0 To UBound(sInstances2)
sInstances(i+instCount1,0) = sInstances2(i)
sInstances(i+instCount1,1) = FALSE
Next
End If
GetInstances = TRUE
End Function


Function ApplyFix(ByVal strInstance, ByVal strServerName)
Err.Clear
ON ERROR RESUME NEXT

Dim objConn, objCmd, objCmd1, objRS, objRS1
Dim strCommand, strConn
Dim strBuildVersion, strProductLevel, bApplyFix

' Initialize return value
ApplyFix = FALSE

strConn = "Provider=sqloledb;Initial Catalog=master;Integrated Security=SSPI;Data Source=" + strServerName + ";"
' Error checking is intentionally left to keep the code short
Set objConn = CreateObject("ADODB.Connection")
Set objCmd = CreateObject("ADODB.Command")
Set objCmd1 = CreateObject("ADODB.Command")

' Open a Connection to the master Database
objConn.Open strConn
If ErrorOccurred("오류: 연결할 수 없습니다. " + strInstance) Then
Set objConn = Nothing
Exit Function
End If

' Validate the version before applying the fix
strCommand = "select SERVERPROPERTY('ProductVersion') as version, SERVERPROPERTY('productlevel') as productlevel"
objCmd.ActiveConnection = objConn
objCmd.CommandType = adCmdText
objCmd.CommandText = strCommand

Set objRS = objCmd.Execute()
If ErrorOccurred("오류: 실행할 수 없습니다. """ + strCommand + """ on " + strInstance) = TRUE Then
objConn.Close()
Set objConn = Nothing
ApplyFix = FALSE
Exit Function
End If

strBuildVersion = objRS("version")
strProductLevel = UCase(objRS("productlevel"))

bApplyFix = FALSE
' Apply the workaround only for SQL 2000 and SQL 2005 (RTM, SP1 and SP2) versions
If (CInt(Mid(strBuildVersion,1,1)) = 8) Then
bApplyFix = TRUE
ElseIf CInt(Mid(strBuildVersion,1,1)) = 9 AND (StrComp(strProductLevel,"RTM") = 0 OR StrComp(strProductLevel,"SP1") = 0 OR StrComp(strProductLevel,"SP2") = 0) Then
bApplyFix = TRUE
End If

If bApplyFix = TRUE Then
strCommand = "deny execute on sp_replwritetovarbin to public"
objCmd1.ActiveConnection = objConn
objCmd1.CommandType = adCmdText
objCmd1.CommandText = strCommand
Set objRS1 = objCmd1.Execute()
If ErrorOccurred("오류: 실행할 수 없습니다. """ + strCommand + """ on " + strInstance) = FALSE Then
WScript.Echo "정보: " + strInstance + "(" + strBuildVersion + ")에 해결 방법을 성공적으로 적용하였습니다." + vbCRLF
ApplyFix = TRUE
End If
Else
WScript.Echo "정보: " + strInstance + "(" + strBuildVersion + ") 인스턴스가 취약하지 않아 관련 정보 수집을 건너뛰었습니다." + vbCRLF
ApplyFix = TRUE
End If

objConn.Close()
Set objConn = Nothing
Set objCmd = Nothing
Set objCmd1 = Nothing
Set objRS = Nothing
Set objRS1 = Nothing
End Function

Private Function GetRegValue (ByVal strMachineName, ByVal hMainKey, ByVal strPath, ByVal strValueName, ByRef strValue, ByVal iValueType, ByVal b32bit)
Err.Clear
ON ERROR RESUME NEXT

Dim objLocator, objServices, objRegistry, objCtx
Dim sMultiStrings, lRc
GetRegValue = TRUE

'Connect to WMI and get an object to STDREGPROV class.
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
If b32bit = TRUE Then
objCtx.Add "__ProviderArchitecture", 32
Else
objCtx.Add "__ProviderArchitecture", 64
End If
objCtx.Add "__RequiredArchitecture", TRUE
set objLocator = createobject("wbemscripting.swbemlocator")
set objServices = objLocator.connectserver(strMachineName,DEFAULTNAMESPACE, "", "",,,,objCtx)
set objRegistry = objServices.get(STDREGPROV)
If ErrorOccurred("오류: WMI 네임스페이스에 연결할 수 없습니다. " + DEFAULTNAMESPACE) Then
GetRegValue = FALSE
Exit Function
End If

lRc = 0
Select Case iValueType
' We only care about REG_MULTI_SZ
Case REG_MULTI_SZ
strValue = ""
lRC = objRegistry.GetMultiStringValue(hMainKey, strPath, strValueName, sMultiStrings)
strValue = sMultiStrings
Case REG_SZ
strValue = ""
lRC = objRegistry.GetStringValue(hMainKey, strPath, strValueName, strValue)
Case Else
GetRegValue = FALSE
End Select

If lRc = 2 Or lRc = 3 Then
GetRegValue = TRUE
strValue = ""
ElseIf Err.Number OR lRc <> 0 Then
GetRegValue = FALSE
End If

Set objLocator = Nothing
Set objServices = Nothing
Set objRegistry = Nothing
End Function

Function IsEmptyNull(sCheck)
IsEmptyNull = FALSE
If IsObject(sCheck) Then Exit Function
If IsArray(sCheck) Then Exit Function
If VarType(sCheck) = vbEmpty Then IsEmptyNull = TRUE : Exit Function
If VarType(sCheck) = vbNull Then IsEmptyNull = TRUE : Exit Function
If sCheck = "" Then IsEmptyNull = TRUE
End Function

Private Function ErrorOccurred (ByVal strIn)
If Err.Number <> 0 Then
WScript.Echo strIn
WScript.Echo "오류: 0x" & Err.Number & " - " & Err.Description
Err.Clear
ErrorOccurred = TRUE
Else
ErrorOccurred = FALSE
End If
End Function

Function IsOs64Bit()
Err.Clear
ON ERROR RESUME NEXT

Dim objProc
Set objProc = GetObject("winmgmts:root\cimv2:Win32_Processor='cpu0'")
If objProc.Architecture = 0 Then
IsOs64Bit = FALSE
Else
IsOs64Bit = TRUE
End If
End Function

Function GetFullInstance (ByRef strInstanceName, ByVal b32bit)
Err.Clear
ON ERROR RESUME NEXT

Dim objServices, objClusters, objCluster
Dim strMacName, isEmpty
Dim strKey, strInstID

GetFullInstance = TRUE

If strComp(UCase(strInstanceName), "MICROSOFT##SSEE", 1) = 0 Then
strInstanceName = "np:\\.\pipe\mssql$microsoft##ssee\sql\query"
Exit Function
End if

strMacName = ""
Set objServices = GetObject("winmgmts:root\cimv2")

' Query Cluster service
Set objClusters = objServices.ExecQuery ("select * from win32_service where Name='ClusSvc' AND Started = TRUE")
isEmpty = TRUE
If Err.Number = 0 Then
For each objCluster in objClusters
isEmpty = FALSE
Next
End If

Set objServices = Nothing
Set objClusters = Nothing

If isEmpty = TRUE Then
strInstanceName = BuildInstanceName (".", strInstanceName)
Exit Function
End If

' If we reach here that means the machine is a clustered node.
' So lets query registry to determine whether the SQL instance is clustered or not.
' For SQL 2000 query the following value
' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\<InstanceName>\Cluster
' ClusterName
strKey = "SOFTWARE\Microsoft\Microsoft SQL Server\" + strInstanceName + "\Cluster"
GetRegValue "", HKEY_LOCAL_MACHINE, strKey, "ClusterName", strMacName, REG_SZ, b32bit

If StrComp(strMacName, "") <> 0 Then
strInstanceName = BuildInstanceName (strMacName, strInstanceName)
Exit Function
End If

strKey = "SOFTWARE\Microsoft\" + strInstanceName + "\Cluster"
GetRegValue "", HKEY_LOCAL_MACHINE, strKey, "ClusterName", strMacName, REG_SZ, b32bit

If StrComp(strMacName, "") <> 0 Then
strInstanceName = BuildInstanceName (strMacName, strInstanceName)
Exit Function
End If

' Lets try querying the registry value for 2005/2008 instances
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL
' RegValue = InstanceName
strInstID = ""
strKey = "SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL"
GetRegValue "", HKEY_LOCAL_MACHINE, strKey, strInstanceName, strInstID, REG_SZ, b32bit

If StrComp(strInstID, "") = 0 Then
' If this key doesnt exist, then return back as a SQL 2000 local instance
strInstanceName = BuildInstanceName (".", strInstanceName)
Exit Function
End If

strKey = "SOFTWARE\Microsoft\Microsoft SQL Server\" + strInstID + "\Cluster"
GetRegValue "", HKEY_LOCAL_MACHINE, strKey, "ClusterName", strMacName, REG_SZ, b32bit

If StrComp(strMacName, "") = 0 Then
strMacName = "."
End If

strInstanceName = BuildInstanceName (strMacName, strInstanceName)
End Function

Function BuildInstanceName (ByVal strMachineName, ByVal strInstanceName)
Dim strPrefix

strPrefix = ""
If StrComp(strMachineName, ".") = 0 Then
strPrefix = "lpc:"
End If

If strComp(UCase(strInstanceName), "MSSQLSERVER", 1) = 0 Then
BuildInstanceName = strPrefix + strMachineName
Else
BuildInstanceName = strPrefix + strMachineName + "\" + strInstanceName
End if
End Function

CScript.exe에 대한 자세한 내용을 보려면 다음 Microsoft 웹 사이트를 방문하십시오.

http://technet.microsoft.com/ko-kr/library/bb490887.aspx참고 보안 업데이트가 제공되었으며 사용자가 제공된 업데이트를 설치한 경우 이 스크립트를 사용하지 않을 것을 권장합니다.

이 스크립트 실행 시 발생할 수 있는 알려진 문제

문제 1

이 스크립트를 실행하면 다음 오류 메시지가 발생합니다.

오류: <instancename>에 대해 "deny execute on sp_replwritetovarbin to public"을 실행할 수 없습니다.
오류: 0x-2147217900 - 개체 'sp_replwritetovarbin'이 없거나 사용자에게 사용 권한이 없으므로 이 개체를 찾을 수 없습니다.
오류: <instancename>에 이 해결 방법을 적용할 수 없습니다.

원인 1

변경 내용을 적용하는 데 필요한 사용 권한이 없는 경우 이 오류 메시지가 발생합니다. 이 오류 메시지는 "<instancename>" 인스턴스에 성공적으로 로그인할 수 있었음을 나타냅니다.


이 오류 메시지는 일반적으로 "Built-In\Users" 그룹에 기본적으로 데이터베이스에 대한 로그인 권한이 있는 SQL Server Express에서 발생합니다. 그러나 이 그룹은 sysadmin 역할의 구성원이 아닙니다.

이 오류 메시지는 sp_replwritetovarbin 프로시저를 삭제한 경우에도 발생할 수 있습니다. 이 프로시저 삭제는 타사 보고서에 포함된 권장 작업이었습니다. Microsoft는 이 저장 프로시저의 삭제를 권장하지 않습니다. 대신 다음 해결 방법을 적용할 것을 권장합니다.

해결 방법 1

연결하는 계정이 해당 데이터베이스 인스턴스에서 sysadmin 역할의 구성원인지 확인하십시오. 이 계정이 해당 구성원이 아니면 연결할 사용자를 sysadmin 역할에 추가하거나 다른 사용자 계정을 사용하십시오. SQL Server 2005 및 이전 버전의 경우 "Built-in\Administrators" 그룹이 기본적으로 sysadmin 역할의 구성원입니다. Windows Vista 또는 Windows Server 2008에서 이 스크립트를 실행할 경우 “권한이 승격된” 명령 프롬프트에서 실행해야 합니다.

문제 2

이 스크립트를 SQL Server 2005에서 실행하는 경우 다음 오류 메시지가 발생합니다.

오류: <instancename>에 연결할 수 없습니다.
오류: 0x-2147217843 - 사용자 '<user>'이(가) 로그인하지 못했습니다.
오류: <instancename>에 이 해결 방법을 적용할 수 없습니다.

원인 2

이 인스턴스가 있는 경우에도 "<instancename>" 인스턴스에 연결할 수 없는 경우 이 오류 메시지가 발생합니다.


이 오류 메시지는 일반적으로 Windows 내부 데이터베이스 또는 Microsoft SQL Server 2000 Desktop Edition(Windows) 인스턴스에 연결할 때 발생합니다. 일반적으로 이러한 데이터베이스에 대해 로그인을 갖는 사용자 계정은 없습니다.

해결 방법 2

해당 데이터베이스에서 스크립트 실행에 사용하는 계정이 sysadmin 역할의 구성원인 로그인을 갖는지 확인하십시오.

Windows 내부 데이터베이스 및 Microsoft SQL Server 2000 Desktop Edition(Windows) 데이터베이스에 개별 사용자를 추가하는 것은 권장하지 않습니다. 추가 작업을 수행하면 추가한 사용자가 이러한 데이터베이스의 일반 작업을 방해할 수 있습니다. 이 경우 sysadmin 역할의 구성원인 계정에서 연결하는지 확인하십시오. Windows의 "Built-in\Administrators" 그룹은 기본적으로 SQL Server 2005 및 이전 버전에서 sysadmin 역할의 구성원입니다. Windows Vista 또는 Windows Server 2008에서 이 스크립트를 실행할 경우 "권한이 승격된" 명령 프롬프트에서 실행해야 합니다.

문제 3

이름이 MICROSOFT##SSEE인 데이터베이스 인스턴스를 발견할 수 있습니다. 그렇지만 이 데이터베이스를 설치한 적이 없습니다.

원인 3

이 데이터베이스는 "SQL Server Embedded Edition" 또는 때때로 "Windows 내부 데이터베이스"나 "Microsoft SQL Server 2000 Desktop Edition(Windows)"으로 알려져 있는 Windows 내부 데이터베이스입니다. 이 데이터베이스는 SharePoint Services를 비롯한 일부 Microsoft 제품과 함께 설치됩니다.

해결 방법 3

이 해결 스크립트는 Windows 내부 데이터베이스에 작동하도록 설계되었습니다. 사용자가 수행할 작업은 없습니다.

일부 응용 프로그램은 제거 시 Windows 내부 데이터베이스를 제거하지 않습니다.
Windows 내부 데이터베이스를 제거하는 방법에 대한 자세한 내용은 다음 문서 번호를 클릭하여 Microsoft 기술 자료 문서를 참조하십시오.

920277 Windows 내부 데이터베이스가 프로그램 추가/제거 도구에 표시되지 않으며 컴퓨터에서 Windows SharePoint Services 3.0을 제거할 때 Windows 내부 데이터베이스가 제거되지 않음 (영문)

문제 4

이 스크립트를 실행하면 다음 오류 메시지가 발생합니다.


오류: .\<instancename>에 연결할 수 없습니다.
오류: 0x-2147467259 - [DBNETLIB][ConnectionOpen (Connect()).]SQL Server가 없거나 액세스가 거부되었습니다.

원인 4

다음과 같은 경우 오류 메시지가 나타납니다.

  • 64비트 운영 체제에 32비트 버전의 SQL Server 2000을 설치했습니다.

  • 컴퓨터에 64비트 버전의 SQL Server 2005 또는 SQL Server 2008이 설치되어 있습니다.


이 오류 메시지는 해당 스크립트가 64비트 버전의 dbmslpcn.dll 파일을 사용하는 경우 발생합니다. 이 버전은 SQL Server 2000의 WoW 인스턴스와 통신할 수 없습니다.

해결 방법 4

%WINDOWS%\SysWOW64 폴더에 있는 32비트 버전의 cscript.exe 파일을 사용하여 해당 스크립트를 시작합니다. 그러면 WoW 인스턴스를 검색할 수 있는 32비트 버전의 dbmslpcn.dll 파일이 로드됩니다.

참조

SQL Server 버전 및 에디션을 확인하는 방법에 대한 자세한 내용은 다음 문서 번호를 클릭하여 Microsoft 기술 자료 문서를 참조하십시오.

321185SQL Server 버전과 에디션을 확인하는 방법

추가 정보

다음 표에는 이 문서의 중요한 기술 수정 내역이 나와 있습니다. 이 문서의 수정 번호와 마지막 검토 날짜에는 이 표에 포함되지 않은 이 문서의 간단한 편집 수정 내역이나 구조 수정 내역이 반영될 수도 있습니다.

날짜

수정 내역

2008년 12월 31일

SQL Server 장애 조치(failover) 클러스터링 인스턴스를 검색하는 업데이트된 스크립트를 포함합니다.

2008년 12월 30일

64비트 버전의 Windows에서 실행 중인 32비트 버전의 SQL Server를 검색하는 업데이트된 스크립트를 포함합니다.

도움이 더 필요하세요?

더 많은 옵션을 원하세요?

구독 혜택을 살펴보고, 교육 과정을 찾아보고, 디바이스를 보호하는 방법 등을 알아봅니다.

커뮤니티를 통해 질문하고 답변하고, 피드백을 제공하고, 풍부한 지식을 갖춘 전문가의 의견을 들을 수 있습니다.

이 정보가 유용한가요?

언어 품질에 얼마나 만족하시나요?
사용 경험에 어떠한 영향을 주었나요?
제출을 누르면 피드백이 Microsoft 제품과 서비스를 개선하는 데 사용됩니다. IT 관리자는 이 데이터를 수집할 수 있습니다. 개인정보처리방침

의견 주셔서 감사합니다!

×