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

[Security Solution] webhook action can sends invalid json payload when combined with mustache #88893

Closed
LouDeter opened this issue Jan 20, 2021 · 3 comments
Labels
bug Fixes for quality problems that affect the customer experience Feature:Alerting fixed impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc.

Comments

@LouDeter
Copy link

LouDeter commented Jan 20, 2021

Describe the bug:
We can use webhook, in the action section of a detection rule to send a JSON to another service. In the body of the action we can use mustache to render some context information like the query that matched some logs and generated the alert.
If the query contains a \ for exemple CommandLine:*process\ call* then mustach will render the variable "as is" but it creates an invalid JSON.

Kibana/Elasticsearch Stack version:
v 7.10.0

Server OS version:
Debian GNU/Linux 9 (stretch)

Browser and Browser OS versions:
Firefox 84.0.2 (64 bits)

Elastic Endpoint version:
N/A

Original install method (e.g. download page, yum, from source, etc.):
deb package

Functional Area (e.g. Endpoint management, timelines, resolver, etc.):
SIEM/detection rule

Steps to reproduce:

  1. Create a webhook that will be listend by netcat
  2. Create a new detection rule from app/security/detections/rules/create
  3. Use the search CommandLine:*process\ call* and fill other fields with any value
  4. In the Action tab, select the created webhook and fill the following body {"description": "{{context.rule.query}}"}
  5. Have a document that match the alert like {"CommandLine": "wmic process call create cmd"}
  6. Go to your netcat listener and see the request sent:
POST /api/alert HTTP/1.1
Accept: application/json, text/plain, */*
Content-Type: application/json
User-Agent: axios/0.19.2
Content-Length: 725
Host: <removed>:9000
Connection: close

{
"description": "CommandLine:*process\ call*"
}
  1. Consider that the logic is right but the json is malformed because in a json string, spaces can't be escaped https://www.json.org/img/string.png
  2. Try to parse the json with any json parser and it will fail

Current behavior:
Sends an invalid JSON document

Expected behavior:
results of Mustach should be "JSON dumped"

Screenshots (if relevant):

Errors in browser console (if relevant):

Provide logs and/or server output (if relevant):

Any additional context (logs, chat logs, magical formulas, etc.):

@LouDeter LouDeter added Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. bug Fixes for quality problems that affect the customer experience labels Jan 20, 2021
@MadameSheema MadameSheema added Team:Detections and Resp Security Detection Response Team impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. labels Jan 21, 2021
@MadameSheema
Copy link
Member

@mikecote can you please take a look to this issue? Lots of thanks :)

@mikecote
Copy link
Contributor

mikecote commented Feb 3, 2021

cc @elastic/kibana-alerting-services

@MadameSheema Thanks for the ping. @pmuellr, I believe you have encountered this in SDHs before, and a fix in 7.11 is merged?

@pmuellr
Copy link
Member

pmuellr commented Feb 4, 2021

Yes, this should be fixed in 7.11 via #83919

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Alerting fixed impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc.
Projects
None yet
Development

No branches or pull requests

5 participants