Core Scanning Mechanism
Relevant source files
The following files were used as context for generating this wiki page:The core scanning mechanism of PPScan is designed to detect client-side prototype pollution vulnerabilities. It operates through two primary modes: a "Passive Mode" for identifying potentially vulnerable code patterns in JavaScript files, and an "Active Mode" for injecting payloads to confirm vulnerabilities. The extension also includes a manual "Gadget Brute-Forcing" feature to test for exploitable gadgets on a vulnerable page.
The mechanism is implemented across several components of the browser extension, including a background script for network monitoring and state management, content scripts for interacting with web pages, and a dedicated script within an iframe for payload delivery and testing.
Architecture Overview
The extension's functionality is distributed among background scripts, content scripts, and UI components. The background script orchestrates passive scanning and manages global state, while the content script, in conjunction with a sandboxed iframe, handles active scanning and gadget brute-forcing.
The following diagram illustrates the high-level interaction between these components.
This diagram shows the main components of the extension and their interactions during scanning operations.
Sources: manifest.json, scripts/background.js, scripts/content_script.js, scripts/utils.js
Scanning Modes
PPScan can be configured to run in different modes, which can be controlled from the extension's popup window.
| Mode | UI Toggle | Default State | Description |
|---|---|---|---|
| Passive Mode | Disable Passive Mode / Enable Passive Mode | Enabled | Passively scans JavaScript files for known vulnerable patterns. |
| Active Mode | Disable Active Mode / Enable Active Mode | Disabled | Actively injects payloads into the page to test for prototype pollution. |
| Window Mode | Disable Window Mode / Enable Window Mode | Disabled | A sub-mode of Active Mode, used to bypass frame-busting mechanisms by opening a new window. |
Sources: scripts/popup.js:5-49, scripts/background.js:27-35
Passive Scanning
When "Passive Mode" is enabled, the extension monitors network requests for JavaScript files. Each script's content is then matched against a database of known vulnerable patterns.
Sources: scripts/utils.js, scripts/background.js:51-53
Data Flow
The passive scanning process is initiated when the extension starts and the mode is enabled.
This flowchart details the process of passive scanning, from initialization to vulnerability detection.
Sources: scripts/utils.js:100-106, scripts/utils.js:113-116, scripts/utils.js:77-98
The patterns are defined in database.csv and loaded into memory. Each pattern has a name, type (regex or text), and the chunk of code to match.
Sources: scripts/utils.js:41-59
Active Scanning
When "Active Mode" is enabled, the content script injects logic into the visited page to actively test for prototype pollution. This involves creating an iframe that loads scripts/exp.js to deliver payloads and then checking if Object.prototype has been polluted.
*Sources: scripts/content_script.js:34-78, scripts/exp.js *
Sequence of Events
The active scan is a multi-step process involving the content script, a dedicated iframe, and the target page itself.
This sequence diagram illustrates the interaction between the content script and the injected iframe to perform an active scan.
Sources: scripts/content_script.js:101-112, scripts/exp.js:82-103, scripts/content_script.js:70-74
The active scan uses a small set of payloads to check for basic pollution vectors.
| Payload Name | Parameter | Value |
|---|---|---|
| XSS Prototype #3 | __proto__[e32a5ec9c99] | ddcb362f1d60 |
| XSS Prototype #4 | __proto__.e32a5ec9c99 | ddcb362f1d60 |
Sources: scripts/exp.js:3-6
Header Modification
To facilitate testing within iframes, Active Mode modifies HTTP response headers to bypass security restrictions like Content-Security-Policy and X-Frame-Options.
// from scripts/background.js
if (isCSPHeader(header)) {
header.value = `default-src * 'unsafe-inline' 'unsafe-eval' data: blob:; `;
};
if (isXFrameEnabled(header)) {
header.name = 'foo'; // Effectively removes the header
};
Sources: scripts/background.js:40-46, scripts/utils.js:124-131
Gadget Brute-Forcing
This is a manual feature triggered from the popup UI. It allows the user to test a list of known exploitation gadgets against a page believed to be vulnerable. The gadgets are applied to the URL's search parameters or hash.
Sources: scripts/popup.js:51-62, scripts/content_script.js:1-24, scripts/exp.js:9-41
Flow of Gadget Testing
This flowchart shows how the gadget brute-forcing feature is initiated and executed.
Sources: scripts/popup.js:51-62, scripts/content_script.js:1-24, scripts/exp.js:44-71
A large list of over 30 gadgets is defined in scripts/exp.js to test for various RCE and XSS vectors that can be triggered via prototype pollution.
Sources: scripts/exp.js:9-41
Vulnerability Reporting
When a vulnerability is found, either through passive or active scanning, the finding is logged.
- Passive Scan: A
found.add()call inutils.jsstores the domain, finding type, file, and line number. - Active Scan: The injected script in
content_script.jsdispatches aPPLogevent, which is then sent tobackground.jsviachrome.runtime.sendMessage. - Display: The
background.jsscript maintains aSetof found vulnerabilities. The popup UI requests this list from the background script and displays it in a table. The browser action icon's badge is also updated with the count of found vulnerabilities.
Sources: scripts/utils.js:95-97, scripts/content_script.js:115-117, scripts/background.js:9-12, scripts/popup.js:68-72, pages/popup.html:86-92