[LINPEAS] Add privilege escalation check: ECS on EC2 Covering Gaps in IMDS Hardeni... #545
+170
−0
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.
🔧 Automated Privilege Escalation Check Addition
🤔 Privilege Escalation Reasoning
The blog describes a cloud-side local privilege escalation pattern that is both realistic and widely applicable in production: abusing EC2 Instance Metadata Service (IMDS) from containers on ECS‑on‑EC2 to obtain higher-privilege credentials and pivot. While this is not a classic OS-level privesc (kernel, setuid, sudo, etc.), from the perspective of a foothold inside a Linux container/host it is a straightforward, automatable step to escalate effective privileges in the environment.
Key techniques that are generic and not CTF-specific:
IMDS credential theft from inside containers (ECS on EC2)
http://169.254.169.254/latest/meta-data/iam/security-credentials/→ list available instance profile names, thenhttp://169.254.169.254/latest/meta-data/iam/security-credentials/{InstanceProfileName}→ obtain host-level EC2 instance profile credentials.Network-mode–dependent IMDS reachability (awsvpc / host / bridge)
awsvpcmode: IMDS reachable (single hop).hostmode: IMDS reachable (shares host network namespace).bridgemode: typically blocked by hop limit 1, because Docker bridge adds an extra hop, unless additional iptables rules exist or are misconfigured.Detection of hardening that blocks IMDS
While mainly defensive guidance, these are also useful checks for an attacker-focused privesc enumerator to understand why IMDS is inaccessible:
awsvpcmode, IMDS can be blocked via ECS agent configuration on the Linux host:/etc/ecs/ecs.configwithECS_AWSVPC_BLOCK_IMDS=true.DOCKER-USERchain such as:--in-interface docker+ --destination 169.254.169.254/32 --jump DROP.ECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST.ECScape-style agent impersonation (conceptual)
Why this fits linpeas:
Why not winpeas / macOS:
Therefore, the post does contain a realistic, reusable privilege escalation pattern (cloud-side) that linpeas could meaningfully enumerate and highlight for Linux systems running inside AWS.
🤖 Implementation Details
PEASS linpeas agent completed successfully with 70 items. Agent Comment: Summary of additions
linPEAS/builder/linpeas_parts/3_cloud/16_AWS_ECS_IMDS.sh) to capture the blog’s privilege-escalation vector where ECS tasks can pivot to host- or cross-task IAM credentials via IMDS.awsvpc,bridge, orhostnetworking—the exact modes the blog shows behave differently with hop-limit hardening.Detection logic implemented
/etc/ecs/ecs.configwhen available and explains the impact ofECS_AWSVPC_BLOCK_IMDSandECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST, making it clear whether awsvpc or host-mode tasks are actually blocked from metadata as recommended in the article.DOCKER-USERiptables chain (or reports why it can’t) to show whether bridge-mode protections like the documented--in-interface docker+ --destination 169.254.169.254/32 --jump DROPrule are in place.Testing
bash -n linPEAS/builder/linpeas_parts/3_cloud/16_AWS_ECS_IMDS.shNo additional documentation updates were required because the new module is self-documenting via its metadata header and console output.
🏗️ Builder Agent Response
LinPEAS build agent completed successfully with 50 items. Agent Comment: LinPEAS now builds cleanly. Here’s what I did:
Initial build attempt: Ran
python3 -m builder.linpeas_builder --all --output /tmp/linpeas_fat.shfrom/tmp/hacktricks_update_d9wq0okm/repo/linPEAS. It failed because the new module3_cloud/16_AWS_ECS_IMDS.shreferenced several variables that weren’t declared in the module metadata, causing the builder’s sanity checks to abort.Metadata fix: Updated the module header to enumerate every variable it generates or consumes (
$should_check_ecs_imds,$ecs_task_metadata,$launch_type,$network_modes,$imds_tool,$imds_token,$imds_roles,$first_role,$imds_http_code,$ecs_block_line,$ecs_host_line,$iptables_cmd,$docker_rules,$aws_exec_env). This aligns with the LinPEAS module syntax requirements so the builder can track variable provenance.Environment variable handling: Replaced the direct use of
$AWS_EXECUTION_ENVwithaws_exec_env=$(printenv AWS_EXECUTION_ENV 2>/dev/null)and documented$aws_exec_envas a generated variable. This prevents the builder from looking for an external module that “defines”AWS_EXECUTION_ENV, while still surfacing the information at runtime.Verification build: Re-ran the build command (timeout 300 s). The build completed successfully, finishing all internal steps and writing the assembled script to
/tmp/linpeas_fat.sh.No further errors occurred, so LinPEAS is ready. Let me know if you need additional tweaks or want the generated script copied elsewhere.
This PR was automatically created by the HackTricks Feed Bot. Please review the implementation carefully and test thoroughly before merging.