A Practical guide for Sysmon : Configure file fields and writing

1. 개요

이전 'Sysmon 활용 가이드: 이벤트 구성 항목'에서 Sysmon이 기록하는 이벤트의 구성 항목을 알아봤다. 본 글에서는 Sysmon Configure File의 구성과 작성 방법을 살펴본다.

Sysmon을 기본 설정으로 설치하게 되면 기록하지 않는 이벤트가 존재하고, 설정을 모두 활성화하면 매우 많은 이벤트가 기록되어 정작 필요한 이벤트를 놓칠 수 있다. 따라서 시스템 용도에 따라 Configure File을 작성해야 한다.

XML 형식의 Configure File은 이벤트 유형이 정의된 필드에 논리 연산(AND, OR)을 적용해 많은 필터링 옵션을 사용할 수 있어 높은 유연성을 가진다.

-i 또는 -c 옵션 뒤에 Configure File을 지정해 적용할 수 있다.

1) Sysmon 설치 시 Configure File 적용

sysmon.exe -i <Configure File>

2) Sysmon 구동 중 Configure File 적용

sysmon.exe -c <Configure File>

Configure File이 정상적으로 적용됐는지 Command Line 명령어와 Registry로 확인할 수 있다.

1) Command Line

sysmon.exe -c
[그림 1] sysmon.exe -c 명령어 출력 내용
[그림 1] sysmon.exe -c 출력 내용

2) Registry

🧭
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SysmonDrv\Parameters
[그림 2] Sysmon Configure File Registry
[그림 2] Sysmon Configure File Registry

2. Schema Version

Schema Version은 Configure File의 버전을 지정하는 값으로 Configure File을 작성할 때 반드시 지정해야 한다.

현재 Schema Version은 sysmon.exe -? config 명령어를 사용해 확인할 수 있다.

[그림 3] sysmon.exe -? config 결과 일부
[그림 3] sysmon.exe -? config 결과 일부

Schema Version에는 Sysmon Configure File 구조와 Option이 정의되어 있으며, 각 Schema Version의 내용은 sysmon.exe -s [Schema Version] 명령어로 확인할 수 있다.

[그림 4] sysmon.exe -s 4.83 결과 일부
[그림 4] sysmon.exe -s 4.83 결과 일부

Sysmon 기능이 추가되면 Schema Version도 변경된다. Schema Version은 Sysmon Version과는 독립적이며, 이전 Version도 사용할 수 있다. 하지만, Sysmon의 기능과 호환성을 제어하는 중요한 역할을 해 Configure File을 작성할 때 항상 최신 버전의 Sysmon과 해당 버전에 맞는 Schema Version을 사용하는 것이 좋다.


3. Configure File 구성

Configure File은 아래 항목들로 구성된다.

  • <Sysmon> : Configure File의 최상위 요소로 Schema Version을 정의
  • <Configure_Entries> : Sysmon Meta Config(HashAlgorithms 등)를 정의
  • <EventFiltering> : Sysmon 이벤트 필터링을 위한 요소
  • <RuleGroup> : 같은 종류의 이벤트에 대한 필터링을 그룹화해 논리 연산 적용
  • <Event_Tag> : 필터링 할 이벤트를 지정
  • <Field> : 이벤트에서 필터링할 필드를 지정
<Sysmon schemaversion="0.00">
	<Configure_Entries>...</Configure_Entries>
	<EventFiltering>
		<RuleGroup name="", groupRelation="">
			<Event_Tag onmatch="">
				<!-- Filtering -->
				<Field condition=""> ... </Field>
				<Rule name="", groupRelation="">
					<Field condition=""> ... </Field>
				</Rule>
			</Event_Tag>
		</RuleGroup>
	</EventFiltering>
</Sysmon>

▲ Configure File 구성 요소

3.1. Configure Entries

<Configure_Entries>는 Sysmon Command Line 옵션 명령어와 유사하며, Configure File 내 설정값을 지정할 수 있다.

