Giter Site home page Giter Site logo

datadog / threatest Goto Github PK

View Code? Open in Web Editor NEW
309.0 13.0 26.0 390 KB

Threatest is a CLI and Go framework for end-to-end testing threat detection rules.

Home Page: https://securitylabs.datadoghq.com/articles/threatest-end-to-end-testing-threat-detection/

License: Apache License 2.0

Go 94.18% Makefile 2.03% Dockerfile 1.02% Ruby 2.77%
continuous-security detection-engineering security-automation threat-detection

threatest's Introduction

Threatest

unit tests static analysis

Threatest

Threatest is a CLI and Go framework for testing threat detection end-to-end.

Threatest allows you to detonate an attack technique, and verify that the alert you expect was generated in your favorite security platform.

Read the announcement blog post: https://securitylabs.datadoghq.com/articles/threatest-end-to-end-testing-threat-detection/

Concepts

Detonators

A detonator describes how and where an attack technique is executed.

Supported detonators:

  • Local command execution
  • SSH command execution
  • Stratus Red Team
  • AWS CLI detonator
  • AWS detonator (programmatic only, does not work with the CLI)

Alert matchers

An alert matcher is a platform-specific integration that can check if an expected alert was triggered.

Supported alert matchers:

  • Datadog security signals

Detonation and alert correlation

Each detonation is assigned a UUID. This UUID is reflected in the detonation and used to ensure that the matched alert corresponds exactly to this detonation.

The way this is done depends on the detonator; for instance, Stratus Red Team and the AWS Detonator inject it in the user-agent; the SSH detonator uses a parent process containing the UUID.

Usage

Through the CLI

Threatest comes with a CLI that you can use to run test scenarios described as YAML, following a specific schema. You can configure this schema in your editor to benefit from in-IDE linting and autocompletion (see documentation for VSCode using the YAML extension).

Install the CLI by downloading a binary release or with Homebrew:

brew tap datadog/threatest https://github.com/datadog/threatest
brew install datadog/threatest/threatest

Sample usage:

$ threatest lint scenarios.threatest.yaml
All 6 scenarios are syntaxically valid

# Local detonation
$ threatest run local-scenarios.threatest.yaml

# Remote detonation over SSH
$ threatest run scenarios.threatest.yaml --ssh-host test-box --ssh-username vagrant

# Alternatively, specify SSH parameters from environment variables
$ export THREATEST_SSH_HOST=test-box
$ export THREATEST_SSH_USERNAME=vagrant
$ threatest run scenarios.threatest.yaml

Sample scenario definition files

  • Detonating over SSH
scenarios:
  # Remote detonation over SSH
  # Note: SSH configuration is provided using the --ssh-host, --ssh-username and --ssh-keyfile CLI arguments
  - name: curl metadata service
    detonate:
      remoteDetonator:
        commands: ["curl http://169.254.169.254 --connect-timeout 1"]
    expectations:
      - timeout: 1m
        datadogSecuritySignal:
          name: "Network utility accessed cloud metadata service"
          severity: medium
  • Detonating using Stratus Red Team
scenarios:
  # Stratus Red Team detonation
  # Note: You must be authenticated to the relevant cloud provider before running it
  # The example below is equivalent to manually running "stratus detonate aws.exfiltration.ec2-security-group-open-port-22-ingress"
  - name: opening a security group to the Internet
    detonate:
      stratusRedTeamDetonator:
        attackTechnique: aws.exfiltration.ec2-security-group-open-port-22-ingress
    expectations:
      - timeout: 15m
        datadogSecuritySignal:
          name: "Potential administrative port open to the world via AWS security group"
  • Detonating using AWS CLI commands
scenarios:
  # AWS CLI detonation
  # Note: You must be authenticated to AWS before running it and have the AWS CLI installed
  - name: opening a security group to the Internet
    detonate:
      awsCliDetonator:
        script: |
          set -e
          
          # Setup
          vpc=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --query Vpc.VpcId --output text)
          sg=$(aws ec2 create-security-group --group-name sample-sg --description "Test security group" --vpc-id $vpc --query GroupId --output text)
          
          # Open security group
          aws ec2 authorize-security-group-ingress --group-id $sg --protocol tcp --port 22 --cidr 0.0.0.0/0
          
          # Cleanup
          aws ec2 delete-security-group --group-id $sg
          aws ec2 delete-vpc --vpc-id $vpc
    expectations:
      - timeout: 15m
        datadogSecuritySignal:
          name: "Potential administrative port open to the world via AWS security group"

You can output the test results to a JSON file:

$ threatest run scenarios.threatest.yaml --output test-results.json
$ cat test-results.json
[
  {
    "description": "change user password",
    "isSuccess": true,
    "errorMessage": "",
    "durationSeconds": 22.046627348,
    "timeDetonated": "2022-11-15T22:26:14.182844+01:00"
  },
  {
    "description": "adding an SSH key",
    "isSuccess": true,
    "errorMessage": "",
    "durationSeconds": 23.604699625,
    "timeDetonated": "2022-11-15T22:26:14.182832+01:00"
  },
  {
    "description": "change user password",
    "isSuccess": false,
    "errorMessage": "At least one scenario failed:\n\nchange user password returned: change user password: 1 assertions did not pass\n =\u003e Did not find Datadog security signal 'bar'\n",
    "durationSeconds": 3.505294235,
    "timeDetonated": "2022-11-15T22:26:36.229349+01:00"
  }
]

