Query-InsecureLDAPBinds.ps1 수정

Query-InsecureLDAPBinds.ps1 수정

이 스크립트에서 찾은 시간 변수를 추가하는 방법을 알아내려고 합니다.

https://github.com/russelltomkins/Active-Directory/blob/master/Query-InsecureLDAPBinds.ps1

$user에 대한 줄 아래 에 다양한 변형을 던지려고 했지만 $Time = $eventXML.event.System.TimeCreatedSystemTime운이 없었으며 이 정보를 추가하는 방법을 잘 모르겠습니다. 또한 $Row.User = $User 아래에 다음을 추가했습니다.

$Row.Time = $Time





 # Prepare Variables
    Param (
            [parameter(Mandatory=$false,Position=0)][String]$ComputerName = "localhost",
            [parameter(Mandatory=$false,Position=1)][Int]$Hours = 24)

    # Create an Array to hold our returnedvValues
    $InsecureLDAPBinds = @()

    # Grab the appropriate event entries
    $Events = Get-WinEvent -ComputerName $ComputerName -FilterHashtable @{Logname='Directory Service';Id=2889; StartTime=(get-date).AddHours("-$Hours")}

    # Loop through each event and output the 
    ForEach ($Event in $Events) { 
        $eventXML = [xml]$Event.ToXml()

        # Build Our Values
        $Client = ($eventXML.event.EventData.Data[0])
        $IPAddress = $Client.SubString(0,$Client.LastIndexOf(":")) #Accomodates for IPV6 Addresses
        $Port = $Client.SubString($Client.LastIndexOf(":")+1) #Accomodates for IPV6 Addresses
        $User = $eventXML.event.EventData.Data[1]
        Switch ($eventXML.event.EventData.Data[2])
            {
            0 {$BindType = "Unsigned"}
            1 {$BindType = "Simple"}
            }

        # Add Them To a Row in our Array
        $Row = "" | select IPAddress,Port,User,BindType
        $Row.IPAddress = $IPAddress
        $Row.Port = $Port
        $Row.User = $User
        $Row.BindType = $BindType

        # Add the row to our Array
        $InsecureLDAPBinds += $Row
    }
    # Dump it all out to a CSV.
    Write-Host $InsecureLDAPBinds.Count "records saved to .\InsecureLDAPBinds.csv for Domain Controller" $ComputerName
    $InsecureLDAPBinds | Export-CSV -NoTypeInformation .\InsecureLDAPBinds.csv

답변1

XML을 구문 분석하지 않고도 이벤트 자체에서 가져올 수 있습니다.

$Time = $Event.TimeCreated

관련 정보