Skip to content

Commit 440864d

Browse files
committed
Improve in binary search algorithm for parameter optimization
1 parent 3515d72 commit 440864d

File tree

3 files changed

+80
-99
lines changed

3 files changed

+80
-99
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/devploit/dontgo403/issues)
88

9-
Discover hidden debugging parameters and uncover web application secrets with debugHunter. This Chrome extension scans websites for debugging parameters and notifies you when it finds a URL with modified responses.
9+
Discover hidden debugging parameters and uncover web application secrets with debugHunter. This Chrome extension scans websites for debugging parameters and notifies you when it finds a URL with modified responses. The extension utilizes a binary search algorithm to efficiently determine the parameter responsible for the change in the response.
1010

1111
## Features
1212

13-
- Automatically detects URLs with modified responses due to debugging parameters
14-
- Displays a list of URLs with modified responses for easy access
13+
- Perform a binary search on a list of predefined query parameters.
14+
- Compare responses with and without query parameters to identify changes.
15+
- Track and display the number of modified URLs in the browser action badge.
16+
- Allow the user to view and clear the list of modified URLs.
1517

1618
## Installation
1719

@@ -36,7 +38,7 @@ Discover hidden debugging parameters and uncover web application secrets with de
3638

3739
## Usage
3840

39-
It is recommended to pin the extension to the toolbar to check if a new URL debug parameter is found.
41+
It is recommended to pin the extension to the toolbar to check if a new modified URL by debug parameter is found.
4042
1. Navigate to any website.
4143
2. Click on the debugHunter extension icon in the Chrome toolbar.
4244
3. If the extension detects any URLs with modified responses due to debugging parameters, they will be listed in the popup.

background.js

Lines changed: 73 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
// List of query parameters to append
22
const queryParams = [
33
{ key: "_debug", value: "1" },
4-
{ key: "test", value: "1" },
54
{ key: "admin", value: "1" },
6-
{ key: "debug", value: "1" },
7-
{ key: "env", value: "pre" },
8-
{ key: "dev", value: "1" },
9-
{ key: "staging", value: "1" },
5+
{ key: "analysis", value: "1" },
6+
{ key: "beta", value: "1" },
107
{ key: "console", value: "1" },
11-
{ key: "trace", value: "1" },
12-
{ key: "log", value: "1" },
13-
{ key: "verbose", value: "1" },
14-
{ key: "diagnostic", value: "1" },
15-
{ key: "mode", value: "debug" },
16-
{ key: "profiler", value: "1" },
8+
{ key: "debug", value: "1" },
9+
{ key: "debug_flag", value: "1" },
1710
{ key: "debug_mode", value: "1" },
11+
{ key: "debug_output", value: "1" },
12+
{ key: "debug_status", value: "1" },
13+
{ key: "debuginfo", value: "1" },
1814
{ key: "debuglevel", value: "1" },
15+
{ key: "dev", value: "1" },
16+
{ key: "dev_mode", value: "1" },
17+
{ key: "development", value: "1" },
18+
{ key: "diagnostic", value: "1" },
19+
{ key: "env", value: "pre" },
1920
{ key: "error_reporting", value: "1" },
20-
{ key: "show_errors", value: "1" },
21+
{ key: "experiment", value: "1" },
22+
{ key: "internal", value: "1" },
23+
{ key: "log", value: "1" },
24+
{ key: "mode", value: "debug" },
25+
{ key: "monitoring", value: "1" },
2126
{ key: "performance", value: "1" },
22-
{ key: "sandbox", value: "1" },
23-
{ key: "beta", value: "1" },
27+
{ key: "profiler", value: "1" },
2428
{ key: "qa", value: "1" },
25-
{ key: "dev_mode", value: "1" },
26-
{ key: "validate", value: "1" },
27-
{ key: "analysis", value: "1" },
28-
{ key: "experiment", value: "1" },
29+
{ key: "sandbox", value: "1" },
30+
{ key: "show_errors", value: "1" },
31+
{ key: "staging", value: "1" },
32+
{ key: "test", value: "1" },
2933
{ key: "test_mode", value: "1" },
30-
{ key: "debug_flag", value: "1" },
31-
{ key: "development", value: "1" },
32-
{ key: "debuginfo", value: "1" },
33-
{ key: "monitoring", value: "1" },
34-
{ key: "internal", value: "1" },
35-
{ key: "debug_status", value: "1" },
36-
{ key: "debug_output", value: "1" },
3734
{ key: "testing", value: "1" },
35+
{ key: "trace", value: "1" },
36+
{ key: "validate", value: "1" },
37+
{ key: "verbose", value: "1" },
3838
];
3939

