attackmap-analyzer-terraform 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- attackmap_analyzer_terraform-0.2.1/LICENSE +21 -0
- attackmap_analyzer_terraform-0.2.1/PKG-INFO +119 -0
- attackmap_analyzer_terraform-0.2.1/README.md +80 -0
- attackmap_analyzer_terraform-0.2.1/pyproject.toml +74 -0
- attackmap_analyzer_terraform-0.2.1/setup.cfg +4 -0
- attackmap_analyzer_terraform-0.2.1/src/attackmap_analyzer_terraform/__init__.py +3 -0
- attackmap_analyzer_terraform-0.2.1/src/attackmap_analyzer_terraform/analyzer.py +2079 -0
- attackmap_analyzer_terraform-0.2.1/src/attackmap_analyzer_terraform.egg-info/PKG-INFO +119 -0
- attackmap_analyzer_terraform-0.2.1/src/attackmap_analyzer_terraform.egg-info/SOURCES.txt +13 -0
- attackmap_analyzer_terraform-0.2.1/src/attackmap_analyzer_terraform.egg-info/dependency_links.txt +1 -0
- attackmap_analyzer_terraform-0.2.1/src/attackmap_analyzer_terraform.egg-info/entry_points.txt +2 -0
- attackmap_analyzer_terraform-0.2.1/src/attackmap_analyzer_terraform.egg-info/requires.txt +9 -0
- attackmap_analyzer_terraform-0.2.1/src/attackmap_analyzer_terraform.egg-info/top_level.txt +1 -0
- attackmap_analyzer_terraform-0.2.1/tests/test_misconfig_checks.py +804 -0
- attackmap_analyzer_terraform-0.2.1/tests/test_terraform_analyzer.py +1236 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matthew Davis and AttackMap Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: attackmap-analyzer-terraform
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Terraform / HCL infrastructure-as-code analyzer plugin for AttackMap (AWS, Azure, GCP resources; IAM wildcards; open security groups; secret resources).
|
|
5
|
+
Author: AttackMap Contributors
|
|
6
|
+
Author-email: Matthew Davis <mlaify@mlaify.io>
|
|
7
|
+
Maintainer-email: Matthew Davis <mlaify@mlaify.io>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/mlaify/attackmap-analyzer-terraform
|
|
10
|
+
Project-URL: Repository, https://github.com/mlaify/attackmap-analyzer-terraform
|
|
11
|
+
Project-URL: Issues, https://github.com/mlaify/attackmap-analyzer-terraform/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/mlaify/attackmap-analyzer-terraform/blob/main/CHANGELOG.md
|
|
13
|
+
Project-URL: AttackMap core, https://github.com/mlaify/AttackMap
|
|
14
|
+
Keywords: security,static-analysis,appsec,defensive-security,attackmap,attackmap-plugin
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: Information Technology
|
|
18
|
+
Classifier: Intended Audience :: System Administrators
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
25
|
+
Classifier: Topic :: Security
|
|
26
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.11
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: pydantic>=2.7.0
|
|
32
|
+
Provides-Extra: core
|
|
33
|
+
Requires-Dist: attackmap>=0.6.0; extra == "core"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: build>=1.2.0; extra == "dev"
|
|
37
|
+
Requires-Dist: attackmap>=0.6.0; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# attackmap-analyzer-terraform
|
|
41
|
+
|
|
42
|
+
> [!IMPORTANT]
|
|
43
|
+
> **Active development, slow pace.** AttackMap is under active development, but
|
|
44
|
+
> progress may be slow until more contributors or co-maintainers join. Help is
|
|
45
|
+
> very welcome with the core engine, an analyzer, the macOS app, or the docs —
|
|
46
|
+
> see [CONTRIBUTING.md](CONTRIBUTING.md) or open an issue on
|
|
47
|
+
> [mlaify/AttackMap](https://github.com/mlaify/AttackMap/issues) to say hello.
|
|
48
|
+
> Security reports are still welcome at [security@mlaify.io](mailto:security@mlaify.io).
|
|
49
|
+
|
|
50
|
+
Terraform / HCL infrastructure-as-code analyzer for [AttackMap](https://github.com/mlaify/AttackMap).
|
|
51
|
+
|
|
52
|
+
This analyzer is shaped differently from language analyzers — Terraform doesn't have routes in the application sense. Instead, it extracts:
|
|
53
|
+
|
|
54
|
+
- **Public ingress** — security groups (`ingress` blocks only; open egress is ignored) and inbound firewall rules with `0.0.0.0/0` / `::/0`, Lambda Function URLs with no auth, API Gateway methods with `authorization = "NONE"`, S3 buckets with public ACLs (inline or `aws_s3_bucket_acl`), public bucket policies or disabled public-access blocks → `entrypoint_hints`
|
|
55
|
+
- **Asset inventory** — S3 buckets, Azure storage accounts, GCS buckets, KMS keys, Cognito user pools → `service_hints`
|
|
56
|
+
- **Databases** — `aws_db_instance` and `aws_rds_cluster` (engine-aware: postgres / mysql / oracle / sqlserver / mariadb), `aws_dynamodb_table`, `aws_elasticache_*`, `aws_documentdb_*`, Azure PostgreSQL/MySQL/CosmosDB, GCP Cloud SQL → `database_hints`
|
|
57
|
+
- **Secrets** — `aws_secretsmanager_secret`, `aws_ssm_parameter` (SecureString), `azurerm_key_vault`, plus `variable` blocks marked `sensitive = true` or with secret-shaped names (`*secret*`, `*token*`, `*password*`, `*key*`), and secret-shaped string literals in `.tfvars` (`kind="hardcoded"`) → `secret_hints`. A secret variable with a literal string `default` is `kind="hardcoded"` (the value is never echoed); a bare declaration keeps the default kind.
|
|
58
|
+
- **IAM blast radius** — Allow statements with `Action "*"` (0.7), `Resource "*"` (0.5) or unconditioned `Principal "*"` (0.7) in `aws_iam_*_policy`, `aws_iam_role` trust/inline policies and `data "aws_iam_policy_document"` → `auth_hints`
|
|
59
|
+
- **Cognito** — `aws_cognito_user_pool` → `auth_hints`
|
|
60
|
+
- **Modules** — `module "x" { source = ... }` → `service_hints` keyed `module:x`
|
|
61
|
+
- **Misconfigurations** → `cloud_misconfigs` (AttackMap's `CloudMisconfig` record, which core turns into findings with CWE/OWASP ids). Each record names the resource, carries its `for_each`/`count` and, for resources inside a local module, the `module.<name> (file:line)` blocks that call it:
|
|
62
|
+
- `iac_module_unpinned`: git module sources without `?ref=` or pinned to a branch (`main`, `master`, `develop`, ...), and registry modules without `version`. A tag (`?ref=v1.2.3`) or commit SHA is pinned.
|
|
63
|
+
- `public_network_access`: `associate_public_ip_address = true` (`aws_instance`, launch configurations and templates), `publicly_accessible = true` RDS, and `public_network_access_enabled = true` on any `azurerm_*` resource.
|
|
64
|
+
- `public_cluster_endpoint`: `aws_eks_cluster` whose API endpoint is public and open to `0.0.0.0/0` (both are the defaults, reported with lower confidence when left implicit).
|
|
65
|
+
- `plaintext_listener`: `aws_lb_listener` on `HTTP` without a redirect default action, unless its load balancer is `internal = true`.
|
|
66
|
+
- `api_no_authorizer`: API Gateway v1 methods with `authorization = "NONE"` and no API key, and v2 HTTP routes with `authorization_type = "NONE"` or none at all (the default). `OPTIONS` (CORS preflight) is skipped.
|
|
67
|
+
- `unencrypted_storage`: `storage_encrypted = false` on `aws_db_instance` / `aws_rds_cluster`, and `aws_db_instance` without it (defaults to false; replicas, snapshot restores and `kms_key_id` are skipped).
|
|
68
|
+
- `public_data_access`: public S3 ACLs and policies, disabled public-access blocks, OpenSearch / Elasticsearch `access_policies` open to `Principal "*"`, GCS buckets granted to `allUsers` / `allAuthenticatedUsers` (IAM, ACLs, `predefined_acl = "publicRead"`), `allow_nested_items_to_be_public = true` and public `azurerm_storage_container`s.
|
|
69
|
+
- `public_invoker`: Cloud Run / Cloud Functions invoker roles granted to `allUsers` / `allAuthenticatedUsers`, and Lambda function URLs with `authorization_type = "NONE"`.
|
|
70
|
+
- kubernetes provider: privileged containers, `allow_privilege_escalation = true`, `host_network` / `host_pid` / `host_ipc`, `host_path` volumes (high for the runtime socket, `/`, `/etc`, `/proc`, `/var/lib/kubelet`, ...), `cluster-admin` or `system:authenticated` bindings, roles with `*` / `escalate` / `bind` / `impersonate` / `pods/exec` / Secret read, and `LoadBalancer` / `NodePort` services without `load_balancer_source_ranges`.
|
|
71
|
+
- Only literal values are judged: an attribute set from `var.x` or another reference is skipped.
|
|
72
|
+
- **API Gateway v2 routes** — `aws_apigatewayv2_route` with `route_key = "POST /charges"` → actual `Route` entries
|
|
73
|
+
- **API Gateway v1 routes** — `aws_api_gateway_method` on an `aws_api_gateway_resource` chain (`parent_id` / `path_part` joined back to `root_resource_id`, across files) → `Route` entries
|
|
74
|
+
- **Lambda function URLs** — `aws_lambda_function_url` → an `ANY /` `Route`
|
|
75
|
+
- **Route auth (AttackMap#256)** — every route carries `auth` / `guards` / `guard_evidence`. `authorization` / `authorization_type` = `AWS_IAM`, `COGNITO_USER_POOLS`, `CUSTOM` or `JWT` (or v1 `api_key_required = true`) → `required`. `"NONE"` written out → `anonymous`. Omitted or computed (`var.x`) → `unknown`.
|
|
76
|
+
|
|
77
|
+
All emissions populate AttackMap's Signal v2 fields (line numbers + evidence snippets) so downstream insights can cite `infra/main.tf:NN`.
|
|
78
|
+
|
|
79
|
+
## Install
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
uv tool install attackmap --with attackmap-analyzer-terraform \
|
|
83
|
+
--index mlaify=https://pkg.mlaify.io/pypi/simple/ --index-strategy first-index
|
|
84
|
+
# or from source:
|
|
85
|
+
pip install git+https://github.com/mlaify/attackmap-analyzer-terraform.git
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The analyzer is auto-discovered by AttackMap via the `attackmap.analyzers` entry-point group.
|
|
89
|
+
|
|
90
|
+
## Usage with AttackMap
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Auto-discovered when installed:
|
|
94
|
+
attackmap analyze /path/to/terraform/repo
|
|
95
|
+
|
|
96
|
+
# Or invoke explicitly:
|
|
97
|
+
attackmap analyze /path/to/terraform/repo --module terraform
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Detection
|
|
101
|
+
|
|
102
|
+
`detect()` returns true when any `.tf`, `.tf.json`, or `.tfvars` file is present in the tree, ignoring `.terraform/` and AttackMap's shared skip list (`.git/`, `node_modules/`, `vendor/`, `build/`, `dist/`, `out/`, `target/`, ...). Skip directories are matched only *inside* the repo, so a checkout under e.g. `/build/...` is still scanned. Files are walked with `attackmap.sdk.iter_repo_files`, which does not follow symlinks out of the repo.
|
|
103
|
+
|
|
104
|
+
## HCL block parsing
|
|
105
|
+
|
|
106
|
+
The analyzer parses HCL block bodies via brace-depth counting (with string-literal awareness so `"{" inside strings"` doesn't throw off the counter). Nested blocks like multiple `ingress { }` blocks inside a security group are handled correctly. **Variable interpolation** (`${var.foo}`, `aws_iam_role.app.id`) is **not resolved** — string literals and direct attribute values are what get extracted.
|
|
107
|
+
|
|
108
|
+
## Coverage notes
|
|
109
|
+
|
|
110
|
+
- **AWS** is the most thoroughly covered provider. Azure and GCP have basic coverage (NSG/firewall open ingress, Storage Account / GCS bucket as service hints, PostgreSQL/MySQL/CosmosDB/CloudSQL as databases) — extend per resource type as needed.
|
|
111
|
+
- **IAM wildcard detection** matches JSON-shaped (`"Action": "*"`, heredoc or `.tf.json` string) and HCL-shaped (`Action = "*"` in `jsonencode`, `actions = ["*"]` in `aws_iam_policy_document`) policies. A `policy = data.aws_iam_policy_document.x.json` reference isn't followed; the data source is reported under its own name.
|
|
112
|
+
- **`.tf.json`** files get the same analysis as `.tf`. **`.tfvars`** files are checked for secret-shaped string literals (reported as `kind="hardcoded"` with the value redacted).
|
|
113
|
+
- **API Gateway v1** methods become routes when their `resource_id` resolves through literal `aws_api_gateway_resource` blocks to a `root_resource_id`. Methods on resources from modules or with interpolated `path_part`s only emit entrypoint hints. OpenAPI `body`-defined REST APIs aren't parsed.
|
|
114
|
+
- **Lambda Function URLs** with `authorization_type = "NONE"` are flagged as open entrypoints. IAM-authorized URLs are emitted with the regular `lambda_url:` prefix.
|
|
115
|
+
- **Database `publicly_accessible = true`** on `aws_db_instance` produces a separate `rds_publicly_accessible:` entrypoint hint in addition to the standard database hint.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# attackmap-analyzer-terraform
|
|
2
|
+
|
|
3
|
+
> [!IMPORTANT]
|
|
4
|
+
> **Active development, slow pace.** AttackMap is under active development, but
|
|
5
|
+
> progress may be slow until more contributors or co-maintainers join. Help is
|
|
6
|
+
> very welcome with the core engine, an analyzer, the macOS app, or the docs —
|
|
7
|
+
> see [CONTRIBUTING.md](CONTRIBUTING.md) or open an issue on
|
|
8
|
+
> [mlaify/AttackMap](https://github.com/mlaify/AttackMap/issues) to say hello.
|
|
9
|
+
> Security reports are still welcome at [security@mlaify.io](mailto:security@mlaify.io).
|
|
10
|
+
|
|
11
|
+
Terraform / HCL infrastructure-as-code analyzer for [AttackMap](https://github.com/mlaify/AttackMap).
|
|
12
|
+
|
|
13
|
+
This analyzer is shaped differently from language analyzers — Terraform doesn't have routes in the application sense. Instead, it extracts:
|
|
14
|
+
|
|
15
|
+
- **Public ingress** — security groups (`ingress` blocks only; open egress is ignored) and inbound firewall rules with `0.0.0.0/0` / `::/0`, Lambda Function URLs with no auth, API Gateway methods with `authorization = "NONE"`, S3 buckets with public ACLs (inline or `aws_s3_bucket_acl`), public bucket policies or disabled public-access blocks → `entrypoint_hints`
|
|
16
|
+
- **Asset inventory** — S3 buckets, Azure storage accounts, GCS buckets, KMS keys, Cognito user pools → `service_hints`
|
|
17
|
+
- **Databases** — `aws_db_instance` and `aws_rds_cluster` (engine-aware: postgres / mysql / oracle / sqlserver / mariadb), `aws_dynamodb_table`, `aws_elasticache_*`, `aws_documentdb_*`, Azure PostgreSQL/MySQL/CosmosDB, GCP Cloud SQL → `database_hints`
|
|
18
|
+
- **Secrets** — `aws_secretsmanager_secret`, `aws_ssm_parameter` (SecureString), `azurerm_key_vault`, plus `variable` blocks marked `sensitive = true` or with secret-shaped names (`*secret*`, `*token*`, `*password*`, `*key*`), and secret-shaped string literals in `.tfvars` (`kind="hardcoded"`) → `secret_hints`. A secret variable with a literal string `default` is `kind="hardcoded"` (the value is never echoed); a bare declaration keeps the default kind.
|
|
19
|
+
- **IAM blast radius** — Allow statements with `Action "*"` (0.7), `Resource "*"` (0.5) or unconditioned `Principal "*"` (0.7) in `aws_iam_*_policy`, `aws_iam_role` trust/inline policies and `data "aws_iam_policy_document"` → `auth_hints`
|
|
20
|
+
- **Cognito** — `aws_cognito_user_pool` → `auth_hints`
|
|
21
|
+
- **Modules** — `module "x" { source = ... }` → `service_hints` keyed `module:x`
|
|
22
|
+
- **Misconfigurations** → `cloud_misconfigs` (AttackMap's `CloudMisconfig` record, which core turns into findings with CWE/OWASP ids). Each record names the resource, carries its `for_each`/`count` and, for resources inside a local module, the `module.<name> (file:line)` blocks that call it:
|
|
23
|
+
- `iac_module_unpinned`: git module sources without `?ref=` or pinned to a branch (`main`, `master`, `develop`, ...), and registry modules without `version`. A tag (`?ref=v1.2.3`) or commit SHA is pinned.
|
|
24
|
+
- `public_network_access`: `associate_public_ip_address = true` (`aws_instance`, launch configurations and templates), `publicly_accessible = true` RDS, and `public_network_access_enabled = true` on any `azurerm_*` resource.
|
|
25
|
+
- `public_cluster_endpoint`: `aws_eks_cluster` whose API endpoint is public and open to `0.0.0.0/0` (both are the defaults, reported with lower confidence when left implicit).
|
|
26
|
+
- `plaintext_listener`: `aws_lb_listener` on `HTTP` without a redirect default action, unless its load balancer is `internal = true`.
|
|
27
|
+
- `api_no_authorizer`: API Gateway v1 methods with `authorization = "NONE"` and no API key, and v2 HTTP routes with `authorization_type = "NONE"` or none at all (the default). `OPTIONS` (CORS preflight) is skipped.
|
|
28
|
+
- `unencrypted_storage`: `storage_encrypted = false` on `aws_db_instance` / `aws_rds_cluster`, and `aws_db_instance` without it (defaults to false; replicas, snapshot restores and `kms_key_id` are skipped).
|
|
29
|
+
- `public_data_access`: public S3 ACLs and policies, disabled public-access blocks, OpenSearch / Elasticsearch `access_policies` open to `Principal "*"`, GCS buckets granted to `allUsers` / `allAuthenticatedUsers` (IAM, ACLs, `predefined_acl = "publicRead"`), `allow_nested_items_to_be_public = true` and public `azurerm_storage_container`s.
|
|
30
|
+
- `public_invoker`: Cloud Run / Cloud Functions invoker roles granted to `allUsers` / `allAuthenticatedUsers`, and Lambda function URLs with `authorization_type = "NONE"`.
|
|
31
|
+
- kubernetes provider: privileged containers, `allow_privilege_escalation = true`, `host_network` / `host_pid` / `host_ipc`, `host_path` volumes (high for the runtime socket, `/`, `/etc`, `/proc`, `/var/lib/kubelet`, ...), `cluster-admin` or `system:authenticated` bindings, roles with `*` / `escalate` / `bind` / `impersonate` / `pods/exec` / Secret read, and `LoadBalancer` / `NodePort` services without `load_balancer_source_ranges`.
|
|
32
|
+
- Only literal values are judged: an attribute set from `var.x` or another reference is skipped.
|
|
33
|
+
- **API Gateway v2 routes** — `aws_apigatewayv2_route` with `route_key = "POST /charges"` → actual `Route` entries
|
|
34
|
+
- **API Gateway v1 routes** — `aws_api_gateway_method` on an `aws_api_gateway_resource` chain (`parent_id` / `path_part` joined back to `root_resource_id`, across files) → `Route` entries
|
|
35
|
+
- **Lambda function URLs** — `aws_lambda_function_url` → an `ANY /` `Route`
|
|
36
|
+
- **Route auth (AttackMap#256)** — every route carries `auth` / `guards` / `guard_evidence`. `authorization` / `authorization_type` = `AWS_IAM`, `COGNITO_USER_POOLS`, `CUSTOM` or `JWT` (or v1 `api_key_required = true`) → `required`. `"NONE"` written out → `anonymous`. Omitted or computed (`var.x`) → `unknown`.
|
|
37
|
+
|
|
38
|
+
All emissions populate AttackMap's Signal v2 fields (line numbers + evidence snippets) so downstream insights can cite `infra/main.tf:NN`.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
uv tool install attackmap --with attackmap-analyzer-terraform \
|
|
44
|
+
--index mlaify=https://pkg.mlaify.io/pypi/simple/ --index-strategy first-index
|
|
45
|
+
# or from source:
|
|
46
|
+
pip install git+https://github.com/mlaify/attackmap-analyzer-terraform.git
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The analyzer is auto-discovered by AttackMap via the `attackmap.analyzers` entry-point group.
|
|
50
|
+
|
|
51
|
+
## Usage with AttackMap
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Auto-discovered when installed:
|
|
55
|
+
attackmap analyze /path/to/terraform/repo
|
|
56
|
+
|
|
57
|
+
# Or invoke explicitly:
|
|
58
|
+
attackmap analyze /path/to/terraform/repo --module terraform
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Detection
|
|
62
|
+
|
|
63
|
+
`detect()` returns true when any `.tf`, `.tf.json`, or `.tfvars` file is present in the tree, ignoring `.terraform/` and AttackMap's shared skip list (`.git/`, `node_modules/`, `vendor/`, `build/`, `dist/`, `out/`, `target/`, ...). Skip directories are matched only *inside* the repo, so a checkout under e.g. `/build/...` is still scanned. Files are walked with `attackmap.sdk.iter_repo_files`, which does not follow symlinks out of the repo.
|
|
64
|
+
|
|
65
|
+
## HCL block parsing
|
|
66
|
+
|
|
67
|
+
The analyzer parses HCL block bodies via brace-depth counting (with string-literal awareness so `"{" inside strings"` doesn't throw off the counter). Nested blocks like multiple `ingress { }` blocks inside a security group are handled correctly. **Variable interpolation** (`${var.foo}`, `aws_iam_role.app.id`) is **not resolved** — string literals and direct attribute values are what get extracted.
|
|
68
|
+
|
|
69
|
+
## Coverage notes
|
|
70
|
+
|
|
71
|
+
- **AWS** is the most thoroughly covered provider. Azure and GCP have basic coverage (NSG/firewall open ingress, Storage Account / GCS bucket as service hints, PostgreSQL/MySQL/CosmosDB/CloudSQL as databases) — extend per resource type as needed.
|
|
72
|
+
- **IAM wildcard detection** matches JSON-shaped (`"Action": "*"`, heredoc or `.tf.json` string) and HCL-shaped (`Action = "*"` in `jsonencode`, `actions = ["*"]` in `aws_iam_policy_document`) policies. A `policy = data.aws_iam_policy_document.x.json` reference isn't followed; the data source is reported under its own name.
|
|
73
|
+
- **`.tf.json`** files get the same analysis as `.tf`. **`.tfvars`** files are checked for secret-shaped string literals (reported as `kind="hardcoded"` with the value redacted).
|
|
74
|
+
- **API Gateway v1** methods become routes when their `resource_id` resolves through literal `aws_api_gateway_resource` blocks to a `root_resource_id`. Methods on resources from modules or with interpolated `path_part`s only emit entrypoint hints. OpenAPI `body`-defined REST APIs aren't parsed.
|
|
75
|
+
- **Lambda Function URLs** with `authorization_type = "NONE"` are flagged as open entrypoints. IAM-authorized URLs are emitted with the regular `lambda_url:` prefix.
|
|
76
|
+
- **Database `publicly_accessible = true`** on `aws_db_instance` produces a separate `rds_publicly_accessible:` entrypoint hint in addition to the standard database hint.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "attackmap-analyzer-terraform"
|
|
7
|
+
version = "0.2.1"
|
|
8
|
+
description = "Terraform / HCL infrastructure-as-code analyzer plugin for AttackMap (AWS, Azure, GCP resources; IAM wildcards; open security groups; secret resources)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{name = "Matthew Davis", email = "mlaify@mlaify.io"},
|
|
15
|
+
{name = "AttackMap Contributors"},
|
|
16
|
+
]
|
|
17
|
+
maintainers = [
|
|
18
|
+
{name = "Matthew Davis", email = "mlaify@mlaify.io"},
|
|
19
|
+
]
|
|
20
|
+
keywords = [
|
|
21
|
+
"security",
|
|
22
|
+
"static-analysis",
|
|
23
|
+
"appsec",
|
|
24
|
+
"defensive-security",
|
|
25
|
+
"attackmap",
|
|
26
|
+
"attackmap-plugin",
|
|
27
|
+
]
|
|
28
|
+
classifiers = [
|
|
29
|
+
"Development Status :: 4 - Beta",
|
|
30
|
+
"Intended Audience :: Developers",
|
|
31
|
+
"Intended Audience :: Information Technology",
|
|
32
|
+
"Intended Audience :: System Administrators",
|
|
33
|
+
"Operating System :: OS Independent",
|
|
34
|
+
"Programming Language :: Python :: 3",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
38
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
39
|
+
"Topic :: Security",
|
|
40
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
41
|
+
"Typing :: Typed",
|
|
42
|
+
]
|
|
43
|
+
dependencies = [
|
|
44
|
+
"pydantic>=2.7.0",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.optional-dependencies]
|
|
48
|
+
core = [
|
|
49
|
+
"attackmap>=0.6.0",
|
|
50
|
+
]
|
|
51
|
+
dev = [
|
|
52
|
+
"pytest>=8.0.0",
|
|
53
|
+
"build>=1.2.0",
|
|
54
|
+
"attackmap>=0.6.0",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[project.urls]
|
|
58
|
+
Homepage = "https://github.com/mlaify/attackmap-analyzer-terraform"
|
|
59
|
+
Repository = "https://github.com/mlaify/attackmap-analyzer-terraform"
|
|
60
|
+
Issues = "https://github.com/mlaify/attackmap-analyzer-terraform/issues"
|
|
61
|
+
Changelog = "https://github.com/mlaify/attackmap-analyzer-terraform/blob/main/CHANGELOG.md"
|
|
62
|
+
"AttackMap core" = "https://github.com/mlaify/AttackMap"
|
|
63
|
+
|
|
64
|
+
[project.entry-points."attackmap.analyzers"]
|
|
65
|
+
terraform = "attackmap_analyzer_terraform:TerraformAnalyzer"
|
|
66
|
+
|
|
67
|
+
[tool.setuptools]
|
|
68
|
+
package-dir = {"" = "src"}
|
|
69
|
+
|
|
70
|
+
[tool.setuptools.packages.find]
|
|
71
|
+
where = ["src"]
|
|
72
|
+
|
|
73
|
+
[tool.pytest.ini_options]
|
|
74
|
+
testpaths = ["tests"]
|