-
Notifications
You must be signed in to change notification settings - Fork 9
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
Rasp command injection tests #3524
Open
NachoEchevarria
wants to merge
15
commits into
main
Choose a base branch
from
nacho/RaspCmdITests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+492
−75
Open
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6a9bf4a
Rasp cmdI system tests
NachoEchevarria 9c3de14
Update _features.py
NachoEchevarria 9c088af
Merge branch 'main' into nacho/RaspCmdITests
NachoEchevarria 967994d
Lint
NachoEchevarria 928b1ba
Merge branch 'nacho/RaspCmdITests' of https://github.com/DataDog/syst…
NachoEchevarria d2c66bd
Fix format
NachoEchevarria 89c9a4c
Format
NachoEchevarria d1156a3
Fix format
NachoEchevarria 90c8c75
Format and order fix
NachoEchevarria e355ef3
Update _features.py
NachoEchevarria e83d446
Waf tests refactor
NachoEchevarria 61bfe12
Fix format
NachoEchevarria fbb430d
Update test_cmdi.py
NachoEchevarria 6cb60d3
set lfi rules version as missing
NachoEchevarria a6ab0de
Merge branch 'main' into nacho/RaspCmdITests
NachoEchevarria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
# Unless explicitly stated otherwise all files in this repository are licensed under the the Apache License Version 2.0. | ||
# This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
# Copyright 2021 Datadog, Inc. | ||
|
||
from utils import features, weblog, interfaces, scenarios, rfc | ||
from utils.dd_constants import Capabilities | ||
from tests.appsec.rasp.utils import ( | ||
validate_span_tags, | ||
validate_stack_traces, | ||
find_series, | ||
validate_metric_variant, | ||
Base_Rules_Version, | ||
) | ||
|
||
|
||
@rfc("https://docs.google.com/document/d/1DDWy3frMXDTAbk-BfnZ1FdRwuPx6Pl7AWyR4zjqRFZw") | ||
@features.rasp_command_injection | ||
@scenarios.appsec_rasp | ||
class Test_Cmdi_UrlQuery: | ||
"""Shell Injection through query parameters""" | ||
|
||
def setup_cmdi_get(self): | ||
self.r = weblog.get("/rasp/cmdi", params={"command": "/bin/evilCommand"}) | ||
|
||
def test_cmdi_get(self): | ||
assert self.r.status_code == 403 | ||
|
||
interfaces.library.assert_rasp_attack( | ||
self.r, | ||
"rasp-932-110", | ||
{ | ||
"resource": {"address": "server.sys.exec.cmd", "value": "/bin/evilCommand",}, | ||
"params": {"address": "server.request.query", "value": "/bin/evilCommand",}, | ||
}, | ||
) | ||
|
||
|
||
@rfc("https://docs.google.com/document/d/1DDWy3frMXDTAbk-BfnZ1FdRwuPx6Pl7AWyR4zjqRFZw") | ||
@features.rasp_command_injection | ||
@scenarios.appsec_rasp | ||
class Test_Cmdi_BodyUrlEncoded: | ||
"""Shell Injection through a url-encoded body parameter""" | ||
|
||
def setup_cmdi_post_urlencoded(self): | ||
self.r = weblog.post("/rasp/cmdi", data={"command": "/bin/evilCommand"}) | ||
|
||
def test_cmdi_post_urlencoded(self): | ||
assert self.r.status_code == 403 | ||
|
||
interfaces.library.assert_rasp_attack( | ||
self.r, | ||
"rasp-932-110", | ||
{ | ||
"resource": {"address": "server.sys.exec.cmd", "value": "/bin/evilCommand",}, | ||
"params": {"address": "server.request.body", "value": "/bin/evilCommand",}, | ||
}, | ||
) | ||
|
||
|
||
@rfc("https://docs.google.com/document/d/1DDWy3frMXDTAbk-BfnZ1FdRwuPx6Pl7AWyR4zjqRFZw") | ||
@features.rasp_command_injection | ||
@scenarios.appsec_rasp | ||
class Test_Cmdi_BodyXml: | ||
"""Shell Injection through an xml body parameter""" | ||
|
||
def setup_cmdi_post_xml(self): | ||
data = "<?xml version='1.0' encoding='utf-8'?><command>/bin/evilCommand</command>" | ||
self.r = weblog.post("/rasp/cmdi", data=data, headers={"Content-Type": "application/xml"}) | ||
|
||
def test_cmdi_post_xml(self): | ||
assert self.r.status_code == 403 | ||
|
||
interfaces.library.assert_rasp_attack( | ||
self.r, | ||
"rasp-932-110", | ||
{ | ||
"resource": {"address": "server.sys.exec.cmd", "value": "/bin/evilCommand",}, | ||
"params": {"address": "server.request.body", "value": "/bin/evilCommand",}, | ||
}, | ||
) | ||
|
||
|
||
@rfc("https://docs.google.com/document/d/1DDWy3frMXDTAbk-BfnZ1FdRwuPx6Pl7AWyR4zjqRFZw") | ||
@features.rasp_command_injection | ||
@scenarios.appsec_rasp | ||
class Test_Cmdi_BodyJson: | ||
"""Shell Injection through a json body parameter""" | ||
|
||
def setup_cmdi_post_json(self): | ||
"""AppSec detects attacks in JSON body values""" | ||
self.r = weblog.post("/rasp/cmdi", json={"command": "/bin/evilCommand"}) | ||
|
||
def test_cmdi_post_json(self): | ||
assert self.r.status_code == 403 | ||
|
||
interfaces.library.assert_rasp_attack( | ||
self.r, | ||
"rasp-932-110", | ||
{ | ||
"resource": {"address": "server.sys.exec.cmd", "value": "/bin/evilCommand",}, | ||
"params": {"address": "server.request.body", "value": "/bin/evilCommand",}, | ||
}, | ||
) | ||
|
||
|
||
@rfc("https://docs.google.com/document/d/1DDWy3frMXDTAbk-BfnZ1FdRwuPx6Pl7AWyR4zjqRFZw") | ||
@features.rasp_span_tags | ||
@features.rasp_command_injection | ||
@scenarios.appsec_rasp | ||
class Test_Cmdi_Mandatory_SpanTags: | ||
"""Validate span tag generation on exploit attempts""" | ||
|
||
def setup_cmdi_span_tags(self): | ||
self.r = weblog.get("/rasp/cmdi", params={"command": "/bin/evilCommand"}) | ||
|
||
def test_cmdi_span_tags(self): | ||
validate_span_tags(self.r, expected_metrics=["_dd.appsec.rasp.duration"]) | ||
|
||
|
||
@rfc("https://docs.google.com/document/d/1DDWy3frMXDTAbk-BfnZ1FdRwuPx6Pl7AWyR4zjqRFZw") | ||
@features.rasp_span_tags | ||
@features.rasp_command_injection | ||
@scenarios.appsec_rasp | ||
class Test_Cmdi_Optional_SpanTags: | ||
"""Validate span tag generation on exploit attempts""" | ||
|
||
def setup_cmdi_span_tags(self): | ||
self.r = weblog.get("/rasp/cmdi", params={"command": "/bin/evilCommand"}) | ||
|
||
def test_cmdi_span_tags(self): | ||
validate_span_tags( | ||
self.r, expected_metrics=["_dd.appsec.rasp.duration_ext", "_dd.appsec.rasp.rule.eval",], | ||
) | ||
|
||
|
||
@rfc("https://docs.google.com/document/d/1DDWy3frMXDTAbk-BfnZ1FdRwuPx6Pl7AWyR4zjqRFZw") | ||
@features.rasp_stack_trace | ||
@features.rasp_command_injection | ||
@scenarios.appsec_rasp | ||
class Test_Cmdi_StackTrace: | ||
"""Validate stack trace generation on exploit attempts""" | ||
|
||
def setup_cmdi_stack_trace(self): | ||
self.r = weblog.get("/rasp/cmdi", params={"command": "/bin/evilCommand"}) | ||
|
||
def test_cmdi_stack_trace(self): | ||
assert self.r.status_code == 403 | ||
validate_stack_traces(self.r) | ||
|
||
|
||
@rfc("https://docs.google.com/document/d/1DDWy3frMXDTAbk-BfnZ1FdRwuPx6Pl7AWyR4zjqRFZw") | ||
@features.rasp_command_injection | ||
@scenarios.appsec_rasp | ||
class Test_Cmdi_Telemetry: | ||
"""Validate Telemetry data on exploit attempts""" | ||
|
||
def setup_cmdi_telemetry(self): | ||
self.r = weblog.get("/rasp/cmdi", params={"command": "/bin/evilCommand"}) | ||
|
||
def test_cmdi_telemetry(self): | ||
assert self.r.status_code == 403 | ||
|
||
series_eval = find_series(True, "appsec", "rasp.rule.eval") | ||
assert series_eval | ||
assert any(validate_metric_variant("rasp.rule.eval", "command_injection", "exec", s) for s in series_eval), [ | ||
s.get("tags") for s in series_eval | ||
] | ||
|
||
series_match = find_series(True, "appsec", "rasp.rule.match") | ||
assert series_match | ||
assert any(validate_metric_variant("rasp.rule.match", "command_injection", "exec", s) for s in series_match), [ | ||
s.get("tags") for s in series_match | ||
] | ||
|
||
|
||
@rfc("https://docs.google.com/document/d/1DDWy3frMXDTAbk-BfnZ1FdRwuPx6Pl7AWyR4zjqRFZw") | ||
@features.rasp_command_injection | ||
@scenarios.remote_config_mocked_backend_asm_dd | ||
class Test_Cmdi_Capability: | ||
"""Validate that ASM_RASP_CMDI (37) capability is sent""" | ||
|
||
def test_cmdi_capability(self): | ||
interfaces.library.assert_rc_capability(Capabilities.ASM_RASP_CMDI) | ||
|
||
|
||
@features.rasp_command_injection | ||
class Test_Cmdi_Rules_Version(Base_Rules_Version): | ||
"""Test cmdi min rules version""" | ||
|
||
min_version = "1.13.5" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are going to have multiple libddwaf min versions, it will worth to move the test to each test file, like we are doing with
Rules_Version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I have updated the code addressing your comment.