|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>Client-Side Logic Lab</title> |
| 7 | + <style> |
| 8 | + body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; } |
| 9 | + .lab-section { border: 1px solid #ccc; padding: 20px; margin-bottom: 20px; border-radius: 5px; } |
| 10 | + h2 { color: #d32f2f; } |
| 11 | + pre { background: #f4f4f4; padding: 10px; border-radius: 5px; } |
| 12 | + button { background: #007bff; color: white; border: none; padding: 10px 20px; cursor: pointer; } |
| 13 | + button:hover { background: #0056b3; } |
| 14 | + input { padding: 10px; width: 300px; } |
| 15 | + .result { margin-top: 10px; font-weight: bold; } |
| 16 | + </style> |
| 17 | +</head> |
| 18 | +<body> |
| 19 | + <h1>Client-Side Logic & Prototype Pollution</h1> |
| 20 | + |
| 21 | + <!-- Lab 1: DOM Clobbering --> |
| 22 | + <div class="lab-section"> |
| 23 | + <h2>Lab 1: DOM Clobbering</h2> |
| 24 | + <p>Goal: Inject HTML to clobber the global <code>config</code> variable and force the application to load a malicious script (or simulate it).</p> |
| 25 | + <p>The application runs this logic:</p> |
| 26 | + <pre> |
| 27 | +window.onload = function() { |
| 28 | + let scriptUrl = window.config?.scriptUrl || 'default.js'; |
| 29 | + document.getElementById('current-script').innerText = "Loading script: " + scriptUrl; |
| 30 | +}; |
| 31 | + </pre> |
| 32 | + |
| 33 | + <!-- Vulnerable Output Sink --> |
| 34 | + <div id="user-content"> |
| 35 | + <!-- This simulates user-controlled content being rendered without proper sanitization --> |
| 36 | + <!-- In a real scenario, this would be an XSS sink or content injection point --> |
| 37 | + <!-- For this lab, enter HTML below to see it rendered here --> |
| 38 | + </div> |
| 39 | + |
| 40 | + <h3>Inject HTML:</h3> |
| 41 | + <textarea id="html-input" rows="4" cols="50" placeholder="Enter HTML here (e.g. <a id=config>...</a>)"></textarea><br> |
| 42 | + <button onclick="renderUserHtml()">Inject & Reload</button> |
| 43 | + |
| 44 | + <p>Current Status: <span id="current-script">Waiting...</span></p> |
| 45 | + </div> |
| 46 | + |
| 47 | + <!-- Lab 2: Prototype Pollution --> |
| 48 | + <div class="lab-section"> |
| 49 | + <h2>Lab 2: Server-Side Prototype Pollution</h2> |
| 50 | + <p>Goal: Pollute the server-side Object prototype to gain Admin access.</p> |
| 51 | + <p>Send a JSON payload to merge settings. If successful, <code>isAdmin</code> will become true for all objects.</p> |
| 52 | + |
| 53 | + <h3>Update Settings:</h3> |
| 54 | + <textarea id="json-input" rows="4" cols="50">{"theme": "dark"}</textarea><br> |
| 55 | + <button onclick="sendUpdate()">Send Update</button> |
| 56 | + |
| 57 | + <div id="server-response" class="result"></div> |
| 58 | + <br> |
| 59 | + <button onclick="checkAdmin()">Check Admin Access</button> |
| 60 | + <div id="admin-status" class="result"></div> |
| 61 | + </div> |
| 62 | + |
| 63 | + <script> |
| 64 | + // Vulnerable DOM Clobbering Logic |
| 65 | + function renderUserHtml() { |
| 66 | + const input = document.getElementById('html-input').value; |
| 67 | + // DANGEROUS: Directly setting innerHTML (simulating an XSS/injection sink) |
| 68 | + document.getElementById('user-content').innerHTML = input; |
| 69 | + |
| 70 | + // Re-run the vulnerable logic to see if 'config' was clobbered |
| 71 | + setTimeout(() => { |
| 72 | + let scriptUrl = 'default.js'; |
| 73 | + |
| 74 | + // Vulnerable check |
| 75 | + if (window.config && window.config.scriptUrl) { |
| 76 | + scriptUrl = window.config.scriptUrl; |
| 77 | + |
| 78 | + // Note: In real DOM clobbering with <a> tags, toString() gives the href. |
| 79 | + // We simulate this behavior check. |
| 80 | + if (typeof scriptUrl === 'object') { // It might be an element collection if clobbered |
| 81 | + scriptUrl = scriptUrl.toString(); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + document.getElementById('current-script').innerText = "Loading script: " + scriptUrl; |
| 86 | + |
| 87 | + if (scriptUrl.includes('malicious')) { |
| 88 | + alert("DOM Clobbering Successful! Malicious script path detected."); |
| 89 | + } |
| 90 | + }, 100); |
| 91 | + } |
| 92 | + |
| 93 | + // Prototype Pollution Logic |
| 94 | + async function sendUpdate() { |
| 95 | + const input = document.getElementById('json-input').value; |
| 96 | + try { |
| 97 | + const json = JSON.parse(input); |
| 98 | + const response = await fetch('/api/update-settings', { |
| 99 | + method: 'POST', |
| 100 | + headers: { 'Content-Type': 'application/json' }, |
| 101 | + body: JSON.stringify(json) |
| 102 | + }); |
| 103 | + const result = await response.json(); |
| 104 | + document.getElementById('server-response').innerText = JSON.stringify(result, null, 2); |
| 105 | + } catch (e) { |
| 106 | + document.getElementById('server-response').innerText = "Error: " + e.message; |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + async function checkAdmin() { |
| 111 | + try { |
| 112 | + const response = await fetch('/api/admin-check'); |
| 113 | + const result = await response.json(); |
| 114 | + document.getElementById('admin-status').innerText = result.message; |
| 115 | + if(result.flag) { |
| 116 | + document.getElementById('admin-status').innerText += "\n" + result.flag; |
| 117 | + document.getElementById('admin-status').style.color = "green"; |
| 118 | + } |
| 119 | + } catch (e) { |
| 120 | + document.getElementById('admin-status').innerText = "Error: " + e.message; |
| 121 | + } |
| 122 | + } |
| 123 | + </script> |
| 124 | +</body> |
| 125 | +</html> |
| 126 | + |
0 commit comments