By default, scenarios are run with a maximum parallelism of 5. You can increase this setting using the --parallelism argument. Note that when using remote SSH detonators, each scenario running establishes a new SSH connection.

Using Threatest programmatically

See examples for complete programmatic usage example.

Testing Datadog Cloud SIEM signals triggered by Stratus Red Team

threatest := Threatest()

threatest.Scenario("AWS console login").
  WhenDetonating(StratusRedTeamTechnique("aws.initial-access.console-login-without-mfa")).
  Expect(DatadogSecuritySignal("AWS Console login without MFA").WithSeverity("medium")).
  WithTimeout(15 * time.Minute)

assert.NoError(t, threatest.Run())

Testing Datadog Cloud Workload Security signals triggered by running commands over SSH

ssh, _ := NewSSHCommandExecutor("test-box", "", "")

threatest := Threatest()

threatest.Scenario("curl to metadata service").
  WhenDetonating(NewCommandDetonator(ssh, "curl http://169.254.169.254 --connect-timeout 1")).
  Expect(DatadogSecuritySignal("EC2 Instance Metadata Service Accessed via Network Utility"))

assert.NoError(t, threatest.Run())

threatest's People

Contributors

christophetd avatar dependabot[bot] avatar evanj avatar goreleaserbot avatar martinvoigt-dd avatar will-giraldo-d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

threatest's Issues

Alert Matching with Elastic

Hi guys! Love the project as is, if it didn't already exist we were liable to build something similar. We'd love to discuss adding an integration for alert matching with Elastic, and Kubernetes detonators (will make a separate issue for the latter).

Earliest we (Thought Machine) are likely to be in a position to give this serious attention (if you guys are game) is Q1 2024. With that said we'd like to know two things:

  1. What's in your immediate roadmap for the tool? Ie. is it liable to shift dramatically in such a way that it no longer makes sense for us to use it?
  2. Does adding support for Elastic align with your vision for this project? Your introductory blog post suggests it does, but would like to confirm since that was some time ago (Aug 2022).

Kubernetes Detonators

These got a mention in the original blog post associated with this project. As far as I'm aware a detonator does not currently exist for this, and it doesn't really seem like it's in scope of the offering of the stratus-red-team or the go-atomicredteam detonators.

I for one would love to see this made a reality, is it anywhere on any existing roadmap? If not could potentially contribute towards this in the coming year.

Add an Atomic Red Team detonator

Possible implementation:

  • In the local/remote command detonators, offer a field atomicRedTeam with the necessary configuration
  • This would allow maximum code reuse and avoid duplication of the logic to run commands locally/remotely

Unsure how we'd need to manage Atomic Red Team TTPs pre-requisites or clean-up, to be investigated

Terraform detonator

Use-case: People who need custom control-plane level threat detection but don't want to write custom Go code such as

https://github.com/DataDog/threatest/blob/main/examples/custom-aws-detonator-terratest/custom_aws_detonator_with_terratest_test.go#L31-L39

Alternatives:

  • Use something already covered by Stratus Red Team
  • Provide a Terraform script that performs the detonation - in this case, we need to check if (1) Terraform is suitable for the "imperative-style" changes and (2) if we can inject the detonation UUID inside of the Terraform user agent programmatically (which should be able since Stratus Red Team does it...)
  • Provide a Bash script using the AWS CLI that performs the detonation

Use proper logging

We should use log.x instead of fmt.Println, and figure out how to work it out when using go test

installation failed using brew on MacOS platform

What is not working?
Installation using homebrew failed. Not sure whether it's due to the brew or datadog/threatest

What OS are you using?
Mac OS X 13.4.1 (c) (22F770820d) (Apple M1 Pro)

What version of threatest are you using?
NA

Code to reproduce the issue

% brew tap datadog/threatest https://github.com/datadog/threatest
% brew install datadog/threatest/threatest

Full output?

% brew install datadog/threatest/threatest
Error: invalid attribute for formula 'datadog/threatest/threatest': url ("https://github.com/DataDog/threatest/releases/download/v1.2.2/darwin: Darwin threatest_ linux: LinuxDarwin_ windows: Windowsarm64.tar.gz")
Please report this issue:
  https://docs.brew.sh/Troubleshooting
/opt/homebrew/Library/Homebrew/formula.rb:313:in `validate_attributes!'
/opt/homebrew/Library/Homebrew/formula.rb:243:in `initialize'
/opt/homebrew/Library/Homebrew/formulary.rb:484:in `new'
/opt/homebrew/Library/Homebrew/formulary.rb:484:in `get_formula'
/opt/homebrew/Library/Homebrew/formulary.rb:644:in `get_formula'
/opt/homebrew/Library/Homebrew/formulary.rb:761:in `factory'
/opt/homebrew/Library/Homebrew/cli/parser.rb:649:in `block in formulae'
/opt/homebrew/Library/Homebrew/cli/parser.rb:645:in `map'
/opt/homebrew/Library/Homebrew/cli/parser.rb:645:in `formulae'
/opt/homebrew/Library/Homebrew/cli/parser.rb:318:in `parse'
/opt/homebrew/Library/Homebrew/cmd/install.rb:167:in `install'
/opt/homebrew/Library/Homebrew/brew.rb:94:in `<main>'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.