-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevtools-detector.js
More file actions
240 lines (208 loc) · 7.48 KB
/
devtools-detector.js
File metadata and controls
240 lines (208 loc) · 7.48 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
// <script src="devtools-detector.js"></script>
// DevTools Detection dan Auto Close Tab
class DevToolsDetector {
constructor() {
this.isDetected = false;
this.threshold = 160; // Threshold untuk mendeteksi devtools
this.methods = [];
this.init();
}
init() {
// Method 1: Console.log timing detection
this.methods.push(() => this.consoleTimingDetection());
// Method 2: Window size detection
this.methods.push(() => this.windowSizeDetection());
// Method 3: debugger statement detection
this.methods.push(() => this.debuggerDetection());
// Method 4: toString override detection
this.methods.push(() => this.toStringDetection());
// Method 5: Console properties detection
this.methods.push(() => this.consolePropertiesDetection());
// Start monitoring
this.startMonitoring();
}
// Method 1: Console timing detection
consoleTimingDetection() {
let start = performance.now();
console.log('%c', 'color: transparent');
let end = performance.now();
return (end - start) > 5; // Jika console terbuka, akan lebih lambat
}
// Method 2: Window size detection
windowSizeDetection() {
const heightThreshold = window.outerHeight - window.innerHeight > this.threshold;
const widthThreshold = window.outerWidth - window.innerWidth > this.threshold;
return heightThreshold || widthThreshold;
}
// Method 3: Debugger detection
debuggerDetection() {
try {
let start = performance.now();
debugger;
let end = performance.now();
return (end - start) > 100; // Jika devtools terbuka, debugger akan pause
} catch (e) {
return false;
}
}
// Method 4: toString override detection
toStringDetection() {
let detected = false;
const element = document.createElement('div');
Object.defineProperty(element, 'id', {
get: function() {
detected = true;
return 'detected';
}
});
console.log(element);
return detected;
}
// Method 5: Console properties detection
consolePropertiesDetection() {
try {
return !!(window.console &&
(console.firebug ||
console.exception ||
console.table ||
(console.profiles && console.profiles.length > 0)));
} catch (e) {
return true;
}
}
// Function untuk menutup tab
closeTab() {
// Method 1: window.close()
try {
window.close();
} catch (e) {
console.log('Cannot close tab with window.close()');
}
// Method 2: Redirect ke blank page
try {
window.location.href = 'about:blank';
} catch (e) {
console.log('Cannot redirect to blank page');
}
// Method 3: Self-destruct DOM
try {
document.body.innerHTML = '<h1>Access Denied</h1><p>Developer tools detected. Page closed for security.</p>';
document.head.innerHTML = '<title>Access Denied</title>';
} catch (e) {
console.log('Cannot modify DOM');
}
// Method 4: Infinite loop untuk crash tab (extreme measure)
setTimeout(() => {
while(true) {
history.pushState(null, null, Math.random().toString());
}
}, 1000);
}
// Function untuk mengecek semua metode deteksi
checkDevTools() {
let detectionCount = 0;
this.methods.forEach(method => {
try {
if (method()) {
detectionCount++;
}
} catch (e) {
// Jika ada error, anggap sebagai deteksi
detectionCount++;
}
});
// Jika 2 atau lebih metode mendeteksi devtools
return detectionCount >= 2;
}
// Start monitoring
startMonitoring() {
// Check every 500ms
setInterval(() => {
if (!this.isDetected && this.checkDevTools()) {
this.isDetected = true;
console.log('Developer Tools detected! Closing tab...');
this.closeTab();
}
}, 500);
// Additional event listeners
document.addEventListener('keydown', (e) => {
// F12, Ctrl+Shift+I, Ctrl+Shift+J, Ctrl+U
if (e.keyCode === 123 ||
(e.ctrlKey && e.shiftKey && (e.keyCode === 73 || e.keyCode === 74)) ||
(e.ctrlKey && e.keyCode === 85)) {
e.preventDefault();
if (!this.isDetected) {
this.isDetected = true;
this.closeTab();
}
return false;
}
});
// Context menu disable
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
return false;
});
// Additional protection against common devtools shortcuts
document.addEventListener('keydown', (e) => {
if ((e.ctrlKey && e.shiftKey && e.keyCode === 67) || // Ctrl+Shift+C
(e.ctrlKey && e.shiftKey && e.keyCode === 75)) { // Ctrl+Shift+K
e.preventDefault();
if (!this.isDetected) {
this.isDetected = true;
this.closeTab();
}
return false;
}
});
}
// Method untuk disable text selection dan drag
disableSelection() {
document.onselectstart = () => false;
document.ondragstart = () => false;
document.oncontextmenu = () => false;
document.body.style.webkitUserSelect = 'none';
document.body.style.mozUserSelect = 'none';
document.body.style.msUserSelect = 'none';
document.body.style.userSelect = 'none';
}
}
// Anti-tampering protection
(function() {
'use strict';
// Prevent script modification
Object.freeze(DevToolsDetector);
Object.freeze(DevToolsDetector.prototype);
// Initialize detector when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
const detector = new DevToolsDetector();
detector.disableSelection();
// Hide detector instance
Object.defineProperty(window, 'detector', {
value: detector,
writable: false,
configurable: false
});
});
} else {
const detector = new DevToolsDetector();
detector.disableSelection();
Object.defineProperty(window, 'detector', {
value: detector,
writable: false,
configurable: false
});
}
// Console warning
console.log('%cSTOP!', 'color: red; font-size: 50px; font-weight: bold;');
console.log('%cThis is a browser feature intended for developers. Developer tools access is not allowed on this page.', 'color: red; font-size: 16px;');
})();
// Additional obfuscation and protection
setInterval(() => {
if (window.outerHeight - window.innerHeight > 200 ||
window.outerWidth - window.innerWidth > 200) {
document.body.innerHTML = '';
window.location.href = 'about:blank';
}
}, 100);