Payload Injection Mechanism
Relevant source files
The following files were used as context for generating this wiki page:The Payload Injection Mechanism is the core feature of the PPScan extension, designed to automatically test websites for client-side Prototype Pollution vulnerabilities. It operates by systematically injecting test payloads into URL query strings and hash fragments. The process is primarily orchestrated through a content script that injects a hidden iframe into the active page. This iframe then generates and loads further iframes containing the payloads, effectively isolating the tests and allowing for different modes of operation, including a "Window Mode" to bypass frame-busting techniques.
The mechanism is initiated either automatically when "Active Mode" is enabled or manually through the extension's popup. It uses a combination of custom DOM events for internal communication on the page and postMessage for cross-origin communication between the main page and the injected iframes. Detected vulnerabilities are reported back to a background script, which updates the extension's badge and logs the finding.
Architecture Overview
The injection process involves several components of the extension working together: the popup UI, a content script injected into the web page, a background script for state management and reporting, and dedicated HTML/JavaScript files for payload execution.
The general flow begins with a trigger, which causes the content script to create a hidden master iframe. This iframe, running exp.js, receives the target URL and proceeds to generate and inject a series of test payloads in new, sandboxed iframes.
This diagram illustrates the high-level sequence of events from user interaction to vulnerability detection.
Injection Triggers
Payload injection can be initiated in several ways, primarily controlled from the extension's popup window.
Sources: pages/popup.html, scripts/popup.js
Manual Brute-force
The user can manually trigger a brute-force scan using a predefined list of "gadgets". The popup UI provides two buttons for this purpose.
| Button ID | Value | Action |
|---|---|---|
brute | Search | Dispatches a TriggerBrute custom event on the active tab to test gadgets in the URL search part. |
brutehash | Hash | Dispatches a TriggerBruteHash custom event to test gadgets in the URL hash part. |
Sources: pages/popup.html:85-91, scripts/popup.js:58-68
When a button is clicked, popup.js executes a content script that dispatches the corresponding event.
// scripts/popup.js:58-62
document.getElementById("brute").onclick = function() {
chrome.tabs.executeScript(null, {
code: `document.dispatchEvent(new CustomEvent('TriggerBrute'));`
});
}
Active Mode Injection
When "Active Mode" is enabled, content_script.js automatically initiates a basic pollution check upon page load. This mode does not use the "gadgets" but a smaller set of PAYLOADS to perform an initial check.
Sources: scripts/content_script.js:33-34, 95-108, scripts/exp.js:80-94
Iframe-based Payload Execution
The core of the injection mechanism relies on creating a hidden iframe to manage and launch the tests. This isolates the scanning logic from the target page's main execution context.
Sources: scripts/content_script.js:1-24, pages/iframe.html, scripts/exp.js
Master Iframe Creation
The content_script.js listens for the TriggerBrute and TriggerBruteHash events. Upon receiving an event, it creates an iframe element, sets its source to a local extension page, and appends it to the document body. This iframe is named ppdeadbeef to prevent recursive injection.
// scripts/content_script.js:1-12
document.addEventListener('TriggerBrute', () => {
var iframe = document.createElement('iframe');
iframe.addEventListener('load', () => {
iframe.contentWindow.postMessage({
url: location.href,
foo: 'baz',
type: 'search'
}, '*');
}, false);
iframe.src = chrome.runtime.getURL('/pages/iframe.html');
iframe.name = "ppdeadbeef";
iframe.style.display = "none";
document.body.appendChild(iframe);
});
The iframe.html page is a simple container that loads the main payload execution script, exp.js.
Sources: pages/iframe.html:8-9, manifest.json:25-28
Payload Dispatch Logic
The exp.js script within the master iframe listens for message events. The logic branches based on the foo property of the received data.
This flowchart shows the decision-making process within exp.js.
Sources: scripts/exp.js:40-94
Gadget Brute-forcing (foo: 'baz')
When triggered manually, content_script.js sends a message with foo: 'baz'. The exp.js script then iterates through the GADGETS array. For each gadget, it creates a new iframe with the gadget appended to either the search parameters or the hash of the target URL, with a 500ms delay between each test.
// scripts/exp.js:10-39 (Sample GADGETS)
var GADGETS = [
'__proto__[innerHTML]=<img/src/onerror=debugger>',
'__proto__[context]=<img/src/onerror%3ddebugger>&__proto__[jquery]=x',
'__proto__[url][]=data:,debugger//&__proto__[dataType]=script',
// ... 28 more gadgets
];
Sources: scripts/exp.js:10-39, 41-65
Initial Check (foo: 'bar')
In "Active Mode", content_script.js sends a message with foo: 'bar'. exp.js then iterates through the PAYLOADS array, testing each one in both the URL search and hash.
// scripts/exp.js:1-8 (PAYLOADS array)
var PAYLOADS = [
['XSS Prototype #3', '__proto__[e32a5ec9c99]', 'ddcb362f1d60', ],
['XSS Prototype #4', '__proto__.e32a5ec9c99', 'ddcb362f1d60', ],
];
Sources: scripts/exp.js:1-8, 80-94
Window Mode for Frame-Busting
If "Window Mode" is enabled (via the buster flag in chrome.storage), the initial check logic changes. Instead of creating an iframe, it uses window.open to launch the test URL in a new window. This is designed to circumvent frame-busting protections that might prevent the site from being loaded in an iframe.
Sources: README.md:27-29, scripts/exp.js:67-77, scripts/popup.js:28-38
Vulnerability Detection and Reporting
Detection is handled by a script injected directly into the target page by content_script.js.
Prototype Checking
The injected script periodically checks for the pollution of Object.prototype with specific keys (e32a5ec9c99 or a0def12bce) that are used in the PAYLOADS array. This check runs on window.onload and is also set up with a setInterval to catch pollution that may occur asynchronously.
// scripts/content_script.js:70-76
var timerID = setInterval(function() {
if ((Object.prototype.e32a5ec9c99 == "ddcb362f1d60" || Object.prototype.a0def12bce == "ddcb362f1d60" || typeof(Object.prototype.a0def12bce)!='undefined' || typeof(Object.prototype.e32a5ec9c99)!='undefined')) {
console.log(`%c--------------------Found one------------------\n${location.href}`, `color:red`);
logger(location.href);
clearInterval(timerID);
}
}, 5 * 1000);
Sources: scripts/content_script.js:37-81
Reporting Flow
If pollution is detected, the logger function is called, which dispatches a PPLog custom event with the vulnerable URL as its detail.
- An event listener in
content_script.jscatches thePPLogevent. - It sends a message containing the vulnerable URL to the background script using
chrome.runtime.sendMessage. - The
background.jsscript receives the message, adds the finding to aSetof found vulnerabilities, and updates the browser action badge count.
// scripts/content_script.js:92-94
document.addEventListener('PPLog', function(event) {
chrome.runtime.sendMessage(event.detail);
});
// scripts/background.js:7-10
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
sourceUrl = new URL(msg);
found.add(JSON.stringify({ domain: sourceUrl.origin, type: 'Active Mode', file: sourceUrl.href, lineCol: 0 }));
setBadgeCount(found.size);
});
Sources: scripts/content_script.js:37-41, 92-94, scripts/background.js:7-10