Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/client/hardware.js
1154 views
1
//
2
// Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
/**
8
* @namespace beef.hardware
9
*/
10
11
beef.hardware = {
12
13
ua: navigator.userAgent,
14
15
/**
16
* @return {String} CPU type
17
*/
18
getCpuArch: function() {
19
var arch = 'UNKNOWN';
20
// note that actually WOW64 means IE 32bit and Windows 64 bit. we are more interested
21
// in detecting the OS arch rather than the browser build
22
if (navigator.userAgent.match('(WOW64|x64|x86_64)') || navigator.platform.toLowerCase() == "win64"){
23
arch = 'x86_64';
24
}else if(typeof navigator.cpuClass != 'undefined'){
25
switch (navigator.cpuClass) {
26
case '68K':
27
arch = 'Motorola 68K';
28
break;
29
case 'PPC':
30
arch = 'Motorola PPC';
31
break;
32
case 'Digital':
33
arch = 'Alpha';
34
break;
35
default:
36
arch = 'x86';
37
}
38
}
39
// TODO we can infer the OS is 64 bit, if we first detect the OS type (os.js).
40
// For example, if OSX is at least 10.7, most certainly is 64 bit.
41
return arch;
42
},
43
44
/**
45
* Returns number of CPU cores
46
* @return {String}
47
*/
48
getCpuCores: function() {
49
var cores = 'unknown';
50
try {
51
if(typeof navigator.hardwareConcurrency != 'undefined') {
52
cores = navigator.hardwareConcurrency;
53
}
54
} catch(e) {
55
cores = 'unknown';
56
}
57
return cores;
58
},
59
60
/**
61
* Returns CPU details
62
* @return {String}
63
*/
64
getCpuDetails: function() {
65
return {
66
arch: beef.hardware.getCpuArch(),
67
cores: beef.hardware.getCpuCores()
68
}
69
},
70
71
/**
72
* Returns GPU details
73
* @return {object}
74
*/
75
getGpuDetails: function() {
76
var gpu = 'unknown';
77
var vendor = 'unknown';
78
// use canvas technique:
79
// https://github.com/Valve/fingerprintjs2
80
// http://codeflow.org/entries/2016/feb/10/webgl_debug_renderer_info-extension-survey-results/
81
try {
82
var getWebglCanvas = function () {
83
var canvas = document.createElement('canvas')
84
var gl = null
85
try {
86
gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl')
87
} catch (e) { }
88
if (!gl) { gl = null }
89
return gl;
90
}
91
92
var glContext = getWebglCanvas();
93
var extensionDebugRendererInfo = glContext.getExtension('WEBGL_debug_renderer_info');
94
var gpu = glContext.getParameter(extensionDebugRendererInfo.UNMASKED_RENDERER_WEBGL);
95
var vendor = glContext.getParameter(extensionDebugRendererInfo.UNMASKED_VENDOR_WEBGL);
96
beef.debug("GPU: " + gpu + " - Vendor: " + vendor);
97
} catch (e) {
98
beef.debug('Failed to detect WebGL renderer: ' + e.toString());
99
}
100
return {
101
gpu: gpu,
102
vendor: vendor
103
}
104
},
105
106
/**
107
* Returns RAM (GiB)
108
* @return {String}
109
*/
110
getMemory: function() {
111
var memory = 'unknown';
112
try {
113
if(typeof navigator.deviceMemory != 'undefined') {
114
memory = navigator.deviceMemory;
115
}
116
} catch(e) {
117
memory = 'unknown';
118
}
119
return memory;
120
},
121
122
/**
123
* Returns battery details
124
* @return {Object}
125
*/
126
getBatteryDetails: function() {
127
var battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery;
128
129
if (!!battery) {
130
return {
131
chargingStatus: battery.charging,
132
batteryLevel: battery.level * 100 + "%",
133
chargingTime: battery.chargingTime,
134
dischargingTime: battery.dischargingTime
135
}
136
} else {
137
return {
138
chargingStatus: 'unknown',
139
batteryLevel: 'unknown',
140
chargingTime: 'unknown',
141
dischargingTime: 'unknown'
142
}
143
}
144
},
145
146
/**
147
* Returns zombie screen size and color depth.
148
* @return {Object}
149
*/
150
getScreenSize: function () {
151
return {
152
width: window.screen.width,
153
height: window.screen.height,
154
colordepth: window.screen.colorDepth
155
}
156
},
157
158
/**
159
* Is touch enabled?
160
* @return {Boolean} true or false.
161
*/
162
isTouchEnabled: function() {
163
if ('ontouchstart' in document) return true;
164
return false;
165
},
166
167
/**
168
* Is virtual machine?
169
* @return {Boolean} true or false.
170
*/
171
isVirtualMachine: function() {
172
if (this.getGpuDetails().vendor.match('VMware, Inc'))
173
return true;
174
175
if (this.isMobileDevice())
176
return false;
177
178
// if the screen resolution is uneven, and it's not a known mobile device
179
// then it's probably a VM
180
if (screen.width % 2 || screen.height % 2)
181
return true;
182
183
return false;
184
},
185
186
/**
187
* Is a Laptop?
188
* @return {Boolean} true or false.
189
*/
190
isLaptop: function() {
191
if (this.isMobileDevice()) return false;
192
// Most common laptop screen resolution
193
if (screen.width == 1366 && screen.height == 768) return true;
194
// Netbooks
195
if (screen.width == 1024 && screen.height == 600) return true;
196
return false;
197
},
198
199
/**
200
* Is Nokia?
201
* @return {Boolean} true or false.
202
*/
203
isNokia: function() {
204
return (this.ua.match('(Maemo Browser)|(Symbian)|(Nokia)|(Lumia )')) ? true : false;
205
},
206
207
/**
208
* Is Zune?
209
* @return {Boolean} true or false.
210
*/
211
isZune: function() {
212
return (this.ua.match('ZuneWP7')) ? true : false;
213
},
214
215
/**
216
* Is HTC?
217
* @return {Boolean} true or false.
218
*/
219
isHtc: function() {
220
return (this.ua.match('HTC')) ? true : false;
221
},
222
223
/**
224
* Is Ericsson?
225
* @return {Boolean} true or false.
226
*/
227
isEricsson: function() {
228
return (this.ua.match('Ericsson')) ? true : false;
229
},
230
231
/**
232
* Is Motorola?
233
* @return {Boolean} true or false.
234
*/
235
isMotorola: function() {
236
return (this.ua.match('Motorola')) ? true : false;
237
},
238
239
/**
240
* Is Google?
241
* @return {Boolean} true or false.
242
*/
243
isGoogle: function() {
244
return (this.ua.match('Nexus One')) ? true : false;
245
},
246
247
/**
248
* Returns true if the browser is on a Mobile device
249
* @return {Boolean} true or false
250
*
251
* @example: if(beef.hardware.isMobileDevice()) { ... }
252
*/
253
isMobileDevice: function() {
254
return MobileEsp.DetectMobileQuick();
255
},
256
257
/**
258
* Returns true if the browser is on a game console
259
* @return {Boolean} true or false
260
*
261
* @example: if(beef.hardware.isGameConsole()) { ... }
262
*/
263
isGameConsole: function() {
264
return MobileEsp.DetectGameConsole();
265
},
266
267
getName: function() {
268
var ua = navigator.userAgent.toLowerCase();
269
if(MobileEsp.DetectIphone()) { return "iPhone"};
270
if(MobileEsp.DetectIpod()) { return "iPod Touch"};
271
if(MobileEsp.DetectIpad()) { return "iPad"};
272
if (this.isHtc()) { return 'HTC'};
273
if (this.isMotorola()) { return 'Motorola'};
274
if (this.isZune()) { return 'Zune'};
275
if (this.isGoogle()) { return 'Google Nexus One'};
276
if (this.isEricsson()) { return 'Ericsson'};
277
if(MobileEsp.DetectAndroidPhone()) { return "Android Phone"};
278
if(MobileEsp.DetectAndroidTablet()) { return "Android Tablet"};
279
if(MobileEsp.DetectS60OssBrowser()) { return "Nokia S60 Open Source"};
280
if(ua.search(MobileEsp.deviceS60) > -1) { return "Nokia S60"};
281
if(ua.search(MobileEsp.deviceS70) > -1) { return "Nokia S70"};
282
if(ua.search(MobileEsp.deviceS80) > -1) { return "Nokia S80"};
283
if(ua.search(MobileEsp.deviceS90) > -1) { return "Nokia S90"};
284
if(ua.search(MobileEsp.deviceSymbian) > -1) { return "Nokia Symbian"};
285
if (this.isNokia()) { return 'Nokia'};
286
if(MobileEsp.DetectWindowsPhone7()) { return "Windows Phone 7"};
287
if(MobileEsp.DetectWindowsPhone8()) { return "Windows Phone 8"};
288
if(MobileEsp.DetectWindowsPhone10()) { return "Windows Phone 10"};
289
if(MobileEsp.DetectWindowsMobile()) { return "Windows Mobile"};
290
if(MobileEsp.DetectBlackBerryTablet()) { return "BlackBerry Tablet"};
291
if(MobileEsp.DetectBlackBerryWebKit()) { return "BlackBerry OS 6"};
292
if(MobileEsp.DetectBlackBerryTouch()) { return "BlackBerry Touch"};
293
if(MobileEsp.DetectBlackBerryHigh()) { return "BlackBerry OS 5"};
294
if(MobileEsp.DetectBlackBerry()) { return "BlackBerry"};
295
if(MobileEsp.DetectPalmOS()) { return "Palm OS"};
296
if(MobileEsp.DetectPalmWebOS()) { return "Palm Web OS"};
297
if(MobileEsp.DetectGarminNuvifone()) { return "Gamin Nuvifone"};
298
if(MobileEsp.DetectArchos()) { return "Archos"}
299
if(MobileEsp.DetectBrewDevice()) { return "Brew"};
300
if(MobileEsp.DetectDangerHiptop()) { return "Danger Hiptop"};
301
if(MobileEsp.DetectMaemoTablet()) { return "Maemo Tablet"};
302
if(MobileEsp.DetectSonyMylo()) { return "Sony Mylo"};
303
if(MobileEsp.DetectAmazonSilk()) { return "Kindle Fire"};
304
if(MobileEsp.DetectKindle()) { return "Kindle"};
305
if(MobileEsp.DetectSonyPlaystation()) { return "Playstation"};
306
if(ua.search(MobileEsp.deviceNintendoDs) > -1) { return "Nintendo DS"};
307
if(ua.search(MobileEsp.deviceWii) > -1) { return "Nintendo Wii"};
308
if(ua.search(MobileEsp.deviceNintendo) > -1) { return "Nintendo"};
309
if(MobileEsp.DetectXbox()) { return "Xbox"};
310
if(this.isLaptop()) { return "Laptop"};
311
if(this.isVirtualMachine()) { return "Virtual Machine"};
312
313
return 'Unknown';
314
}
315
};
316
317
beef.regCmp('beef.hardware');
318
319