4040
// Counter for the number of modified URLs
@@ -93,97 +93,76 @@ function clearModifiedUrls() {
9393
window.getModifiedUrls = getModifiedUrls;
9494
window.clearModifiedUrls = clearModifiedUrls;
9595

96+
// Preprocess Text from responses
97+
function preprocessText(text) {
98+
return text.replace(/\s+/g, '');
99+
}
100+
96101
// Function to check if two responses are meaningfully different
97102
function isDifferentResponse(originalText, modifiedText) {
98-
// Calculate the similarity between the two responses
99-
const similarity = stringSimilarity.compareTwoStrings(originalText, modifiedText);
103+
// Preprocess the texts before comparison
104+
const preprocessedOriginalText = preprocessText(originalText);
105+
const preprocessedModifiedText = preprocessText(modifiedText);
106+
107+
// Calculate the similarity between the two preprocessed responses
108+
const similarity = stringSimilarity.compareTwoStrings(
109+
preprocessedOriginalText,
110+
preprocessedModifiedText
111+
);
100112

101113
// Set a threshold for similarity; responses with similarity below this threshold are considered different
102-
const similarityThreshold = 0.90;
114+
const similarityThreshold = 0.93;
103115

104116
// Return true if the similarity is below the threshold
105117
return similarity < similarityThreshold;
106118
}
107119

108-
// Function to fetch URL and compare responses with and without each parameter
109-
async function checkUrlWithParameters(url, parameters) {
110-
const originalResponse = await fetch(url);
111-
const originalText = await originalResponse.text();
112-
113-
// Check the response with all parameters combined
114-
const combinedUrl = parameters.reduce((currentUrl, param) => {
115-
return appendQueryParam(currentUrl, param);
116-
}, url);
117-
const combinedResponse = await fetch(combinedUrl);
118-
const combinedText = await combinedResponse.text();
119-
120-
if (!isDifferentResponse(originalText, combinedText)) {
121-
// If the response is the same, there is no need to perform the binary search
120+
// Perform the binary search
121+
async function binarySearch(url, includedParams, searchParams, originalText) {
122+
if (searchParams.length === 0) {
122123
return;
123124
}
124125

125-
// Define the start and end indices for the binary search
126-
let startIndex = 0;
127-
let endIndex = parameters.length - 1;
128-
129-
// Perform the binary search
130-
while (startIndex <= endIndex) {
131-
// Calculate the middle index
132-
const middleIndex = Math.floor((startIndex + endIndex) / 2);
133-
134-
// Construct the modified URL using the parameters up to the middle index
135-
const modifiedUrl = parameters.slice(0, middleIndex + 1).reduce((currentUrl, param) => {
136-
return appendQueryParam(currentUrl, param);
137-
}, url);
138-
139-
// Fetch the modified response and compare it to the original response
126+
if (searchParams.length === 1) {
127+
const modifiedUrl = appendQueryParam(url, searchParams[0]);
140128
const modifiedResponse = await fetch(modifiedUrl);
141129
const modifiedText = await modifiedResponse.text();
142-
143130
if (isDifferentResponse(originalText, modifiedText)) {
144-
// If the response is different, add the modified URL and search for more modifications
145131
addModifiedUrl(modifiedUrl);
146-
endIndex = middleIndex - 1;
147-
} else {
148-
// If the response is the same, continue searching in the upper half of the list
149-
startIndex = middleIndex + 1;
150132
}
133+
return;
151134
}
152135

153-
// Check each parameter individually until the first parameter that modifies the response is found
154-
let found = false;
155-
for (const param of parameters) {
156-
const modifiedUrl = appendQueryParam(url, param);
157-
const modifiedResponse = await fetch(modifiedUrl);
158-
const modifiedText = await modifiedResponse.text();
136+
// Calculate the middle index
137+
const middleIndex = Math.floor(searchParams.length / 2);
159138

160-
if (isDifferentResponse(originalText, modifiedText)) {
161-
// If the response is different, add the modified URL to the set
162-
addModifiedUrl(modifiedUrl);
163-
found = true;
164-
break;
165-
}
166-
}
139+
// Construct the modified URL using the includedParams and up to the middle index of searchParams
140+
const modifiedUrl = includedParams.concat(searchParams.slice(0, middleIndex)).reduce((currentUrl, param) => {
141+
return appendQueryParam(currentUrl, param);
142+
}, url);
167143

168-
// If there are only two parameters left and we have a modified response when using only one of them,
169-
// try the other parameter
170-
if (!found && parameters.length === 2) {
171-
const modifiedUrl = appendQueryParam(url, parameters[0]);
172-
const modifiedResponse = await fetch(modifiedUrl);
173-
const modifiedText = await modifiedResponse.text();
144+
// Fetch the modified response and compare it to the original response
145+
const modifiedResponse = await fetch(modifiedUrl);
146+
const modifiedText = await modifiedResponse.text();
147+
148+
if (isDifferentResponse(originalText, modifiedText)) {
149+
// If the response is different, add the modified URL and search for more modifications
150+
addModifiedUrl(modifiedUrl);
151+
await binarySearch(url, includedParams, searchParams.slice(0, middleIndex), originalText);
152+
} else {
153+
// If the response is the same, continue searching in the upper half of the list
154+
await binarySearch(url, includedParams.concat(searchParams.slice(0, middleIndex)), searchParams.slice(middleIndex), originalText);
155+
}
156+
}
174157

175-
if (!isDifferentResponse(originalText, modifiedText)) {
176-
const otherModifiedUrl = appendQueryParam(url, parameters[1]);
177-
const otherModifiedResponse = await fetch(otherModifiedUrl);
178-
const otherModifiedText = await otherModifiedResponse.text();
158+
// Function to check URL with parameters
159+
async function checkUrlWithParameters(url, parameters) {
160+
// Fetch the original response only once
161+
const originalResponse = await fetch(url);
162+
const originalText = await originalResponse.text();
179163

180-
if (isDifferentResponse(originalText, otherModifiedText)) {
181-
addModifiedUrl(otherModifiedUrl);
182-
}
183-
} else {
184-
addModifiedUrl(modifiedUrl);
185-
}
186-
}
164+
// Perform the binary search with the full list of parameters and the original response text
165+
await binarySearch(url, [], parameters, originalText);
187166
}
188167

189168
// Listen for tab updates to perform background checks
@@ -195,4 +174,4 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
195174

196175
// Expose getModifiedUrls and clearModifiedUrls functions to popup
197176
window.getModifiedUrls = getModifiedUrls;
198-
window.clearModifiedUrls = clearModifiedUrls;
177+
window.clearModifiedUrls = clearModifiedUrls;

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "debugHunter",
4-
"version": "1.0.0",
4+
"version": "1.0.2",
55
"description": "Discover hidden debugging parameters and uncover web application secrets",
66
"icons": {
77
"48": "images/icon.png"

0 commit comments

Comments
 (0)