Content Script (content_script.js)
Relevant source files
The following files were used as context for generating this wiki page:The content_script.js is a core component of the PPScan extension, responsible for executing client-side prototype pollution scans on web pages. As defined in manifest.json, it is injected into all URLs (<all_urls>) and frames (all_frames: true), allowing it to operate directly within the context of the visited page. Its primary function is to check for prototype pollution vulnerabilities, both automatically upon page load (if "Active Mode" is enabled) and manually when triggered by the user from the extension's popup.
This script orchestrates the scanning process by creating a hidden iframe that loads exp.js, a script containing the actual pollution payloads and gadget lists. It communicates with this iframe via postMessage to initiate different scanning phases. Upon discovering a vulnerability, it reports the findings back to the background script (background.js) for logging and display in the popup UI.
Sources: scripts/content_script.js, manifest.json:17-25
Architecture and Execution Flow
The content script's execution is conditional, based on the toggle state stored in chrome.storage.sync. If "Active Mode" is enabled, the script proceeds with its main logic.
Sources: scripts/content_script.js:35-36
Initialization
The script's initialization involves several key steps:
- Configuration Check: It first queries
chrome.storage.syncfor thetogglekey to determine if active scanning is enabled. - Code Injection: If active, it wraps its primary detection logic (
checkfunction) into a self-executing function and injects it as a<script>tag into the page's DOM. This is done to execute the detection logic within the page's own JavaScript context, which is necessary to check the state ofObject.prototype. - Iframe Orchestrator: It creates a hidden iframe (
id="ppbada55") that loads/pages/iframe.html. This iframe acts as a sandboxed environment for running the exploit payloads fromexp.js. - Initial Scan Trigger: After the iframe loads, the content script sends it a message with
{ foo: "bar" }to begin the initial, automatic prototype pollution check. - Event Forwarding: It sets up a listener for a custom
PPLogevent. When this event is dispatched by the injected script, the listener forwards the vulnerability details tobackground.jsusingchrome.runtime.sendMessage.
The following diagram illustrates this initialization and automatic scanning flow.
Scanning Triggers
The content script listens for custom events dispatched from the popup UI to initiate manual scans. This allows the user to trigger more intensive gadget brute-forcing on demand.
Manual Gadget Brute-Forcing
The popup UI (popup.html and popup.js) contains "Search" and "Hash" buttons that trigger gadget scanning. When a user clicks one of these buttons, popup.js executes a small script in the active tab to dispatch a custom event.
| Event Name | Triggered By | Purpose |
|---|---|---|
TriggerBrute | "Search" button | Initiates a gadget scan where payloads are placed in the URL search query. |
TriggerBruteHash | "Hash" button | Initiates a gadget scan where payloads are placed in the URL hash. |
Sources: scripts/popup.js:68-77, scripts/content_script.js:1-24
The content script has event listeners for both TriggerBrute and TriggerBruteHash. When an event is caught, the script creates the hidden iframe and posts a message with { foo: 'baz' } and a type of either 'search' or 'hash'. This instructs exp.js in the iframe to iterate through its GADGETS list and test them against the target URL.
This diagram shows the flow initiated from the popup UI.
Vulnerability Detection and Reporting
The core detection logic is executed by the script that content_script.js injects directly into the page.
Injected Detection Logic
The inject variable holds the code that runs in the page's context. Its responsibilities are:
- Periodic Check: It uses
setIntervalto check for the existence of specific properties (e32a5ec9c99ora0def12bce) onObject.prototypeevery 5 seconds. - onload Check: It also checks for these properties when the
window.onloadevent fires. - Logging: If a property is found, it logs a message to the console and calls a local
loggerfunction. - Custom Event Dispatch: The
loggerfunction creates and dispatches aCustomEventnamedPPLog, with the currentlocation.hrefas its detail.
// Source: scripts/content_script.js:82-89
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);
Reporting Flow
The reporting mechanism decouples the detection (in the page's context) from the communication with the extension's background script (in the content script's isolated world).
This flow is visualized below:
Frame Busting Countermeasures
The script includes special logic to handle sites that use "frame busting" techniques, which prevent them from being loaded inside an iframe. This is primarily handled by the "Window Mode" feature, which opens the target URL in a new window instead of an iframe.
The injected script checks if the string "dummy" is present in the URL. This acts as a flag to engage a multi-step testing process designed to work in a top-level window rather than a frame. It manipulates the URL with different test payloads and reloads the page, checking for pollution at each step. This logic is complex and appears tailored to bypass specific anti-framing implementations.