Getting Data In

import csv file and only store diffs from last import of same file (autoruns data)

johnmccash
Explorer

I'm interested in storing csv output from the sysinternals autoruns tool in Splunk. But I will be pulling in from a rather large number of hosts, and most of the data will be the same from dump to dump. What I'm really interested in are the additions, removals, and changes. Is there any way to import the csv but have Splunk only record lines that are added, removed, or changed, from the last time the autoruns dump from a particular system was imported?

Tags (4)
0 Karma

mhorch
New Member

This is what i use for my threat hunting.

<#
Collect AutoRuns Records
This script is used to gather autoruns data for threat hunting.

>

.\autorunsc64.exe -accepteula -a * -s -h -m -ct -nobanner > autoruns.csv

$directory = "C:\"
$x1 = Get-ChildItem -File autoruns.csv -ErrorAction SilentlyContinue | select Name, FullName

$csvExportPath = Join-Path $directory $x1.Name
$createCSV = "$csvExportPath"+".csv"
$renamedReferenceCSV = "$directory"+"ReferenceAutoRuns.csv"
$renamedDifferenceCSV = "$directory"+"DifferenceAutoRuns.csv"
$deltaFile = "$directory"+"DeltaAutoRuns.csv"

if (!(Test-Path $renamedReferenceCSV)){Rename-Item $x1.FullName -NewName "ReferenceAutoRuns.csv"
Copy-Item $renamedReferenceCSV -Destination $deltaFile

}else{

if (!(Test-Path $renamedDifferenceCSV) -and (Test-Path $renamedReferenceCSV)){Rename-Item $x1.FullName -NewName "DifferenceAutoRuns.csv"

if ((Test-Path $renamedReferenceCSV) -and (Test-Path $renamedDifferenceCSV))
{
$importReferenceCSV = Import-Csv -Delimiter "t" $renamedReferenceCSV -ErrorAction SilentlyContinue
$importDifferenceCSV = Import-Csv -Delimiter "
t" $renamedDifferenceCSV -ErrorAction SilentlyContinue

Compare-Object -ReferenceObject $importReferenceCSV -DifferenceObject $importDifferenceCSV |
Select-Object -ExpandProperty InputObject|
Export-Csv $deltaFile -NoTypeInformation
Start-Sleep 10
#Clean Up Old Files
Remove-Item $renamedDifferenceCSV

}

}
}

0 Karma

johnmccash
Explorer

Surely somebody out there has done this? It's a perfectly reasonable use case...
John

0 Karma

johnmccash
Explorer

Just freshening this up, so maybe somebody will answer it...

0 Karma

renjith_nair
Legend

http://stackoverflow.com/questions/11108667/comparing-two-csv-files-and-getting-difference

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

somesoni2
Revered Legend

You can write a script which will compare last two dump file (csv) from the host and log the changes. I believe there should be scripts like this already available on web.

johnmccash
Explorer

Can you point me to one? I did look, but haven't found anything.
Thanks

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...