Copy part of a field into new field

Alright, I've got another question is it possible to copy part of one field into another? I.E.
I have
NewProcessName - C:\Windows\SysWOW64\dllhost.exe
I want to move everything after last backslash to new field
SuspProc - dllhost.exe

I have this

filter {
if [event_id] == 4688 {
mutate {
copy => {"[event_data][NewProcessName]" => "[event_data][SuspProc]" }
}
}
}

and I have the regex that will pull what is after the last back slash -
([^\]+)$
and regex that will pull everything before -
/^(.*[\/])/

is there a way to do this with copy? Or would I need to try and use gsub to erase everything before the last backslash?

Thanks!

Use a grok filter. Examples have been posted in the past, though perhaps tailored to paths with forward slashes rather than backslashes.

Hmmm, so why can't I use this?

filter {
grok {
match => [ "[event_data][NewProcessName]", "(?<[event_data][SuspProc]>([^\/]+$))" ]
}
}

NewProcessName - C:\Windows\SysWOW64\dllhost.exe
to create the new field and add what's after the last backslash?
SuspProc - dllhost.exe

this gives me the pipleine terminated error.

Because the syntax is grok { match => { "field" => "pattern" }} not grok { match => [ "field" , "pattern" ]}

This is torture, nothing seems to be working...

filter {
grok {
match => ["[event_data][NewProcessName]", "/(?<SuspProc>([^\\]+)$)"]
}
}
*no pipeline errors but no new SuspProc field


filter {
grok {
match => "[event_data][NewProcessName]", "/(?<SuspProc>([^\\]+)$)"
}
}
*pipeline errors and no new SuspProc field


filter {
grok {
match => {"[event_data][NewProcessName]", "/(?<SuspProc>([^\\]+)$)"}
}
}
*pipeline errors and no new SuspProc field


filter {
grok {
match => ["[event_data.NewProcessName]", "/(?<SuspProc>([^\\]+)$)"]
}
}
*no pipeline errors but no new SuspProc field


filter {
grok {
match => ["[event_data.NewProcessName]" => "/(?<SuspProc>([^\\]+)$)"]
}
}
*pipeline errors and no new SuspProc field


filter {
grok {
match => ["event_data.NewProcessName" , "/(?<SuspProc>([^\\]+)$)"]
}
}
*no pipeline errors but no new SuspProc field


filter {
grok {
match => ["NewProcessName" , "/(?<SuspProc>([^\\]+)$)"]
}
}
*no pipeline errors but no new SuspProc field

event_data.NewProcessName is in Discovery why can't I do this?

Because the syntax is grok { match => { "field" => "pattern" }} not grok { match => [ "field" , "pattern" ]}

Actually, both syntaxes are fine.

Show us an example event. Use a stdout { codec => rubydebug } output.

filter {
grok {
match => ["[event_data][NewProcessName]", "/(?([^\]+)$)"]
}
}

Here is syslog with above, I hope I didn't copy anything in there, I appreciate this @magnusbaeck....

