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

Command injection vulnerability #692

Open
svandezande opened this issue Jul 22, 2024 · 2 comments
Open

Command injection vulnerability #692

svandezande opened this issue Jul 22, 2024 · 2 comments

Comments

@svandezande
Copy link

svandezande commented Jul 22, 2024

When using pass-arguments-to-command you can inject arbitrary commands into the payload and they will be executed.

Hook definition:

- id: my_hook
  execute-command: "/my_script.sh"
  http-methods:
    - POST
  pass-arguments-to-command:
    - source: payload
      name: prefix
curl -d "prefix=dummy$(touch ~/my_test_file)" -X POST http://localhost:9000/hooks/my_hook

Running this curl command causes ~/my_test_file to be created.

@hnutank163
Copy link

hnutank163 commented Jul 23, 2024

You mentioned potential shell injection in the prefix parameter. To mitigate this risk, you can use regex to validate the prefix parameter. The webhook documentation provides a way to use regex for parameter validation, which can help ensure that the prefix parameter conforms to expected patterns and reduces the risk of injection attacks.

Using Regex to Validate the prefix Parameter
You can use the match regex rule to validate the prefix parameter in your webhook configuration. For example, if you want the prefix parameter to only contain alphanumeric characters, you can use the following configuration:

{
  "match": {
    "type": "regex",
    "regex": "^[a-zA-Z0-9]+$",
    "parameter": {
      "source": "payload",
      "name": "prefix"
    }
  }
}

@svandezande
Copy link
Author

On further testing, I realized this probably isn't as serious as I thought - the $() injection was happening on my command line when issuing the curl command. If I escape the $ so it is passed in the payload, it doesn't seem to get executed when the hook executes the script. Per your suggestion, I've added regex rules to exclude payloads with special characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants