Powershell script ile yerel makineler üzerinde oturum açma aktivitelerini kolay anlaşılır tablo biçiminde alan scripti paylaşacağım.
4624_User_Logon_Analysis.ps1
# ===========================================================
# NAME: 4624_User_Logon_Analysis.ps1
# AUTHOR: Bekir Yalçın
# DATE: 06/12/2012
# COMMENT: Oturum açma olayları analizi - EventID: 4624
# VERSION: 1
# ===========================================================
#
Clear
$Events=Get-Eventlog security -InstanceId 4624 -After (Get-Date).AddDays(-1) | # Son 1 gün
# $Events=Get-Eventlog security -InstanceId 4624 -After (Get-Date).AddHours(-1) | # Son 1 saat
Select TimeGenerated,ReplacementStrings |
% {
New-Object PSObject -Property @{
TimeGenerated = $_.TimeGenerated
SubjectUserSid = $_.ReplacementStrings[0]
SubjectUserName = $_.ReplacementStrings[1]
SubjectDomainName = $_.ReplacementStrings[2]
SubjectLogonId = $_.ReplacementStrings[3]
TargetUserSid = $_.ReplacementStrings[4]
TargetUserName = $_.ReplacementStrings[5]
TargetDomainName = $_.ReplacementStrings[6]
TargetLogonId = $_.ReplacementStrings[7]
LogonType = $_.ReplacementStrings[8]
LogonProcessName = $_.ReplacementStrings[9]
AuthenticationPackageName = $_.ReplacementStrings[10]
Source_WorkstationName = $_.ReplacementStrings[11]
LogonGuid = $_.ReplacementStrings[12]
TransmittedServices = $_.ReplacementStrings[13]
LmPackageName = $_.ReplacementStrings[14]
KeyLength = $_.ReplacementStrings[15]
ProcessID = $_.ReplacementStrings[16]
ProcessName = $_.ReplacementStrings[17]
Source_IPAddress = $_.ReplacementStrings[18]
Source_IpPort = $_.ReplacementStrings[19]
}
}
$Events | Where {$_.TargetUserName -notlike "*$" } |
Sort-Object -Descending TimeGenerated |`
Format-Table TimeGenerated,Source_WorkstationName,Source_IPAddress,
Source_IpPort,SubjectDomainName,SubjectUserName,TargetDomainName,
TargetUserName,@{Label="LogonTypeName"; Expression={
switch ($_.LogonType){
(2) {"Interactive"}
(3) {"Network"}
(4) {"Batch"}
(5) {"Service"}
(7) {"Unlock"}
(8) {"NetworkCleartext"}
(9) {"RunAs"}
(10) {"RemoteInteractive"}
(11) {"CachedInteractive"}
default {"Unknown"}
}
}
},LogonType,SubjectLogonId,TargetLogonId,SubjectUserSid,TargetUserSid,
LogonProcessName,AuthenticationPackageName,LogonGuid,TransmittedServices,
LmPackageName,KeyLength,ProcessID,ProcessName -AutoSize |
Out-File -Width 600 -Append -FilePath "4624_User_Logon_Reports.csv" -Encoding Unicode
Start "4624_User_Logon_Reports.csv"
[adsenseyu2]
Script çalıştırıldığında 4624_User_Logon_Reports.csv adında bir rapor dosyası oluşmaktadır. Bu dosyayı Microsoft Excel vb. uygulamalar ile açabilir ve otomatik sütunlara dönüştürebilirsiniz. Ayrıca Kolonlara filtre ekleyerek istediğiniz gibi inceleyebilirsiniz

1- TimeGenerated: Olay kaydı zamanı.
2- Source_WorkstationName: Kaynak makine adı. İş İstasyonu Adı (RDP oturumları hariç)
3- Source_IPAddress: Kaynak Ağ Adresi .
4- Source_IpPort: Kaynak Bağlantı Noktası
5- SubjectDomainName: Hedef makine Domain adı. Hesap Etki Alanı
6- SubjectUserName: Hedef makine adı. Hesap Adı
7- TargetDomainName: Bağlantı için kullanılan Domain adı. Hesap Etki Alanı
8- TargetUserName: Bağlantı için kullanılan kullanıcı hesap adı. Hesap Adı
9- LogonTypeName: Bağlantı tipi adı.
10- LogonType: Bağlantı tipi ID'si. Oturum Türü
11- SubjectLogonId: Oturum Açma Kimliği
12- TargetLogonId: İşlem Kimliği
13- SubjectUserSid:
14- TargetUserSid:
15- LogonProcessName: Oturum Açma İşlemi
16- AuthenticationPackageName: Kimlik Doğrulama Paketi
17- LogonGuid: Oturum Açma GUID'si
18- TransmittedServices: Aktarılan Hizmetler
19- LmPackageName: Kimlik Doğrulama Paket
20- KeyLength: Anahtar Uzunluğu
21- ProcessID: İşlem Kimliği
22- ProcessName: İşlem Adı
Event Viewer görünümü ile kolonların eşleşmesi:

Bağlantı tipleri ile ilgili ufak hatırlatmalar yapalım:

LogonTypeName:
Interactive (2): Interactive (logon at keyboard and screen of system)
Network (3): Network (i.e. connection to shared folder on this computer from elsewhere on network)
Batch (4): Batch (i.e. scheduled task)
Service (5): Service (Service startup)
Unlock (7): Unlock (i.e. unnattended workstation with password protected screen saver)
NetworkCleartext (8): NetworkCleartext (Logon with credentials sent in the clear text. Most often indicates a logon to IIS with "basic authentication")
RunAs (9): NewCredentials such as with RunAs or mapping a network drive with alternate credentials. This logon type does not seem to show up in any events. If you want to track users attempting to logon with alternate credentials see 4648.
RemoteInteractive (10): RemoteInteractive (Terminal Services, Remote Desktop or Remote Assistance)
CachedInteractive (11): CachedInteractive (logon with cached domain credentials such as when logging on to a laptop when away from the network)
Download script: http://siberblog.org/wp-content/uploads/2012/12/4624_User_Logon_Analysis.rar
Referans: http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4624
Hiç yorum yok:
Yorum Gönder