Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate more ECS fields in the Suricata module #10006

Merged
merged 17 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 118 additions & 9 deletions x-pack/filebeat/module/suricata/eve/ingest/pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,58 @@
,"ignore_missing": true
}
}
, {"lowercase":
{"field": "suricata.eve.http.http_method"
,"target_field": "http.request.method"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.http.http_method"
,"target_field": "http.request.method"
{"field": "suricata.eve.http.status"
,"target_field": "http.response.status_code"
,"type": "string"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.http.status"
,"target_field": "http.response.status_code"
{"field": "suricata.eve.http.hostname"
,"target_field": "url.domain"
,"type": "string"
,"ignore_missing": true
}
}
, { "grok":
{ "field": "suricata.eve.http.url"
, "patterns": ["%{PATH:url.path}(?:\\?%{QUERY:url.query})?(?:#%{ANY:url.fragment})?"]
, "ignore_missing": true
, "pattern_definitions":
{ "PATH": "[^?#]*"
, "QUERY": "[^#]*"
, "ANY": ".*"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for moving to grok here ❤️ The golden files haven't been re-generated, so it's hard to validate. It's also why CI is failing right now :-)

}
}
, {"convert":
{"field": "suricata.eve.http.hostname"
,"target_field": "url.hostname"
,"target_field": "destination.domain"
,"type": "string"
,"ignore_missing": true
}
}
, {"convert":
webmat marked this conversation as resolved.
Show resolved Hide resolved
{"field": "suricata.eve.http.http_refer"
webmat marked this conversation as resolved.
Show resolved Hide resolved
,"target_field": "http.request.referrer"
,"type": "string"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.http.length"
,"target_field": "http.response.body.bytes"
,"type": "integer"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.fileinfo.filename"
,"target_field": "file.path"
Expand Down Expand Up @@ -85,15 +116,93 @@

, { "lowercase":
{ "field": "suricata.eve.event_type"
, "target_field": "event.type"
, "ignore_missing": true
}
}
, { "set":
{ "field": "event.type"
, "value": "{{suricata.eve.event_type}}"
, {"convert":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need type conversion? Otherwise we could just use the rename processor: https://www.elastic.co/guide/en/elasticsearch/reference/current/rename-processor.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I wonder why it was done this way. Did I do it this way initially? (If so, I'm sorry, this was my very first module LOL)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, it just occurred to me that this was the simplest way to copy the data out (instead of renaming).

We had decided that since Suricata had a JSON format which is already very familiar to people, we would start for now by leaving the full untouched event in place, and only copy out data, instead of renaming the fields.

This is different from most modules, but most modules have field names determined by the grok patterns (us), not determined by the tool creator (and familiar to the tool's community).

(My first coffee just kicked in, haha)

Copy link
Contributor Author

@adriansr adriansr Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Back in the day convert was the only way we found to copy a field and failing silently if the source field doesn't exist.

That, or an ugly gigantic piece of painless.

Original discussion: #8550 (comment)

{"field": "suricata.eve.alert.category"
,"target_field": "message"
,"type": "string"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.alert.action"
,"target_field": "event.outcome"
,"type": "string"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.alert.severity"
,"target_field": "event.severity"
,"type": "integer"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.flow.pkts_toclient"
,"target_field": "destination.packets"
,"type": "integer"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.flow.pkts_toserver"
,"target_field": "source.packets"
,"type": "integer"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.flow.bytes_toclient"
,"target_field": "destination.bytes"
,"type": "integer"
,"ignore_missing": true
}
}
, {"convert":
{"field": "suricata.eve.flow.bytes_toserver"
,"target_field": "source.bytes"
,"type": "integer"
,"ignore_missing": true
}
}
, { "script":
{ "lang": "painless"
, "source": "long getOrZero(def map, def key) { if(map!=null && map[key]!=null) { return map[key]; } return 0; } def network=ctx['network'], source=ctx['source'], dest=ctx['destination']; def sp=getOrZero(source,'packets'), sb=getOrZero(source,'bytes'), dp=getOrZero(dest,'packets'), db=getOrZero(dest,'bytes'); if(sb+db+sp+dp > 0){if (network==null){network=new HashMap(); ctx['network']=network; } if(sb+db>0) network['bytes'] = sb+db; if(sp+dp>0) network['packets'] = sp+dp; }"
}
}
, {"date":
{"field": "suricata.eve.flow.start"
,"target_field": "event.start"
,"formats": ["ISO8601"]
,"ignore_failure": true
}
}
, {"set":
{"field": "event.end"
,"value": "{{@timestamp}}"
}
}
, { "script":
{ "lang": "painless"
, "source": "Instant ins(def d){try{return Instant.parse(d);}catch(Exception e){return null;}}def ev=ctx['event'];if(ev!=null){def start=ins(ev['start']); def end=ins(ev['end']); if(start!=null && end!=null && !start.isAfter(end)) {ev['duration'] = Duration.between(start,end).toNanos();}}"
}
}
, { "lowercase":
{ "field": "suricata.eve.proto"
, "target_field": "network.transport"
, "ignore_missing": true
}
}
, { "lowercase":
{ "field": "suricata.eve.app_proto"
, "target_field": "network.protocol"
, "ignore_missing": true
}
}

, { "user_agent":
{ "field": "user_agent.original"
, "target_field": "user_agent"
Expand Down
Loading