Repository navigation
Expand file tree
/
Copy pathbackground.js
More file actions
392 lines (326 loc) · 11 KB
/
Copy pathbackground.js
File metadata and controls
392 lines (326 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
// background.js - Service Worker para la extensión HackBar
// Importar módulos (solo si estamos en un contexto tipo worker)
if (typeof importScripts === 'function') {
importScripts('config/payloads.js', 'utils/encoding.js');
}
// Estado global
const state = {
currentUrl: '',
postData: '',
referrer: '',
history: []
};
// ============================================
// MANEJADOR DE MENSAJES
// ============================================
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
console.log('[HackBar] Message received:', message.action);
handleMessage(message, sender)
.then(response => sendResponse(response))
.catch(error => {
console.error('[HackBar] Error:', error);
sendResponse({ error: error.message });
});
return true; // Mantener el canal abierto para respuestas asíncronas
});
// ============================================
// MANEJADOR PRINCIPAL
// ============================================
async function handleMessage(message, sender) {
switch (message.action) {
// URL Operations
case 'getCurrentUrl':
return await getCurrentUrl();
case 'splitUrl':
return splitUrl(message.url);
case 'loadUrl':
return await loadUrl(message.url, message.postData, message.referrer);
// Encoding/Decoding
case 'encodeText':
return await encodeText(message.text, message.method);
// Hashing
case 'hashText':
return await hashText(message.text, message.algorithm);
// SQL Generation
case 'generateSQL':
return await generateSQL(message.type, message.params);
// XSS Generation
case 'generateXSS':
return await generateXSS(message.type, message.params);
// State Management
case 'getState':
return state;
case 'updateState':
return updateState(message.updates);
default:
throw new Error(`Unknown action: ${message.action}`);
}
}
// ============================================
// URL OPERATIONS
// ============================================
async function getCurrentUrl() {
try {
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
if (tabs.length > 0) {
state.currentUrl = tabs[0].url;
return tabs[0].url;
}
return '';
} catch (error) {
console.error('[HackBar] Error getting current URL:', error);
return '';
}
}
function splitUrl(url) {
try {
if (!url) return '';
// Parsear la URL
const urlObj = new URL(url);
let result = urlObj.origin + urlObj.pathname;
// Agregar parámetros en líneas separadas
if (urlObj.search) {
const params = new URLSearchParams(urlObj.search);
result += '\n';
for (const [key, value] of params) {
result += `${key}=${value}\n`;
}
}
return result;
} catch (error) {
console.error('[HackBar] Error splitting URL:', error);
return url;
}
}
async function loadUrl(url, postData = '', referrer = '') {
try {
const tabs = await browser.tabs.query({ active: true, currentWindow: true });
if (tabs.length === 0) {
return { success: false, error: 'No active tab found' };
}
const tabId = tabs[0].id;
// Si hay POST data, necesitamos usar un enfoque diferente
if (postData) {
// Inyectar script para hacer POST request
await browser.tabs.executeScript(tabId, {
code: `
(function() {
const form = document.createElement('form');
form.method = 'POST';
form.action = '${url}';
${postData.split('&').map(pair => {
const [key, value] = pair.split('=');
return `
const input_${key} = document.createElement('input');
input_${key}.type = 'hidden';
input_${key}.name = '${key}';
input_${key}.value = '${decodeURIComponent(value || '')}';
form.appendChild(input_${key});
`;
}).join('\n')}
document.body.appendChild(form);
form.submit();
})();
`
});
} else {
// Simple GET request
await browser.tabs.update(tabId, { url: url });
}
// Guardar en historial
state.history.push({
url: url,
postData: postData,
referrer: referrer,
timestamp: Date.now()
});
return { success: true };
} catch (error) {
console.error('[HackBar] Error loading URL:', error);
return { success: false, error: error.message };
}
}
// ============================================
// ENCODING OPERATIONS
// ============================================
async function encodeText(text, method) {
try {
switch (method) {
case 'urlencode':
return EncodingUtils.urlEncode(text);
case 'urldecode':
return EncodingUtils.urlDecode(text);
case 'urlencodeall':
return EncodingUtils.urlEncodeAll(text);
case 'base64encode':
return EncodingUtils.base64Encode(text);
case 'base64decode':
return EncodingUtils.base64Decode(text);
case 'hexencode':
return EncodingUtils.stringToHex(text);
case 'hexdecode':
return EncodingUtils.hexToString(text);
case 'htmlencode':
return EncodingUtils.htmlEntityEncode(text);
case 'htmldecode':
return EncodingUtils.htmlDecode(text);
case 'unicodeencode':
return EncodingUtils.unicodeEncode(text);
case 'unicodedecode':
return EncodingUtils.unicodeDecode(text);
case 'mysqlchar':
return EncodingUtils.toMySQLChar(text);
case 'mssqlchar':
return EncodingUtils.toMSSQLChar(text);
case 'oraclechar':
return EncodingUtils.toOracleChar(text);
default:
return 'Error: Unknown encoding method';
}
} catch (error) {
console.error('[HackBar] Encoding error:', error);
return 'Error: ' + error.message;
}
}
// ============================================
// HASHING OPERATIONS
// ============================================
async function hashText(text, algorithm) {
try {
switch (algorithm.toLowerCase()) {
case 'md5':
return await EncodingUtils.md5(text);
case 'sha1':
return await EncodingUtils.sha1(text);
case 'sha256':
return await EncodingUtils.sha256(text);
case 'sha512':
return await EncodingUtils.sha512(text);
default:
return 'Error: Unknown hash algorithm';
}
} catch (error) {
console.error('[HackBar] Hashing error:', error);
return 'Error: ' + error.message;
}
}
// ============================================
// SQL PAYLOAD GENERATION
// ============================================
async function generateSQL(type, params = {}) {
try {
console.log('[HackBar] Generating SQL:', type, params);
// Navegar por la estructura de PayloadConfig
const parts = type.split('.');
let payload = PayloadConfig.sql;
for (const part of parts) {
if (payload && payload[part]) {
payload = payload[part];
} else {
return 'Error: Payload not found';
}
}
// Si el payload tiene una función generate, llamarla
if (payload && typeof payload.generate === 'function') {
const result = payload.generate(params.value, params.value2);
return result;
}
// Compatibilidad con el sistema antiguo
return generateSQLLegacy(type, params);
} catch (error) {
console.error('[HackBar] SQL generation error:', error);
return 'Error: ' + error.message;
}
}
// Mantener compatibilidad con el sistema antiguo
function generateSQLLegacy(type, params) {
switch (type) {
case 'selectionToUnionSelect':
const columns = params.columns || 10;
const cols = Array.from({length: columns}, (_, i) => i + 1).join(',');
return `+UNION+ALL+SELECT+${cols}`;
case 'UnionSelectGen':
const choice = params.choice || '1';
if (choice === '1') {
return PayloadConfig.sql.union.null.generate(params.columns || 10);
}
return PayloadConfig.sql.union.basic.generate(params.columns || 10);
case 'ErrorBased':
const errorChoice = params.choice || '1';
if (errorChoice === '1') {
return PayloadConfig.sql.errorBased.basic.generate();
} else if (errorChoice === '2') {
return PayloadConfig.sql.errorBased.database.generate();
}
return PayloadConfig.sql.errorBased.version.generate();
case 'char':
const dbEngine = params.dbEngine || 'mysql';
const text = params.text || '[TEXT]';
if (dbEngine === 'mysql') {
return EncodingUtils.toMySQLChar(text);
} else if (dbEngine === 'mssql') {
return EncodingUtils.toMSSQLChar(text);
} else if (dbEngine === 'oracle') {
return EncodingUtils.toOracleChar(text);
}
return 'Error: Unknown database engine';
case 'statement':
const stmtChoice = params.choice || '1';
if (stmtChoice === '1') {
return PayloadConfig.sql.information.version.generate();
}
return 'Error: Unknown statement type';
case 'select':
const selectChoice = params.choice || '3';
if (selectChoice === '3') {
return PayloadConfig.sql.information.databases.generate();
}
return 'Error: Unknown select type';
case 'waf':
const wafChoice = params.choice || '1';
const wafText = params.text || 'SELECT * FROM users';
if (wafChoice === '1') {
return PayloadConfig.sql.wafBypass.comments.generate(wafText);
} else if (wafChoice === '2') {
return PayloadConfig.sql.wafBypass.versionComment.generate(wafText);
}
return PayloadConfig.sql.wafBypass.caseManipulation.generate(wafText);
default:
return 'Error: Unknown SQL payload type';
}
}
// ============================================
// XSS PAYLOAD GENERATION
// ============================================
async function generateXSS(type, params = {}) {
try {
const parts = type.split('.');
let payload = PayloadConfig.xss;
for (const part of parts) {
if (payload && payload[part]) {
payload = payload[part];
} else {
return 'Error: Payload not found';
}
}
if (payload && typeof payload.generate === 'function') {
return payload.generate(params.value);
}
return 'Error: Invalid XSS payload';
} catch (error) {
console.error('[HackBar] XSS generation error:', error);
return 'Error: ' + error.message;
}
}
// ============================================
// STATE MANAGEMENT
// ============================================
function updateState(updates) {
Object.assign(state, updates);
return state;
}
// ============================================
// INITIALIZATION
// ============================================
console.log('[HackBar] Background script loaded');
console.log('[HackBar] Payloads available:', Object.keys(PayloadConfig));