Hallo,
ich versuche, das Event 4625 () mit Powershell auszuwerten.
Um an die Datenstruktur zu kommen, nutze ich folgenden Code:
(Get-WinEvent-ListProviderMicrosoft-Windows-Security-Auditing).Events
|Where-Object{$_.Id
-eq4625}
Das ergibt folgendes Schema für das Ereignis 4625:
Id : 4625
Version : 0
LogLink : System.Diagnostics.Eventing.Reader.EventLogLink
Level : System.Diagnostics.Eventing.Reader.EventLevel
Opcode : System.Diagnostics.Eventing.Reader.EventOpcode
Task : System.Diagnostics.Eventing.Reader.EventTask
Keywords : {}
Template : <template xmlns="http://schemas.microsoft.com/win/2004/08/events">
<data name="SubjectUserSid" inType="win:SID" outType="xs:string"/>
<data name="SubjectUserName" inType="win:UnicodeString" outType="xs:string"/>
<data name="SubjectDomainName" inType="win:UnicodeString" outType="xs:string"/>
<data name="SubjectLogonId" inType="win:HexInt64" outType="win:HexInt64"/>
<data name="TargetUserSid" inType="win:SID" outType="xs:string"/>
<data name="TargetUserName" inType="win:UnicodeString" outType="xs:string"/>
<data name="TargetDomainName" inType="win:UnicodeString" outType="xs:string"/>
<data name="Status" inType="win:HexInt32" outType="win:HexInt32"/>
<data name="FailureReason" inType="win:UnicodeString" outType="xs:string"/>
<data name="SubStatus" inType="win:HexInt32" outType="win:HexInt32"/>
<data name="LogonType" inType="win:UInt32" outType="xs:unsignedInt"/>
<data name="LogonProcessName" inType="win:UnicodeString" outType="xs:string"/>
<data name="AuthenticationPackageName" inType="win:UnicodeString" outType="xs:string"/>
<data name="WorkstationName" inType="win:UnicodeString" outType="xs:string"/>
<data name="TransmittedServices" inType="win:UnicodeString" outType="xs:string"/>
<data name="LmPackageName" inType="win:UnicodeString" outType="xs:string"/>
<data name="KeyLength" inType="win:UInt32" outType="xs:unsignedInt"/>
<data name="ProcessId" inType="win:Pointer" outType="win:HexInt64"/>
<data name="ProcessName" inType="win:UnicodeString" outType="xs:string"/>
<data name="IpAddress" inType="win:UnicodeString" outType="xs:string"/>
<data name="IpPort" inType="win:UnicodeString" outType="xs:string"/>
</template>
Description : Fehler beim Anmelden eines Kontos.
Antragsteller:
Sicherheits-ID: %1
Kontoname: %2
Kontodomäne: %3
Anmelde-ID: %4
Anmeldetyp: %11
Konto, für das die Anmeldung fehlgeschlagen ist:
Sicherheits-ID: %5
Kontoname: %6
Kontodomäne: %7
Fehlerinformationen:
Fehlerursache: %9
Status: %8
Unterstatus:: %10
Prozessinformationen:
Aufrufprozess-ID: %18
Aufrufprozessname: %19
Netzwerkinformationen:
Arbeitsstationsname: %14
Quellnetzwerkadresse: %20
Quellport: %21
Detaillierte Authentifizierungsinformationen:
Anmeldeprozess: %12
Authentifizierungspaket: %13
Übertragene Dienste: %15
Paketname (nur NTLM): %16
Schlüssellänge: %17
Somit ist mir bekannt, dass das Datenfeld "FailureReason" ein Unicode-String ist.
Im Eventlog sieht das so aus:
Fehler beim Anmelden eines Kontos.
Antragsteller:
Sicherheits-ID: SYSTEM
Kontoname: TestClient$
Kontodomäne: testlab.local
Anmelde-ID: 0x3e7
Anmeldetyp: 7
Konto, für das die Anmeldung fehlgeschlagen ist:
Sicherheits-ID: NULL SID
Kontoname: User01
Kontodomäne: testlab.local
Fehlerinformationen:
Fehlerursache: Unbekannter Benutzername oder ungültiges Kennwort.
Status: 0xc000006d
Unterstatus:: 0xc000006a
Wert 0.
Ich benötige die Ausgabe "Unbekannter Benutzername oder ungültiges Kennwort."
Folgenden Code wurde genutzt, um das Feld auszulesen:
Get-WinEvent -FilterHashtable @{Path="c:\test.evtx";} -ErrorAction SilentlyContinue |
Where-Object {($_.id -eq "4625")}|
ForEach-Object{
if ($_.Id -eq 4625){
$SelectorStrings = [string[]]@(
'Event/EventData/Data[@Name="LogonType"]',
'Event/EventData/Data[@Name="FailureReason"]'
)
$PropertySelector = [System.Diagnostics.Eventing.Reader.EventLogPropertySelector]::new($SelectorStrings)
$LogonType,$FailureReason = $_.GetPropertyValues($PropertySelector)
#Create the PSCustomObject from the given Fieldnames
[PSCustomObject]@{
TimeCreated = $_.TimeCreated
FailureReason = $FailureReason
LogonType = $LogonType
}
}
}|Export-Csv -NoTypeInformation -Force -Encoding UTF8 -Path 'c:\temp\failedlogin.csv'
Als Ergebnis gibt es dann den Zeitstempel und einen StatusCode:
"TimeCreated","FailureReason","LogonType"
"04.12.2017 13:56:34","%%2313","7"
"04.12.2017 10:20:28","%%2309","2"
Im Microsoft-Artikel
https://docs.microsoft.com/en-us/windows/device-security/auditing/event-4625
steht, das Feld ist ein Unicode Feld:
Failure Reason [Type = UnicodeString]: textual explanation of Status field value. For this event it typically has “Account locked out” value.
•Status [Type = HexInt32]: the reason why logon failed. For this event it typically has “0xC0000234” value. The most common status codes are listed in “Table 12. Windows logon status codes.”
Wie bekomme ich den dynamischen Beschreibungstext der FailureReason in meine csv-Datei?
(Unbekannter Benutzername oder ungültiges Kennwort. oder eben was da steht im Feld?)
Danke