항목 타입 설명
ArchiveDirectory String 삭제된 파일이 저장되는 Volume roots 디렉토리 이름
폴더가 시스템 ACL로 보호(기본값: Sysmon)
* CLI에서는 "-a" 옵션으로 설정 가능
CheckRevocation Boolean 폐지된 서명 검사 기능 제어 여부(기본값: True)
* CLI에서는 "-r" 옵션으로 설정 가능
CopyOnDeletePE Boolean 삭제된 PE 파일 ArchiveDirectory 복사 여부(기본값: False)
CopyOnDeleteSIDs Strings 파일 삭제 시 ArchiveDirectory에 복사할 계정 SID 목록
CopyOnDeleteExtensions Strings 파일 삭제 시 ArchiveDirectory에 복사할 확장자명 목록
CopyOnDeleteProcesses Strings 파일 삭제 시 ArchiveDirectory에 복사할 프로세스 목록
DnsLookup Boolean Reverse DNS lookup 제어 여부(기본값: True)
DriverName String Sysmon Driver 및 Service 이름을 지정된 이름으로 실행
* CLI에서는 "-d" 옵션으로 설정 가능
HashAlgorithms Strings Hash에 적용할 Hash 알고리즘 목록(기본값: None)
지원되는 알고리즘 : MD5, SHA1, SHA256, IMPHASH 및 *(All)
* CLI에서는 "-h" 옵션으로 설정 가능

3.2. Sysmon Event Filtering

3.2.1. RuleGroup

<RuleGroup>은 같은 종류의 이벤트 필터들을 그룹화해 관리할 수 있으며, groupRelation 속성을 사용해 필터 간 논리 연산을 수정할 수 있다. <RuleGroup> 당 하나의 단일 <Event_Tag>만 가질 수 있으며, 둘 이상의 다른 <Event_Tag>가 있는 경우 Sysmon에서 오류가 발생하지 않지만 첫 번째 <Event_Tag>만 적용된다.

<RuleGroup name="Group Name", groupRelation="and|or">
	...
</RuleGroup>

▲ RuleGroup 사용 예시

💡
Schema Version 4.22 이상에서 필터 간의 기본 관계는 AND이다.

3.2.2. Event Tag

필터링을 하기 위해서는 아래 표와 같이 이벤트 별로 매칭되는 Tag를 사용한다.

Event ID Tag Event Name
1 ProcessCreate Process Create
2 FileCreateTime File creation time changed
3 NetworkConnect Network connection detected
4 N/A Sysmon service state changed
5 ProcessTerminate Process terminated
6 DriverLoad Driver loaded
7 ImageLoad Image loaded
8 CreateRemoteThread CreateRemoteTread detected
9 RawAccessRead RawAccessRead detected
10 ProcessAccess Process accessed
11 FileCreate File created
12 RegistryEvent Registry Object added or deleted
13 RegistryEvent Registry Value set
14 RegistryEvent Registry Object renamed
15 FileCreateStreamHash File stream created
16 N/A Sysmon config state changed
17 PipeEvent Pipe Created
18 PipeEvent Pipe Connected
19 WmiEvent WmiEventFilter activity detected
20 WmiEvent WmiEventConsumer activity detected
21 WmiEvent WmiEventConsumerToFilter activity detected
22 DNSQuery DNS query
23 FileDelete File Delete archived
24 ClipboardChange Clipboard changed
25 ProcessTampering Process Tampering
26 FileDeleteDetected File Delete logged
27 FileBlockExecutable File Block Executable
28 FileBlockShredding File Block Shredding

3.2.3. onmatch

<Event_Tag>에서 반드시 onmatch 속성을 지정해야 한다. 이벤트가 일치하게 되면 onmatch의 값인 'include'와 'exclude'에 따라 이벤트를 포함하거나 제외할 수 있다.

<ProcessCreate onmatch="include|exclude">
	<Field>...</Field>
</ProcessCreate>

