-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-script.js
More file actions
83 lines (71 loc) · 2.33 KB
/
content-script.js
File metadata and controls
83 lines (71 loc) · 2.33 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
// Content Script - 페이지 로드 시 자동 스캔
(async function() {
'use strict';
// 페이지 로드 완료 대기
if (document.readyState === 'loading') {
await new Promise(resolve => {
document.addEventListener('DOMContentLoaded', resolve);
});
}
// 추가 대기 (동적 콘텐츠 로딩을 위해)
await new Promise(resolve => setTimeout(resolve, 1000));
try {
// RSCScanner를 사용하여 스캔 수행
if (typeof window.RSCScanner === 'undefined') {
console.error('RSCScanner가 로드되지 않았습니다');
return;
}
const scanResult = await window.RSCScanner.performScan();
// 결과를 background script로 전송
chrome.runtime.sendMessage({
type: 'SCAN_COMPLETE',
data: scanResult
}, (response) => {
if (chrome.runtime.lastError) {
console.error('메시지 전송 오류:', chrome.runtime.lastError);
} else {
console.log('스캔 결과 전송 완료:', response);
}
});
// 스캔 결과를 로컬 스토리지에도 저장
chrome.storage.local.set({
[`scan_${window.location.hostname}`]: scanResult
});
console.log('React2Shell 스캔 완료:', scanResult);
} catch (error) {
console.error('스캔 중 오류 발생:', error);
// 오류 상황도 background에 전달
chrome.runtime.sendMessage({
type: 'SCAN_ERROR',
data: {
url: window.location.href,
error: error.message
}
});
}
})();
// 메시지 리스너 - popup이나 background에서 재스캔 요청 시
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type === 'RESCAN') {
(async () => {
try {
const scanResult = await window.RSCScanner.performScan();
sendResponse({ success: true, data: scanResult });
} catch (error) {
sendResponse({ success: false, error: error.message });
}
})();
return true; // 비동기 응답을 위해 true 반환
}
if (request.type === 'TEST_VULNERABILITY') {
(async () => {
try {
const testResult = await window.RSCScanner.testVulnerability(window.location.origin);
sendResponse({ success: true, data: testResult });
} catch (error) {
sendResponse({ success: false, error: error.message });
}
})();
return true;
}
});