Dec 7 09:58:23 elkstack logstash[31542]: "type" => "wineventlog",
Dec 7 09:58:23 elkstack logstash[31542]: "opcode" => "Info",
Dec 7 09:58:23 elkstack logstash[31542]: "version" => 1,
Dec 7 09:58:23 elkstack logstash[31542]: "tags" => [
Dec 7 09:58:23 elkstack logstash[31542]: [0] "beats_input_codec_plain_applied",
Dec 7 09:58:23 elkstack logstash[31542]: [1] "_grokparsefailure"
Dec 7 09:58:23 elkstack logstash[31542]: ],
Dec 7 09:58:23 elkstack logstash[31542]: "thread_id" => 96,
Dec 7 09:58:23 elkstack logstash[31542]: "@timestamp" => 2017-12-07T14:54:01.283Z,
Dec 7 09:58:23 elkstack logstash[31542]: "event_id" => 4688,
Dec 7 09:58:23 elkstack logstash[31542]: "task" => "Process Creation",
Dec 7 09:58:23 elkstack logstash[31542]: "provider_guid" => "{54849625-5478-4994-A5BA-3E3B0328C30D}",
Dec 7 09:58:23 elkstack logstash[31542]: "@version" => "1",
Dec 7 09:58:23 elkstack logstash[31542]: "beat" => {
Dec 7 09:58:23 elkstack logstash[31542]: "name" => "IBCESCWVPSECFEV",
Dec 7 09:58:23 elkstack logstash[31542]: "hostname" => "IBCESCWVPSECFEV",
Dec 7 09:58:23 elkstack logstash[31542]: "version" => "6.0.0"
Dec 7 09:58:23 elkstack logstash[31542]: },
Dec 7 09:58:23 elkstack logstash[31542]: "host" => "IBCESCWVPSECFEV",
Dec 7 09:58:23 elkstack logstash[31542]: "source_name" => "Microsoft-Windows-Security-Auditing"
Dec 7 09:58:23 elkstack logstash[31542]: }
Dec 7 09:58:23 elkstack logstash[31542]: {
Dec 7 09:58:23 elkstack logstash[31542]: "computer_name" => "XXXXXX",
Dec 7 09:58:23 elkstack logstash[31542]: "process_id" => 4,
Dec 7 09:58:23 elkstack logstash[31542]: "keywords" => [
Dec 7 09:58:23 elkstack logstash[31542]: [0] "Audit Success"
Dec 7 09:58:23 elkstack logstash[31542]: ],
Dec 7 09:58:23 elkstack logstash[31542]: "log_name" => "Security",
Dec 7 09:58:23 elkstack logstash[31542]: "level" => "Information",
Dec 7 09:58:23 elkstack logstash[31542]: "record_number" => "2889961",
Dec 7 09:58:23 elkstack logstash[31542]: "event_data" => {
Dec 7 09:58:23 elkstack logstash[31542]: "SubjectUserName" => "XXXX",
Dec 7 09:58:23 elkstack logstash[31542]: "CommandLine" => ""C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE" SCODEF:8968 CREDAT:3618026 /prefetch:2",
Dec 7 09:58:23 elkstack logstash[31542]: "NewProcessId" => "0x22d4",
Dec 7 09:58:23 elkstack logstash[31542]: "TokenElevationType" => "%%1936",
Dec 7 09:58:23 elkstack logstash[31542]: "SubjectDomainName" => "XXX",
Dec 7 09:58:23 elkstack logstash[31542]: "ProcessId" => "0x2308",
Dec 7 09:58:23 elkstack logstash[31542]: "SubjectLogonId" => "0x32432f13",
Dec 7 09:58:23 elkstack logstash[31542]: "NewProcessName" => "C:\Program Files (x86)\Internet Explorer\iexplore.exe",
Dec 7 09:58:23 elkstack logstash[31542]: "SubjectUserSid" => "S-1-5-21-2907011200-4146745624-917563655-64722"
Dec 7 09:58:23 elkstack logstash[31542]: },
Dec 7 09:58:23 elkstack logstash[31542]: "message" => "A new process has been created.\n\nSubject:\n\tSecurity ID:\t\tS-1-5-21-2907011200-4146745624-917563655-64722\n\tAccount Name:\t\XXXXt\n\tAccount Domain:\t\tXXXX\n\tLogon ID:\t\t0x32432f13\n\nProcess Information:\n\tNew Process ID:\t\t0x22d4\n\tNew Process Name:\tC:\Program Files (x86)\Internet Explorer\iexplore.exe\n\tToken Elevation Type:\tTokenElevationTypeDefault (1)\n\tCreator Process ID:\t0x2308\n\tProcess Command Line:\t"C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE" SCODEF:8968 CREDAT:3618026 /prefetch:2\n\nToken Elevation Type indicates the type of token that was assigned to the new process in accordance with User Account Control policy.\n\nType 1 is a full token with no privileges removed or groups disabled. A full token is only used if User Account Control is disabled or if the user is the built-in Administrator account or a service account.\n\nType 2 is an elevated token with no privileges removed or groups disabled. An elevated token is used when User Account Control is enabled and the user chooses to start the program using Run as administrator. An elevated token is also used when an application is configured to always require administrative privilege or to always require maximum privilege, and the user is a member of the Administrators group.\n\nType 3 is a limited token with administrative privileges removed and administrative groups disabled. The limited token is used when User Account Control is enabled, the application does not require administrative privilege, and the user does not choose to start the program using Run as administrator.",

Is in Disover -
t event_data.NewProcessName C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

Tried this one I found on google from back in 2013 -

filter {
grok { match => [ "NewProcessName", "([^\]+)${event_data:SuspProc}" ] }
}
*no pipeline errors but no SuspProc field either.

Your expression starts with / but you don't have any forward slashes in your file paths. Try \\ instead, or emitting it completely if that doesn't work.

Whew, I appreciate everyone's help with this... I finally just ended up doing this -

filter {
if [event_id] == 4688 {
mutate {
copy => {"[event_data][NewProcessName]" => "[event_data][SuspProc]" }
}
}
}

filter {
if [event_id] == 4688 {
mutate {
gsub => ["[event_data][SuspProc]", "^(.*[\/])", "" ]
}
}
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.