▲ onmatch 속성 사용 예시

아무런 필터 없이 'include'를 사용하면 해당 <Event_Tag>에 대해 아무 것도 기록하지 않는다.

<Event_Tag onmatch="include">
</Event_Tag>

▲ 이벤트에 대해 기록하고 싶지 않을 때 사용

아무런 필터 없이 'exclude'를 사용하면 해당 <Event_Tag>에 대해 모든 이벤트를 기록한다.

<Event_Tag onmatch="exclude">
</Event_Tag>

▲ 모든 이벤트를 기록하고 싶을 때 사용

3.2.4. Filtering(Field 및 Condition)

각 이벤트 유형의 <Field>를 필터링하기 위해 condition 속성을 사용할 수 있으며, 각 <Field>에는 0개 이상의 필터가 포함될 수 있다. 동일한 <Field> 이름에 대한 필터는 OR 조건으로 동작하고, 다른 <Field> 이름에 대한 필터는 AND 조건으로 동작한다.

<Field> 값에 대한 condition은 아래 표와 같이 대소문자 구분 없이 사용할 수 있다.

조건 설명
is 기본 값, 값이 동일
is any 필드는 세미콜론(;)으로 구분된 값 중 하나
is not 값이 다름
contains 필드에 해당 값이 포함
contains any 필드에 세미콜론(;)으로 구분된 값이 포함
contains all 필드에 세미콜론(;)으로 구분된 값이 모두 포함
excludes 필드에 해당 값이 없음
excludes any 필드에 세미콜론(;)으로 구분된 값이 하나 이상 없음
excludes all 필드에 세미콜론(;)으로 구분된 값이 모두 없음
begin with 필드가 해당 값으로 시작
end with 필드가 해당 값으로 종료
not begin with 필드가 해당 값으로 시작되지 않음
not end with 필드가 해당 값으로 종료되지 않음
less than 사전식 비교 시 0보다 작음
more than 사전식 비교 시 0보다 큼
image 이미지 경로가 일치하는 경우 (전체 경로 또는 이미지 명으로 지정 가능)
ex) lsass.exe 또는 c:\windows\system32\lsass.exe
<Image name="Rule Name" condition="is">C:\Windows\system32\audiodg.exe</Image>

▲ condition 속성 사용 예시

condition 미 설정 시 기본적으로 'is'로 적용되며, name 속성은 이벤트가 생성될 때 이벤트의 RuleName 필드를 채우는 데 사용된다.


4. Configure File 작성 예시

앞서 살펴본 Configure File 작성 방법을 더 쉽게 이해해 보기 위해 간단한 예시를 작성해 봤다.

<Sysmon schemaversion="4.83">
	<!-- Configure_Entries -->
	<ArchiveDirectory>SYSMON_Archive</ArchiveDirectory>
	<HashAlgorithms>md5,sha1</HashAlgorithms>
	<DnsLookup>False</DnsLookup>
	
	<EventFiltering>
		<!-- RuleGroup 1 -->
		<RuleGroup name="Event ID 1 Process Create", groupRelation="or">
			<ProcessCreate onmatch="include">
				<Image name="CMD" condition="is">C:\Windows\System32\cmd.exe</Image>
				<Image name="PowerShell" condition="image">powershell.exe</Image>
				<ParentImage name="UAC Bypass" condition="image">fodhelper.exe</ParentImage>
				<Rule name="Windows Defender Tampering">
					<Image name="Disable or Modify Tools" condition="image">MpCmdRun.exe</Image>
					<CommandLine name="Disable or Modify Tools" condition="contains any">Add-MpPreference;RemoveDefinitions;DisableIOAVProtection</CommandLine>
				</Rule>
			</ProcessCreate>
		</RuleGroup>
		
		<!-- RuleGroup 2 -->
		<RuleGroup name="Event ID 2 File creation time changed", groupRelation="or">
			<FileCreateTime onmatch="exclude"/>
		</RuleGroup>
		
		<!-- RuleGroup 3 -->
		<RuleGroup name="Event ID 23 File Delete archived", groupRelation="or">
			<FileDelete onmatch="include">
				<Rule name="Script Files">
					<TargetFilename condition="end with">.aspx</TargetFilename>
					<TargetFilename condition="end with">.bat</TargetFilename>
					<TargetFilename condition="end with">.ps1</TargetFilename>
					<TargetFilename condition="end with">.vbs</TargetFilename>
					<TargetFilename condition="end with">.vba</TargetFilename>
					<TargetFilename condition="end with">.hta</TargetFilename>
					<TargetFilename condition="end with">.jar</TargetFilename>
					<TargetFilename condition="end with">.js</TargetFilename>
					<TargetFilename condition="end with">.cmd</TargetFilename>
					<TargetFilename condition="end with">.sh</TargetFilename>
					<TargetFilename condition="end with">.sct</TargetFilename>
					<TargetFilename condition="end with">.lnk</TargetFilename>
				</Rule>
			</FileDelete>
		</RuleGroup>
	</EventFiltering>
