Programing

'xp_cmdshell'SQL Server 사용

lottogame 2020. 5. 25. 08:05
반응형

'xp_cmdshell'SQL Server 사용


나는 실행하고 싶다 EXEC master..xp_cmdshell @bcpquery

그러나 다음과 같은 오류가 발생합니다.

SQL Server는이 서버에 대한 보안 구성의 일부로이 구성 요소가 해제되어 있으므로 'xp_cmdshell'구성 요소의 'sys.xp_cmdshell'프로 시저에 대한 액세스를 차단했습니다. 시스템 관리자는 sp_configure를 사용하여 'xp_cmdshell'을 사용할 수 있습니다. 'xp_cmdshell'활성화에 대한 자세한 내용은 SQL Server 온라인 설명서의 "표면 영역 구성"을 참조하십시오.

이 기능을 활성화하거나 기능을 활성화하기 전에 무언가를 실행할 수있는 방법이 있습니까?

그것을 해결하는 방법?


활성화해야합니다. xp_cmdshell MSDN 문서 의 권한 섹션을 확인하십시오 .

http://msdn.microsoft.com/en-us/library/ms190693.aspx :

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO

재구성 후 고급 옵션을 다시 숨길 수도 있습니다.

-- show advanced options
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
-- enable xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
-- hide advanced options
EXEC sp_configure 'show advanced options', 0
GO
RECONFIGURE
GO

서버를 마우스 오른쪽 버튼으로 클릭->면-> 표면 영역 구성-> XPCmshellEnbled-> true 여기에 이미지 설명을 입력하십시오


다른 답변에 나와있는 것처럼, (SQL 2005 이상에서) 트릭에 대한 전역 구성 설정을 변경하는 것입니다 show advanced optionsxp_cmdshell1순서대로.

여기에 이전 값을 유지하려면 sys.configurations먼저 값을 읽은 다음 끝에 역순으로 적용하십시오. 불필요한 reconfigure전화를 피할 수도 있습니다 .

declare @prevAdvancedOptions int
declare @prevXpCmdshell int

select @prevAdvancedOptions = cast(value_in_use as int) from sys.configurations where name = 'show advanced options'
select @prevXpCmdshell = cast(value_in_use as int) from sys.configurations where name = 'xp_cmdshell'

if (@prevAdvancedOptions = 0)
begin
    exec sp_configure 'show advanced options', 1
    reconfigure
end

if (@prevXpCmdshell = 0)
begin
    exec sp_configure 'xp_cmdshell', 1
    reconfigure
end

/* do work */

if (@prevXpCmdshell = 0)
begin
    exec sp_configure 'xp_cmdshell', 0
    reconfigure
end

if (@prevAdvancedOptions = 0)
begin
    exec sp_configure 'show advanced options', 0
    reconfigure
end

이것은 SQL Server 버전 2005 이상에 의존합니다 (원래 질문은 2008).


수락 된 답변은 대부분 효과가 있지만, 그렇지 않은 경우가 있습니다 (아직도 이유를 모릅니다). WITH OVERRIDEin 을 사용하여 쿼리를 약간 수정 RECONFIGURE하면 솔루션이 제공됩니다.

Use Master
GO

EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO

EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
GO

예상 출력은

Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
Configuration option 'xp_cmdshell' changed from 0 to 1. Run the RECONFIGURE statement to install.


Even if this question has resolved, I want to add my advice about that.... since as developer I ignored.

Is important to know that we're talking about MSSQL xp_cmdshell enabled is critical to security, as indicated in the message warning:

Blockquote SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. [...]

서비스를 활성화 상태로 유지하는 것은 일종의 약점 입니다. 예를 들어 웹 응용 프로그램에서 공격자의 SQL 명령을 반영하고 실행할 수 있습니다. 널리 사용되는 CWE-89 : SQL Injection소프트웨어의 약점 일 수 있으므로 이러한 유형의 시나리오는 CAPEC-108 과 같은 가능한 공격을 유발할 수 있습니다 .Command Line Execution through SQL Injection

우리는 즐거운 일을하기를 희망합니다. 개발자와 엔지니어는 인식을 가지고 일을하고 더 안전해질 것입니다!


저에게 SQL 2008 R2의 유일한 방법은 다음과 같습니다.

EXEC sp_configure 'Show Advanced Options', 1    
RECONFIGURE **WITH OVERRIDE**    
EXEC sp_configure 'xp_cmdshell', 1    
RECONFIGURE **WITH OVERRIDE**

SQLcmd를 사용하여 수행 할 수 있습니다. 다음 명령을 실행했습니다.여기에 이미지 설명을 입력하십시오

참고 URL : https://stackoverflow.com/questions/5131491/enable-xp-cmdshell-sql-server

반응형