Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cloudsplaining/output/policy_finding.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

from cloudsplaining.shared.constants import (
ACTIONS_THAT_RETURN_CREDENTIALS,
DATA_EXFILTRATION_ACTIONS,
ISSUE_SEVERITY,
READ_ONLY_DATA_EXFILTRATION_ACTIONS,
RISK_DEFINITION,
)
from cloudsplaining.shared.exclusions import (
Expand Down Expand Up @@ -102,9 +102,7 @@ def data_exfiltration(self) -> list[str]:
"""Returns data exfiltration actions in the policy, if present"""
return [
action
for action in self.policy_document.allows_specific_actions_without_constraints(
READ_ONLY_DATA_EXFILTRATION_ACTIONS
)
for action in self.policy_document.allows_specific_actions_without_constraints(DATA_EXFILTRATION_ACTIONS)
if action.lower() not in self.exclusions.exclude_actions
]

Expand Down
83 changes: 81 additions & 2 deletions cloudsplaining/output/src/sampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4994,6 +4994,7 @@ var sample_iam_data = {
"findings": [
"s3:GetObject",
"ssm:GetParameter",
"ssm:GetParameterHistory",
"ssm:GetParameters",
"ssm:GetParametersByPath"
]
Expand Down Expand Up @@ -5669,7 +5670,13 @@ var sample_iam_data = {
"DataExfiltration": {
"severity": "medium",
"description": "<div style=\"text-align:left\"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>",
"findings": []
"findings": [
"rds:CopyDBClusterSnapshot",
"rds:CopyDBSnapshot",
"rds:CreateDBClusterSnapshot",
"rds:CreateDBSnapshot",
"rds:StartExportTask"
]
},
"ResourceExposure": {
"severity": "high",
Expand Down Expand Up @@ -5912,7 +5919,13 @@ var sample_iam_data = {
"DataExfiltration": {
"severity": "medium",
"description": "<div style=\"text-align:left\"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>",
"findings": []
"findings": [
"ec2:CopySnapshot",
"ec2:CreateInstanceExportTask",
"ec2:CreateSnapshot",
"ec2:CreateSnapshots",
"ec2:ExportImage"
]
},
"ResourceExposure": {
"severity": "high",
Expand Down Expand Up @@ -7071,6 +7084,7 @@ var sample_iam_data = {
"severity": "medium",
"description": "<div style=\"text-align:left\"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>",
"findings": [
"dynamodb:ExportTableToPointInTime",
"s3:GetObject"
]
},
Expand Down Expand Up @@ -10199,9 +10213,21 @@ var sample_iam_data = {
"severity": "medium",
"description": "<div style=\"text-align:left\"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>",
"findings": [
"dynamodb:ExportTableToPointInTime",
"ec2:CopySnapshot",
"ec2:CreateInstanceExportTask",
"ec2:CreateSnapshot",
"ec2:CreateSnapshots",
"ec2:ExportImage",
"rds:CopyDBClusterSnapshot",
"rds:CopyDBSnapshot",
"rds:CreateDBClusterSnapshot",
"rds:CreateDBSnapshot",
"rds:StartExportTask",
"s3:GetObject",
"secretsmanager:GetSecretValue",
"ssm:GetParameter",
"ssm:GetParameterHistory",
"ssm:GetParameters",
"ssm:GetParametersByPath"
]
Expand Down Expand Up @@ -21515,9 +21541,21 @@ var sample_iam_data = {
"severity": "medium",
"description": "<div style=\"text-align:left\"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>",
"findings": [
"dynamodb:ExportTableToPointInTime",
"ec2:CopySnapshot",
"ec2:CreateInstanceExportTask",
"ec2:CreateSnapshot",
"ec2:CreateSnapshots",
"ec2:ExportImage",
"rds:CopyDBClusterSnapshot",
"rds:CopyDBSnapshot",
"rds:CreateDBClusterSnapshot",
"rds:CreateDBSnapshot",
"rds:StartExportTask",
"s3:GetObject",
"secretsmanager:GetSecretValue",
"ssm:GetParameter",
"ssm:GetParameterHistory",
"ssm:GetParameters",
"ssm:GetParametersByPath"
]
Expand Down Expand Up @@ -32006,9 +32044,21 @@ var sample_iam_data = {
"severity": "medium",
"description": "<div style=\"text-align:left\"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>",
"findings": [
"dynamodb:ExportTableToPointInTime",
"ec2:CopySnapshot",
"ec2:CreateInstanceExportTask",
"ec2:CreateSnapshot",
"ec2:CreateSnapshots",
"ec2:ExportImage",
"rds:CopyDBClusterSnapshot",
"rds:CopyDBSnapshot",
"rds:CreateDBClusterSnapshot",
"rds:CreateDBSnapshot",
"rds:StartExportTask",
"s3:GetObject",
"secretsmanager:GetSecretValue",
"ssm:GetParameter",
"ssm:GetParameterHistory",
"ssm:GetParameters",
"ssm:GetParametersByPath"
]
Expand Down Expand Up @@ -43491,9 +43541,21 @@ var sample_iam_data = {
"severity": "medium",
"description": "<div style=\"text-align:left\"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>",
"findings": [
"dynamodb:ExportTableToPointInTime",
"ec2:CopySnapshot",
"ec2:CreateInstanceExportTask",
"ec2:CreateSnapshot",
"ec2:CreateSnapshots",
"ec2:ExportImage",
"rds:CopyDBClusterSnapshot",
"rds:CopyDBSnapshot",
"rds:CreateDBClusterSnapshot",
"rds:CreateDBSnapshot",
"rds:StartExportTask",
"s3:GetObject",
"secretsmanager:GetSecretValue",
"ssm:GetParameter",
"ssm:GetParameterHistory",
"ssm:GetParameters",
"ssm:GetParametersByPath"
]
Expand Down Expand Up @@ -54173,6 +54235,11 @@ var sample_iam_data = {
"severity": "medium",
"description": "<div style=\"text-align:left\"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>",
"findings": [
"ec2:CopySnapshot",
"ec2:CreateInstanceExportTask",
"ec2:CreateSnapshot",
"ec2:CreateSnapshots",
"ec2:ExportImage",
"s3:GetObject"
]
},
Expand Down Expand Up @@ -55635,9 +55702,21 @@ var sample_iam_data = {
"severity": "medium",
"description": "<div style=\"text-align:left\"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>",
"findings": [
"dynamodb:ExportTableToPointInTime",
"ec2:CopySnapshot",
"ec2:CreateInstanceExportTask",
"ec2:CreateSnapshot",
"ec2:CreateSnapshots",
"ec2:ExportImage",
"rds:CopyDBClusterSnapshot",
"rds:CopyDBSnapshot",
"rds:CreateDBClusterSnapshot",
"rds:CreateDBSnapshot",
"rds:StartExportTask",
"s3:GetObject",
"secretsmanager:GetSecretValue",
"ssm:GetParameter",
"ssm:GetParameterHistory",
"ssm:GetParameters",
"ssm:GetParametersByPath"
]
Expand Down
4 changes: 2 additions & 2 deletions cloudsplaining/scan/policy_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from cloudsplaining.scan.statement_detail import StatementDetail
from cloudsplaining.shared.constants import (
ACTIONS_THAT_RETURN_CREDENTIALS,
DATA_EXFILTRATION_ACTIONS,
PRIVILEGE_ESCALATION_METHODS,
READ_ONLY_DATA_EXFILTRATION_ACTIONS,
)
from cloudsplaining.shared.exclusions import DEFAULT_EXCLUSIONS, Exclusions

Expand Down Expand Up @@ -224,7 +224,7 @@ def allows_data_exfiltration_actions(self) -> list[str]:
"""If any 'Data exfiltration' actions are allowed without resource constraints, return those actions."""
return [
action
for action in self.allows_specific_actions_without_constraints(READ_ONLY_DATA_EXFILTRATION_ACTIONS)
for action in self.allows_specific_actions_without_constraints(DATA_EXFILTRATION_ACTIONS)
if action.lower() not in self.exclusions.exclude_actions
]

Expand Down
19 changes: 19 additions & 0 deletions cloudsplaining/shared/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,28 @@
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:GetParametersByPath",
"ssm:GetParameterHistory",
"secretsmanager:GetSecretValue",
]

# Write-level actions that put a full copy of a data store (a snapshot or an export) somewhere it can be
# shared with another account or downloaded. They are reported under the same Data Exfiltration finding.
SNAPSHOT_AND_EXPORT_DATA_EXFILTRATION_ACTIONS = [
"rds:CreateDBSnapshot",
"rds:CopyDBSnapshot",
"rds:CreateDBClusterSnapshot",
"rds:CopyDBClusterSnapshot",
"rds:StartExportTask",
"ec2:CreateSnapshot",
"ec2:CreateSnapshots",
"ec2:CopySnapshot",
"ec2:CreateInstanceExportTask",
"ec2:ExportImage",
"dynamodb:ExportTableToPointInTime",
]

DATA_EXFILTRATION_ACTIONS = READ_ONLY_DATA_EXFILTRATION_ACTIONS + SNAPSHOT_AND_EXPORT_DATA_EXFILTRATION_ACTIONS

ISSUE_SEVERITY = {
"PrivilegeEscalation": "high",
"DataExfiltration": "medium",
Expand Down
9 changes: 7 additions & 2 deletions docs/glossary/data-exfiltration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Data Exfiltration actions allow certain read-only IAM actions without resource constraints, such as `s3:GetObject`, `ssm:GetParameter*`, or `secretsmanager:GetSecretValue`.
Data Exfiltration actions allow certain read-only IAM actions without resource constraints, such as `s3:GetObject`, `ssm:GetParameter*`, or `secretsmanager:GetSecretValue`. It also covers Write-level actions that copy a whole data store into a snapshot or export, such as `rds:CreateDBSnapshot`, `ec2:CreateSnapshot`, or `dynamodb:ExportTableToPointInTime`.

* Unrestricted `s3:GetObject` permissions has a long history of customer data leaks
* `ssm:GetParameter*` and `secretsmanager:GetSecretValue` are both used to access secrets.
* `ssm:GetParameter*`, `ssm:GetParameterHistory` and `secretsmanager:GetSecretValue` are used to access secrets.
* `rds:CopyDBSnapshot` and `rds:CreateDBSnapshot` can be used to exfiltrate RDS database contents.

The full list of actions flagged under this category:

* Read: `s3:GetObject`, `ssm:GetParameter`, `ssm:GetParameters`, `ssm:GetParametersByPath`, `ssm:GetParameterHistory`, `secretsmanager:GetSecretValue`
* Snapshot, copy and export: `rds:CreateDBSnapshot`, `rds:CopyDBSnapshot`, `rds:CreateDBClusterSnapshot`, `rds:CopyDBClusterSnapshot`, `rds:StartExportTask`, `ec2:CreateSnapshot`, `ec2:CreateSnapshots`, `ec2:CopySnapshot`, `ec2:CreateInstanceExportTask`, `ec2:ExportImage`, `dynamodb:ExportTableToPointInTime`
4 changes: 2 additions & 2 deletions index.html

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions test/output/test_policy_finding.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@


class TestPolicyFinding(unittest.TestCase):
def test_policy_finding_data_exfiltration_snapshot_export_gh_654(self):
test_policy = {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["rds:CreateDBSnapshot", "ec2:CreateSnapshot", "dynamodb:ExportTableToPointInTime"],
"Resource": "*",
}
],
}
policy_finding = PolicyFinding(PolicyDocument(test_policy), Exclusions({}))
self.assertListEqual(
policy_finding.data_exfiltration,
["dynamodb:ExportTableToPointInTime", "ec2:CreateSnapshot", "rds:CreateDBSnapshot"],
)
self.assertListEqual(
policy_finding.results["DataExfiltration"]["findings"],
["dynamodb:ExportTableToPointInTime", "ec2:CreateSnapshot", "rds:CreateDBSnapshot"],
)
# exclude-actions still suppresses them
policy_finding = PolicyFinding(
PolicyDocument(test_policy), Exclusions({"exclude-actions": ["rds:CreateDBSnapshot"]})
)
self.assertNotIn("rds:CreateDBSnapshot", policy_finding.data_exfiltration)

def test_policy_finding_for_data_exfiltration(self):
test_policy = {
"Version": "2012-10-17",
Expand Down
27 changes: 27 additions & 0 deletions test/scanning/test_data_exfiltration_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Every Data Exfiltration action must be detectable when allowed on Resource "*".

This also verifies policy_sentry recognizes every action in DATA_EXFILTRATION_ACTIONS:
an unrecognized or misspelled action would drop out during expansion and not be flagged.
"""

import unittest

from cloudsplaining.scan.policy_document import PolicyDocument
from cloudsplaining.shared.constants import DATA_EXFILTRATION_ACTIONS


class TestDataExfiltrationActionsAreDetectable(unittest.TestCase):
def test_no_duplicate_actions(self):
lowered = [action.lower() for action in DATA_EXFILTRATION_ACTIONS]
self.assertEqual(len(lowered), len(set(lowered)))

def test_every_action_detected_on_wildcard_resource(self):
undetected = []
for action in DATA_EXFILTRATION_ACTIONS:
test_policy = {
"Version": "2012-10-17",
"Statement": [{"Effect": "Allow", "Action": action, "Resource": "*"}],
}
if PolicyDocument(test_policy).allows_data_exfiltration_actions != [action]:
undetected.append(action)
self.assertEqual(undetected, [], f"actions not detected: {undetected}")
Loading