1 of 71

DETECTION AS CODE BUZZWORDOr PANACEA?

Daniel Wyleczuk-Stern

2 of 71

Demo

Detection as Code

Is It Right For You?

Getting Started

01.

Maturity Levels

Resources Necessary

02.

03.

04.

05.

06.

Table of contents

3 of 71

get-caller-identity

Current: Threat Detection @ Snowflake

Past: Offensive Security @ Praetorian, US Air Force

Enjoys: Computers, Coffee, Cats

4 of 71

Key Takeaways

  1. Detection as Code is not binary

  • Understand what getting better looks like�
  • Weighing benefits against costs can help determine the level of maturity needed for your organization

5 of 71

Detection as Code

01.

6 of 71

What does chatGPT say?

“Detection as Code (DaC) is a paradigm … which emphasizes the use of code and automation to manage various aspects of software development and infrastructure.��In the context of security, Detection as Code involves writing, storing, and versioning detection rules, policies, and configurations as code.”

7 of 71

DaC Example

8 of 71

Maturity Levels

02.

9 of 71

Four Levels

Ad-Hoc

Structured

Automated

Optimized

10 of 71

Functional Areas

Language

Testing

Integration & Automation

Monitoring

Ability to query external systems to improve detection quality

Some languages offer more features at the expense of complexity

Ad hoc testing to fully automated unit and integration testing

Keeping tabs on health and stability of systems is important as complexity grows

11 of 71

Matrix

Language

Testing

Integration

Monitoring

Ad-hoc

Structured

Automated

Optimized

12 of 71

Language Examples

YAML

Functional Languages

Query Languages

13 of 71

YAML

Limited expressiveness

Designed to be human readable

https://github.com/SigmaHQ/sigma/blob/master/rules/cloud/aws/aws_config_disable_recording.yml

14 of 71

Query Language

Optimized for databases, improved performance

SPL, SQL, etc

https://github.com/splunk/security_content/blob/develop/detections/cloud/aws_iam_successful_group_deletion.yml

15 of 71

Functional Language

Rich libraries, integrations with other languages

More flexible and supports complex logic

https://github.com/panther-labs/panther-analysis/blob/master/rules/cloudflare_rules/cloudflare_firewall_high_volume_events_blocked_greynoise.py

16 of 71

Matrix

Language

Testing

Integration

Monitoring

Ad-hoc

YAML

Structured

Query language

Automated

Functional language

Optimized

All of the above

17 of 71

Types of Testing

Checks for code quality

Unit Testing

Ensure detection logic is correct

Performance

Queries and rules run in time

Linting

Integration

Systems working together

End-to-End

Data generation => Case management

18 of 71

Unit Testing

https://github.com/panther-labs/panther-analysis/blob/master/rules/aws_cloudtrail_rules/aws_cloudtrail_account_discovery.yml

19 of 71

Linting

https://plainenglish.io/blog/how-to-lint-properly-your-sql-code-5ae21e6f9f5c

20 of 71

End-to-End Testing

https://github.com/WithSecureLabs/leonidas

21 of 71

Automate Your Testing

https://binary-studio.com/blog/2021/12/21/lint-your-project-with-github-actions/

CI/CD systems can run tests on code changes

22 of 71

Testing Priority and Difficulty

Unit Testing

End-to-End

Performance

Integration

Linting

Priority Difficulty

Priority Difficulty

Priority Difficulty

Priority Difficulty

Priority Difficulty

23 of 71

Matrix

Language

Testing

Integration

Monitoring

Ad-hoc

YAML

No or minimal testing

Structured

Query language

Some testing in all areas or strong testing in some areas but missing in others

Automated

Functional language

Some testing in all areas with strong capabilities in a few categories. Sandbox/dev environment

Optimized

All of the above

Testing for all components with code coverage measurements. Tests required for new detections

24 of 71

Automation and Integration to Decrease Analyst Friction

Anytime your SOC has to context switch, go into another system for information, or look something up, it increases time to respond and adds unnecessary friction

25 of 71

Categories of Integrations

Generate an Alert

Suppress an Alert

Enrich an Alert

Retrieve data from external system to generate an alert

Query an external system gather data to suppress an alert

Automate collection of information to improve the triage experience

26 of 71

Suppression

“Was this you?”

https://www.tines.com/blog/chatbots-for-security-and-it-teams-part-3-creating-a-slack-chatbot

A classic example of automating a manual process

27 of 71

Enrichment

CloudTrail Removed Data

https://hackingthe.cloud/aws/exploitation/local-priv-esc-mod-instance-att/

Detection for potentially malicious code

28 of 71

Manual Query

29 of 71

Automating this Process Vastly Speeds Up Triage

30 of 71

Matrix

Language

Testing

Integration

Monitoring

Ad-hoc

YAML

No or minimal testing

No or minimal integrations

Structured

Query language

Some testing in all areas or strong testing in some areas but missing in others

Some integrations setup, setting up new integrations is high effort

Automated

Functional language

Some testing in all areas with strong capabilities in a few categories. Sandbox/dev environment

Process for developing new integrations, can automate suppression/enrichment for key detections

Optimized

All of the above

Testing for all components with code coverage measurements. Tests required for new detections

Integrations for suppression, enrichment. Can deploy new integrations easily

31 of 71

Monitoring

As our systems grow in complexity, it becomes increasingly important to monitor their inputs, activity, and outputs

https://www.datadoghq.com/dashboards/elb-dashboard/

32 of 71

Categories of Monitoring

Input

Execution

Outputs

Performance monitoring,�query failures

Data quality

False positive monitoring, �alert volume

33 of 71

Data Quality

Spikes / Drops

Format

Parseable

Completeness

System Coverage

Volume

Timing

Mean Time to Respond

Data Contracts

SLAs/SLOs

34 of 71

Execution

Performance/Cost

Failure Handling

Discovering a cost spike when the bill arrives is like finding out about a speed bump when you're already airborne

Can you monitor for system failures? Can you recover (re-run detections) when that happens?

35 of 71

Outputs

36 of 71

Matrix

Language

Testing

Integration

Monitoring

Ad-hoc

YAML

No or minimal testing

No or minimal integrations

Get told by SOC. Find data outages during IR

Structured

Query language

Some testing in all areas or strong testing in some areas but missing in others

Some integrations setup, setting up new integrations is high effort

Dashboards and visualizations

Automated

Functional language

Some testing in all areas with strong capabilities in a few categories. Sandbox/dev environment

Process for developing new integrations, can automate suppression/enrichment for key detections

Notifications, SLAs/SLOS

Optimized

All of the above

Testing for all components with code coverage measurements. Tests required for new detections

Integrations for suppression, enrichment. Can deploy new integrations easily

Automated suppressions, data contracts, automatic recovery

37 of 71

Resources Necessary

03.

38 of 71

Cost / Benefit

Cost

Benefit

Do you have the resources to be successful?

Does your organization need the benefits of Detection as Code?

39 of 71

Would You Benefit?

Prioritized Risks

Evolving Threats

In-House

Dynamic Environment

Do you have requirements forcing in-house development?

Does your organization face unique risks and can you prioritize them?

Are the threats facing your organization changing?

Is the environment your securing very dynamic or more static?

40 of 71

Weighing the Costs

Infrastructure

Talent

Priorities

Buying and maintaining new systems

Hiring/training security engineers who can code

New projects means something else doesn’t get done

41 of 71

Is It Right for You?

04.

42 of 71

Is It Worth It?

43 of 71

Example 1

Startup

3 total employees in security organization

Has EDR, SIEM

44 of 71

Example 1

Startup

3 total employees in security organization

Has EDR, SIEM

45 of 71

Example 2

Large multinational

SOC split into multiple teams

Hundreds of custom rules

46 of 71

Example 2

Large multinational

SOC split into multiple teams

Hundreds of custom rules

47 of 71

Example 3

Regulated financial company

15 person security team

Robust threat intelligence program

48 of 71

Example 3

Regulated financial company

15 person security team

Robust threat intelligence program

49 of 71

Startup

Language

Testing

Integration

Monitoring

Ad-hoc

YAML

No or minimal testing

No or minimal integrations

Get told by SOC. Find data outages during IR

Structured

Query language

Some testing in all areas or strong testing in some areas but missing in others

Some integrations setup, setting up new integrations is high effort

Dashboards and visualizations

Automated

Functional language

Some testing in all areas with strong capabilities in a few categories. Sandbox/dev environment

Process for developing new integrations, can automate suppression/enrichment for key detections

Notifications, SLAs/SLOS

Optimized

All of the above

Testing for all components with code coverage measurements. Tests required for new detections

Integrations for suppression, enrichment. Can deploy new integrations easily

Automated suppressions, data contracts

50 of 71

Financial institution

Language

Testing

Integration

Monitoring

Ad-hoc

YAML

No or minimal testing

No or minimal integrations

Get told by SOC. Find data outages during IR

Structured

Query language

Some testing in all areas or strong testing in some areas but missing in others

Some integrations setup, setting up new integrations is high effort

Dashboards and visualizations

Automated

Functional language

Some testing in all areas with strong capabilities in a few categories. Sandbox/dev environment

Process for developing new integrations, can automate suppression/enrichment for key detections

Notifications, SLAs/SLOS

Optimized

All of the above

Testing for all components with code coverage measurements. Tests required for new detections

Integrations for suppression, enrichment. Can deploy new integrations easily

Automated suppressions, data contracts

51 of 71

MSSP

Language

Testing

Integration

Monitoring

Ad-hoc

YAML

No or minimal testing

No or minimal integrations

Get told by SOC. Find data outages during IR

Structured

Query language

Some testing in all areas or strong testing in some areas but missing in others

Some integrations setup, setting up new integrations is high effort

Dashboards and visualizations

Automated

Functional language

Some testing in all areas with strong capabilities in a few categories. Sandbox/dev environment

Process for developing new integrations, can automate suppression/enrichment for key detections

Notifications, SLAs/SLOS

Optimized

All of the above

Testing for all components with code coverage measurements. Tests required for new detections

Integrations for suppression, enrichment. Can deploy new integrations easily

Automated suppressions, data contracts

52 of 71

Getting Started

05.

53 of 71

Key Components

Rules Engine

Source Code Repository

Automation

Panther, Elastic, Splunk, Azure Sentinel, etc

GitHub, GitLab

Jenkins, CircleCI, GitHub Actions, etc

54 of 71

Matrix

Language

Testing

Integration

Monitoring

Ad-hoc

YAML

No or minimal testing

No or minimal integrations

Get told by SOC. Find data outages during IR

Structured

Query language

Some testing in all areas or strong testing in some areas but missing in others

Some integrations setup, setting up new integrations is high effort

Dashboards and visualizations

Automated

Functional language

Some testing in all areas with strong capabilities in a few categories. Sandbox/dev environment

Process for developing new integrations, can automate suppression/enrichment for key detections

Notifications, SLAs/SLOS

Optimized

All of the above

Testing for all components with code coverage measurements. Tests required for new detections

Integrations for suppression, enrichment. Can deploy new integrations easily

Automated suppressions, data contracts

55 of 71

Choosing an Area and Level to Focus on First

Questions to Consider

How to Answer Them

  • Improve audability?
  • Write more complex detections?
  • Improve quality through testing?
  • Look through old cases
  • Talk to SOC
  • Penetration test/incident reports

56 of 71

Demo

57 of 71

Matrix

Language

Testing

Integration

Monitoring

Ad-hoc

YAML

No or minimal testing

No or minimal integrations

Get told by SOC. Find data outages during IR

Structured

Query language

Some testing in all areas or strong testing in some areas but missing in others

Some integrations setup, setting up new integrations is high effort

Dashboards and visualizations

Automated

Functional language

Some testing in all areas with strong capabilities in a few categories. Sandbox/dev environment

Process for developing new integrations, can automate suppression/enrichment for key detections

Notifications, SLAs/SLOS

Optimized

All of the above

Testing for all components with code coverage measurements. Tests required for new detections

Integrations for suppression, enrichment. Can deploy new integrations easily

Automated suppressions, data contracts

58 of 71

Root account usage

MITRE ATT&CK T1078.004��https://docs.aws.amazon.com/accounts/latest/reference/best-practices-root-user.html

59 of 71

Old Alert Flow

If we see root usage - generate an alert��High friction for analyst as they track down potentially legitimate usage

60 of 71

Triage & Feedback

Questions to Consider

How to Answer Them

61 of 71

Automatic Ticket Creation

Speeds up improvement process

Populate tickets with all the information engineers need to begin work��Can track SLOs for fixes

62 of 71

Dashboards

Frequent Issues Show Automation is Necessary

63 of 71

Set-up Integration with Deployment Scripts

Pull host and automation information and send to a webhook

64 of 71

Before

Only query CloudTrail

65 of 71

Code Change

Correlate events with data from automation scripts

66 of 71

Historical Testing

Run detection logic against previously collected data to validate the fix works

67 of 71

Live Testing

68 of 71

Merge After Approval and Tests Pass

Templates help guide development and approval process

Change approved and merged once tests pass and proof of testing was submitted

69 of 71

New Flow

  1. Integrations supported quick feedback
  2. Monitoring drove decision for larger update
  3. Easily setup integration for improved enrichment
  4. Testing frameworks provided evidence change would work
  5. Automated tests helped with error checking
  6. Code repositories supported peer review, validation, and auditing

70 of 71

Thank you!

Do you have any questions?

https://www.linkedin.com/in/danielwyleczukstern/

Please keep this slide for attribution

CREDITS: This presentation template was created by Slidesgo, and includes icons by Flaticon, and infographics and images by Freepik

71 of 71

Cat Pic