ãSecurityHubã«IMDSv2ã«ãããã¨è¦åãåºãããã«ãªã£ãä»æ¥ãã®é ã§ããããã§ãããããIMDSv2ã£ã¦ä½ã¨ããçåãããã®ã§ãç°¡åã«è§£èª¬ãã¦ã¿ã¾ããIMDSv2ã¯ãã¤ã³ã¹ã¿ã³ã¹ã¡ã¿ãã¼ã¿ãµã¼ãã¹ Version 2ã§ããiPhone 3Gã®åã¯ç¡å°ã®iPhoneï¼å代ï¼ã§ãããversion 2ã¨ãããã¨ã¯version 1ãããã¾ããv2 (IMDSv2) ãåºã¦ããçµç·¯ã¨ããã®åä½ã®éãçã«ã¤ãã¦ã®è±ç¥èã§ãã
ã¤ã³ã¹ã¿ã³ã¹ã¡ã¿ãã¼ã¿ã¨ã¯ï¼
ãã¤ã³ã¹ã¿ã³ã¹ã¡ã¿ãã¼ã¿ã¨ã¯ã¤ã³ã¹ã¿ã³ã¹ã«é¢ããæ å ±ï¼ãã¼ã¿ï¼ã§ãå®è¡ä¸ã®ã¤ã³ã¹ã¿ã³ã¹ããcURLãªã©ã®ãã¼ã«ãããªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ï¼http://169.254.169.254ï¼ãå¼ã³åºããã¨ã§åå¾ã§ãã¾ããåå¾ã§ããæ å ±ã¨ã¦ã¯ãã¤ã³ã¹ã¿ã³ã¹IDãèªèº«ã®IPã¢ãã¬ã¹ãæå±ããã»ãã¥ãªãã£ã°ã«ã¼ããªã©ã§ããã¤ã³ã¹ã¿ã³ã¹ã®ä¸ã§å®è¡ããããã°ã©ã ãããã¯AWSã®å種ãµã¼ãã¹ãããã®æ å ±ã使ã£ã¦ä½ããã®å¦çãããæã«å©ç¨ãã¾ãã
ãv1ã¨v2ã®éãã¯ãåå¾ã®ä»æ¹ã§ãã
v1ã¯æ¬¡ã®ããã«åç´ã«URLãå©ãã ãã§åå¾ã§ãã¾ãã
v2ã¯ããªã¯ã¨ã¹ãã®ãããã¼ã«æå¹æéãªã©ãå ã«ãããã¼ã¯ã³ãåãè¾¼ãå¿ è¦ãããã¾ãã
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` \
&& curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/
Capital Oneã襲ã£ãSSRFæ»æã¨ã¤ã³ã¹ã¿ã³ã¹ã¡ã¿ãã¼ã¿
ãããã§ã¯ä½æ v2ã¯ããããããã¼ã¯ã³ãåãè¾¼ãã§åå¾ãã«ãããã¦ããã®ã§ãããï¼ãã®èæ¯ãç¥ãããã«ãCapital Oneã襲ã£ãSSRFæ»æã®äºä»¶ãç´¹ä»ãã¾ããäºä»¶ã®æ¦è¦ãç°¡åã«èª¬æããã¨ãæ»æè ã¯WAFã®èå¼±æ§ãå©ç¨ãã¦IAM Roleãè¨å®ããã¦ããã¤ã³ã¹ã¿ã³ã¹ã«Server Side Request Forgeryï¼SSRFï¼æ»æãä»æããã¤ã³ã¹ã¿ã³ã¹ã¡ã¿ãã¼ã¿ãå©ç¨ãã¦IAMã®ã¯ã¬ãã³ã·ã£ã«æ å ±ãåå¾ãã¾ããããã®ã¯ã¬ãã³ã·ã£ã«ãå©ç¨ãã¦ãS3ã«ã¢ã¯ã»ã¹ãã¦å¤§éã®ãã¼ã¿ãçãã ã¨ããäºä»¶ã§ãã
Capital Oneの個人情報流出事件に思うこと - プログラマでありたい
ããã®äºä»¶ã«ã¯å¹¾ã¤ããã¤ã³ããããã®ã§ããããã®ãã¡ã®ä¸ã¤ãã¤ã³ã¹ã¿ã³ã¹ã¡ã¿ãã¼ã¿ãéãã¦IAMãã¼ã«ã®ä¸æçãªã¢ã¯ã»ã¹ãã¼ã»ã·ã¼ã¯ã¬ããï¼ã¯ã¬ãã³ã·ã£ã«ï¼ãåå¾ããããããæªç¨ãããäºã«ããã¾ãã
ãã¤ã³ã¹ã¿ã³ã¹ã¡ã¿ãã¼ã¿ããã¯ã¬ãã³ã·ã£ã«ãåå¾ã§ããäºèªä½ã¯ãã¤ã³ã¹ã¿ã³ã¹ã¡ã¿ãã¼ã¿ãµã¼ãã¹ã®ä»æ§ãªã®ã§ããèªä½ã¯åé¡ããã¾ãããåé¡ã¯ããã®ãã¼ã¿ãç°¡åã«åå¾ã§ããã®ã§ãSSRFæ»æãåããæã«æªç¨ãããããã¨ããç¹ã§ãããã®æ¹åã¨ãã¦v2ãåºã¦ã¾ãããv2ããã¨ãã¨è¨ç»ãã¦ããã®ããCapital Oneãåãã¦ä½ã£ãã®ãã¯ä¸æã§ãããã GCPã®ã¡ã¿ãã¼ã¿ã®åå¾ã¯v2çãªåãã§ãAWSããããã¦æ¬²ããã¨ãã話ã¯ä»¥åããããã¾ããã
ã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ãã¦v1ã»v2ãæå®ãã¦è¨å®ãã
ãã¤ã³ã¹ã¿ã³ã¹ã¡ã¿ãã¼ã¿ãµã¼ãã¹ã®ãã¼ã¸ã§ã³ã®æå®ã¯ãã¤ã³ã¹ã¿ã³ã¹èµ·åæã«æå®ã§ãã¾ããv2ãåºãå½åã¯ãCLIã§ã®èµ·åã®ã¿æå®å¯è½ã§ãããä»ã ã¨ããã¸ã¡ã³ãã³ã³ã½ã¼ã«ããã§ãæå®ã§ããããã«ãªã£ã¦ãã¾ããã¤ã³ã¹ã¿ã³ã¹ã®è©³ç´°è¨å®ã®é«åº¦ãªè©³ç´°ï¼ã©ããªæ¥æ¬èªã ãï¼ã®Metadata Versionã§æå®ã§ãã¾ããããã©ã«ãã¯v1ã¨v2ã®ä¸¡æ¹ã使ãããã®ã§ãv2ã®ã¿ä½¿ãããã®ãæå®ã§ãã¾ããã¾ããMetadata accessibleã§ãã¡ã¿ãã¼ã¿èªä½ã«ã¢ã¯ã»ã¹ã§ããªãããã«ãããã¨ãã§ãã¾ãã
v1ã¨v2ã®æåã®ç¢ºèª
ãããã§ã¯ãå®éã«v1ã¨v2ã®è¨å®ãããã¤ã³ã¹ã¿ã³ã¹ã§ãããããã®æåã確èªãã¦ã¿ã¾ããããã¾ãã¯ãv1è¨å®ã®ã¤ã³ã¹ã¿ã³ã¹ã§ãã
åç´ãªcurlã³ãã³ãã§ã®åå¾
$ curl http://169.254.169.254/latest/meta-data/ami-id/
ami-0ce107ae7af2e92b5
ãæåãã¾ããã
次ã«v2ã«å¯¾å¿ãããã¼ã¯ã³åãè¾¼ã¿ã§ã®åå¾
$ TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/ami-id/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 56 100 56 0 0 11200 0 --:--:-- --:--:-- --:--:-- 11200Trying 169.254.169.254...
TCP_NODELAY set
Connected to 169.254.169.254 (169.254.169.254) port 80 (#0)
> GET /latest/meta-data/ami-id/ HTTP/1.1
> Host: 169.254.169.254
> User-Agent: curl/7.61.1
> Accept: */*
> X-aws-ec2-metadata-token: AQAAAMVnM-DonAFD57_6PRycSd7L-6KgnwwOK2i352oj2ir7dYa85g==
>HTTP 1.0, assume close after body
< HTTP/1.0 200 OK< Accept-Ranges: bytes< Content-Length: 21< Content-Type: text/plain< Date: Tue, 29 Sep 2020 15:32:45 GMT< Last-Modified: Tue, 29 Sep 2020 15:03:15 GMT< X-Aws-Ec2-Metadata-Token-Ttl-Seconds: 21600< Connection: close< Server: EC2ws<
Closing connection 0
ãè¦ãæ¹ãéããã©ãæåãã¦ãã¾ãã
v1,v2ã®ã©ã¡ãã®ã³ãã³ãã§ãåå¾ã§ãããã¨ã確èªã§ãã¾ããã
次ã«v2è¨å®ã®ã¤ã³ã¹ã¿ã³ã¹ã§ãv1ã§åå¾ããéã«å©ç¨ããåç´ãªcurlã³ãã³ãã§ã®åå¾ãã¦ã¿ã¾ãã
$ curl http://169.254.169.254/latest/meta-data/ami-id/ <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>401 - Unauthorized</title> </head> <body> <h1>401 - Unauthorized</h1> </body> </html>
ã401 Unauthorizedã§æ¨©éããªãããã«ã¨ã©ã¼ãã§ã¦ãã¾ãã
ã¨ãããã¨ã§ãv2ã«è¨å®ãã¦ããã¨ãã¼ã¯ã³ãåãè¾¼ã¾ãªãã¨åå¾ã§ããªããã¨ã解ãã¾ããã
ãv1ããv2ã«å¤æ´ããå ´åãAWSã®æ©è½ã»ãµã¼ãã¹ã§å¼ã¶åºãã¦ããã¨ããã¯å½±é¿ãªãã§ãããèªåã§ã¡ã¿ãã¼ã¿ãåå¾ããããã°ã©ã ã»ã³ãã³ããä½ã£ã¦ããå ´åã¯å¤æ´ãå¿ è¦ã§ãã
v2 (IMDSv2) ãè¨å®ããå ´åã®ã»ãã¥ãªãã£çãªå¹æã¯ï¼
ãããã§ã¯ãv2 (IMDSv2) ãè¨å®ããã¨ã»ãã¥ãªãã£çã«ã©ããã£ãå¹æãããã®ã§ããããï¼AWSãã¯ã©ã¹ã¡ã½ããè¼ç°ããã®ããã°ã«ããéããå¹¾ã¤ãã®å¹æãããã¾ãã
- 誤ã£ã¦è¨å®ããã Web ã¢ããªã±ã¼ã·ã§ã³ãã¡ã¤ã¢ã¦ã©ã¼ã«ããã®ä¿è·
- 誤ã£ã¦è¨å®ããããªãã¼ã¹ãããã·ããã®ä¿è·
- SSRF èå¼±æ§ããã®ä¿è·
- 誤ã£ã¦è¨å®ãããã¬ã¤ã¤ï¼ãã¡ã¤ã¢ã¦ã©ã¼ã«ãNAT æ©å¨ããã®ä¿è·
ãv2ã使ãã¨ä½æ é²ããã®ãã¨ããã¨ããããã¼ãæ¤è¨¼ããããã«ãªã£ã¦ããã®ã§X-Forwarded-Forãå ¥ã£ã¦ããã¨ãã¼ã¯ã³ãçºè¡ããªããªã©ã®å¹¾ã¤ãã®ä»æ§ãã¯ãã£ã¦ããããã§ãã詳ããã¯ããã°ã確èªãã¦ãã ããã
å®éãã©ããããã®å¹æãããã®ãï¼
ãããã§ã¯ãv2 (IMDSv2) ã«ããå ´åã«ã©ããããã®å¹æãããã®ã§ããããï¼ããã¯SSRFçã®é²æ¢çã§ã¯ãªãç·©åçã¨èªèãã¦ãã¾ããã¤ã¾ãåç´ãªæ»æããã®è¢«å®³ãé²ãããã©ããã£ã¨æ¬æ°ãåºããæ»æã¯é²ãã¾ããããã®ãããã¯å¾³ä¸¸ããã詳細ææãã¦ãã¾ãã
ã対çã¨ãã¦å¤§äºãªã®ã¯ãè¨è¨ã¬ãã«ã§ããããã®ãµã¼ãã¹ã«é²å¾¡ãçãè¾¼ããã¨ã ã¨æãã¾ããä¾ãã°ãã¤ã³ã¹ã¿ã³ã¹ã«ä»ä¸ããIAMãã¼ã«ã«ã¯æå°æ¨©éã«çµãã¨ããåå¾ãããå ã®S3ãã±ããã¯ãã±ããããªã·ã¼ã§æ¥ç¶å ãçµãè¾¼ããªã©ãããã¾ãããã®ãããã¯ãéå»ã«ã¾ã¨ãã¦ãã¾ãã
ãä»å¾ä½ãã¤ã³ã¹ã¿ã³ã¹ã«ã¤ãã¦ã¯ãv2 (IMDSv2) ã«ãã¹ãã ã¨æãã¾ããã¾ãIAMããªã·ã¼ã§ãIMDSv2ãå¼·å¶ããã¨ãããã¨ãã§ãã¾ãããã ãããã®è¨å®ããã¦ããã°å®å¿ã¨ãã代ç©ã§ã¯ãªãã¨ãããã¨ã¯ãã£ããèªèãã¦ããã¾ããããããããã®ã¬ã¤ã¤ã¼ã§ãåºæ¥ããéãã®è¨è¨ã»é²å¾¡ããã¦ããã¨ãã観ç¹ããã£ã¦ããã¾ããããã§ãIAMã¨ãAWSã®ã»ãã¥ãªãã£ãµã¼ãã¹ã解ããã¨ããæ¹ã¯ããå§ãã®æ¬ãããã¾ããã¨ããã¹ããã§çµãããã¦é ãã¾ããç¾å ´ããã¯ä»¥ä¸ã§ãï¼ï¼