</Sysmon>

▲ Configure File 예시

예시로 작성한 Configure File의 구성을 보면 아래와 같이 나눠볼 수 있다.

1) Configure_Entries

<ArchiveDirectory>는 경로를 지정하지 않으면 %SystemDrive%에 생성되어, 해당 시스템의 %SystemDrive%가 C: 라면 'C:\SYSMON_Archive'로 ArchiveDirectory가 생성된다.

<HashAlgorithms>은 Hash 값을 포함하는 이벤트에서 지정한 MD5와 SHA1 알고리즘을 사용한다.

<DnsLookup>의 값을 False로 지정해 Reverse DNS lookup을 기록하지 않는다.

2) RuleGroup 1

첫 번째 RuleGroup은 <ProcessCreate> 태그의 onmatch를 'include'로 지정하고 필터를 작성해 필터에 해당하는 프로세스 생성 이벤트들을 기록한다.

<Image> 필드가 'cmd.exe', 'powershell.exe'로 프로세스가 생성되고, <ParentImage> 필드가 UAC Bypass로 주로 사용되는 'fodhelper.exe'로 생성되면 이벤트를 기록한다.

<Rule> 태그에 다른 이름의 필드가 존재하면 필드 간에 AND 조건으로 동작해 Windows Defender Tampering을 탐지하기 위해 비활성화와 설정 변경에 사용되는 'MpCmdRun.exe'에 'Add-MpPreference', 'RemoveDefinitions', 'DisableIOAVProtection' 값 중 하나라도 포함되면 이벤트를 기록한다.

3) RuleGroup 2

두 번째 RuleGroup은 <FileCreateTime> 태그의 onmatch를 'exclude'로 지정하고 필터를 주지 않아 파일 생성 시간 변경에 대한 모든 이벤트를 기록한다.

4) RuleGroup 3

세 번째 RuleGroup은 <FileDelete> 태그의 onmatch를 'include'로 지정하고 필터를 작성해 해당되는 파일 삭제 이벤트들을 기록한다.

<Rule> 태그에 같은 필드가 존재하면 필드 간에 OR 조건으로 동작해 스크립트 파일 확장자에 해당하는 파일이 삭제되면 이벤트를 기록한다.

💡
위 예시는 Configure File 작성 방법을 보여주기 위한 간단한 예시로 실제 Configure File은 시스템과 용도에 따라 작성해야 한다.

본 글에서는 Sysmon Configure File의 구성과 작성 방법을 알아봤다. 다음 글은 'Sysmon 활용 가이드: 분석 활용 방안'으로 Sysmon 이벤트를 어떻게 분석할 수 있는지 CASE 시나리오로 알아본다.

You've successfully subscribed to PLAINBIT
Great! Next, complete checkout to get full access to all premium content.
Error! Could not sign up. invalid link.
Welcome back! You've successfully signed in.
Error! Could not sign in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.