0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

xpathの使い方

Posted at

[EventLog][xpath]
xpathを使用する機会があったので、今後のためにメモ。

対象とするイベントログ

  • イベントログの例
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="Microsoft-Windows-Security-Auditing" Guid="{54849625-5478-4994-a5ba-3e3b0328c30d}" />
        <EventID>4624</EventID>
        <Version>2</Version>
        <Level>0</Level>
        <Task>12544</Task>
        <Opcode>0</Opcode>
        <Keywords>0x8020000000000000</Keywords>
        <TimeCreated SystemTime="2025-10-15T10:39:12.123456Z" />
        <EventRecordID>123456</EventRecordID>
        <Correlation />
        <Execution ProcessID="500" ThreadID="600" />
        <Channel>Security</Channel>
        <Computer>WIN-RASPI01.local</Computer>
        <Security />
      </System>
      <EventData>
        <Data Name="SubjectUserSid">S-1-5-18</Data>
        <Data Name="SubjectUserName">WIN-RASPI01$</Data>
        <Data Name="SubjectDomainName">WORKGROUP</Data>
        <Data Name="SubjectLogonId">0x3e7</Data>
        <Data Name="TargetUserSid">S-1-5-21-1234567890-1234567890-1234567890-1001</Data>
        <Data Name="TargetUserName">hogehoge</Data>
        <Data Name="TargetDomainName">WIN-RASPI01</Data>
        <Data Name="TargetLogonId">0x1a2b3c4d</Data>
        <Data Name="LogonType">10</Data>
        <Data Name="LogonProcessName">User32</Data>
        <Data Name="AuthenticationPackageName">Negotiate</Data>
        <Data Name="WorkstationName">REMOTEPC01</Data>
        <Data Name="LogonGuid">{00000000-0000-0000-0000-000000000000}</Data>
        <Data Name="TransmittedServices">-</Data>
        <Data Name="LmPackageName">-</Data>
        <Data Name="KeyLength">128</Data>
        <Data Name="ProcessId">0x0</Data>
        <Data Name="ProcessName">-</Data>
        <Data Name="IpAddress">123.123.123.xxx</Data>
        <Data Name="IpPort">54123</Data>
        <Data Name="ImpersonationLevel">Impersonation</Data>
        <Data Name="RestrictedAdminMode">-</Data>
        <Data Name="TargetOutboundUserName">-</Data>
        <Data Name="TargetOutboundDomainName">-</Data>
        <Data Name="VirtualAccount">false</Data>
        <Data Name="TargetLinkedLogonId">0x0</Data>
        <Data Name="ElevatedToken">true</Data>
      </EventData>
    </Event>
    

xpathの例

  • 指定方法
    日時の指定はUTCでの指定になる。
    日本時間の場合は、9時間前の時間を指定する必要がある。
    例)10/1 00:00:00 -> 9/30 15:00:00

  • 以下のフィルタは、以下の環境で正常に実行されることを確認
    管理コンソール 3.0
    バージョン22H2(OSビルド19045.4170)
    イベント ビューアー Microsoft Corporation(c) バージョン: 1.0

  • イベントIDと日時で絞り込み

    <QueryList>
      <Query Id="0" Path="Security">
        <Select Path="Security">
          *[System
            [(EventID=4624 or EventID=4625) 
              and
              TimeCreated
              [
                @SystemTime&gt;='2024-09-30T15:00:00.000Z'
                and 
                @SystemTime&lt;='2024-10-19T15:00:00.999Z'
              ]
            ]
          ]
        </Select>
      </Query>
    </QueryList>
    
  • ログオンタイプと日時で絞り込み

    <QueryList>
      <Query Id="0" Path="Security">
        <Select Path="Security">
          *[System
            [TimeCreated
              [
                @SystemTime&gt;='2024-09-30T15:00:00.000Z'
                and 
                @SystemTime&lt;='2024-10-19T15:00:00.999Z'
              ]
            ]
          ] and
          *[EventData
            [Data
              [@Name='LogonType']='10'
            ]
          ]
        </Select>
      </Query>
    </QueryList>
    
  • イベントを「発生させた側」のユーザ(SubjectUserName)とイベントの対象となったユーザ(TargetUserName)で絞り込み

    <QueryList>
      <Query Id="0" Path="Security">
        <Select Path="Security">
          *[EventData
            [
            (Data[@Name='TargetUserName']='username')
              or
            (Data[@Name='SubjectUserName']='username')
            ]
          ]
        </Select>
      </Query>
    </QueryList>
    
  • 特定の文字列がEventDataの項目に出現(完全一致)するイベントログを絞り込み

    <QueryList>
      <Query Id="0" Path="Security">
        <Select Path="Security">
          *[EventData[Data='username']]
        </Select>
      </Query>
    </QueryList>
    
  • 複数のログファイルに対して、プロセスIDを指定して絞り込み(Query Idを統一)

    <QueryList>
      <Query Id="0">
        <Select Path="Security">
          *[System[Execution[@ProcessID="656"]]]
        </Select>
        <Select Path="System">
          *[System[Execution[@ProcessID="2192"]]]
        </Select>
      </Query>
    </QueryList>
    
  • 外部のファイルを指定してイベントIDで絞り込んだログと、外部のファイルを指定してログオンタイプで絞り込んだログを表示(Query Idを区別)

    <QueryList>
      <Query Id="0">
        <Select Path="file://C:\Users\hogehoge\Desktop\Logs\Sysmon-Operational.evtx">
          *[System[(EventID=1 or EventID=3)]]
        </Select>
      </Query>
      <Query Id="1">
        <Select Path="file://C:\Users\hogehoge\Desktop\Logs\Security.evtx">
          *[EventData[Data[@Name='LogonType']='10']]
        </Select>
      </Query>
    </QueryList>
    

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?