Hello,
I'm trying to write a mutation to describe a service name based on the port given. Suricata is feeding the data to logstash, and it currently doesn't have a very good way of describing services unless it's in the predefined list. I'd like to still have that information available instead of getting nothing or getting a "failed" entry.
<snip>
# Is app_proto set or failed?
if ![app_proto] or [app_proto] == "failed" {
if [src_port] and [dest_port] {
# Set variable
if [src_port] < [dest_port] {
mutate { add_field => { "[@metadata][port]" => "%{src_port}" } }
}
else if [dest_port] < [src_port] {
mutate { add_field => { "[@metadata][port]" => "%{dest_port}" } }
}
# FTP
if [@metadata][port] == "20" or [@metadata][port] == "21" {
mutate { replace => { "app_proto" => "ftp(%{[@metadata][port]})" } }
}
# SSH
else if [@metadata][port] == "22" {
mutate { replace => { "app_proto" => "ssh(%{[@metadata][port]})" } }
}
# Telnet
else if [@metadata][port] == "23" {
mutate { replace => { "app_proto" => "telnet(%{[@metadata][port]})" } }
}
<snip>
Do I have to do a separate check for whether [app_proto]
is set? I'm using replace
currently, but I'm not sure if it will create the [app_proto]
field if it doesn't already exist. Otherwise, I think I'll have to remove_field
first, then add_field
.