Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/client/os.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
/** @namespace beef.os */
8
9
beef.os = {
10
11
ua: navigator.userAgent,
12
13
/**
14
* Detect default browser (IE only)
15
* Written by unsticky
16
* http://ha.ckers.org/blog/20070319/detecting-default-browser-in-ie/
17
* @return {string}
18
*/
19
getDefaultBrowser: function() {
20
var result = "Unknown"
21
try {
22
var mt = document.mimeType;
23
if (mt) {
24
if (mt == "Safari Document") result = "Safari";
25
if (mt == "Firefox HTML Document") result = "Firefox";
26
if (mt == "Chrome HTML Document") result = "Chrome";
27
if (mt == "HTML Document") result = "Internet Explorer";
28
if (mt == "Opera Web Document") result = "Opera";
29
}
30
} catch (e) {
31
beef.debug("[os] getDefaultBrowser: "+e.message);
32
}
33
return result;
34
},
35
36
// the likelihood that we hook Windows 3.11 (which has only Win in the UA string) is zero in 2015
37
/**
38
* @return {boolean}
39
*/
40
isWin311: function() {
41
return (this.ua.match('(Win16)')) ? true : false;
42
},
43
/**
44
* @return {boolean}
45
*/
46
isWinNT4: function() {
47
return (this.ua.match('(Windows NT 4.0)')) ? true : false;
48
},
49
/**
50
* @return {boolean}
51
*/
52
isWin95: function() {
53
return (this.ua.match('(Windows 95)|(Win95)|(Windows_95)')) ? true : false;
54
},
55
/**
56
* @return {boolean}
57
*/
58
isWinCE: function() {
59
return (this.ua.match('(Windows CE)')) ? true : false;
60
},
61
/**
62
* @return {boolean}
63
*/
64
isWin98: function() {
65
return (this.ua.match('(Windows 98)|(Win98)')) ? true : false;
66
},
67
/**
68
* @return {boolean}
69
*/
70
isWinME: function() {
71
return (this.ua.match('(Windows ME)|(Win 9x 4.90)')) ? true : false;
72
},
73
/**
74
* @return {boolean}
75
*/
76
isWin2000: function() {
77
return (this.ua.match('(Windows NT 5.0)|(Windows 2000)')) ? true : false;
78
},
79
/**
80
* @return {boolean}
81
*/
82
isWin2000SP1: function() {
83
return (this.ua.match('Windows NT 5.01 ')) ? true : false;
84
},
85
/**
86
* @return {boolean}
87
*/
88
isWinXP: function() {
89
return (this.ua.match('(Windows NT 5.1)|(Windows XP)')) ? true : false;
90
},
91
/**
92
* @return {boolean}
93
*/
94
isWinServer2003: function() {
95
return (this.ua.match('(Windows NT 5.2)')) ? true : false;
96
},
97
/**
98
* @return {boolean}
99
*/
100
isWinVista: function() {
101
return (this.ua.match('(Windows NT 6.0)')) ? true : false;
102
},
103
/**
104
* @return {boolean}
105
*/
106
isWin7: function() {
107
return (this.ua.match('(Windows NT 6.1)|(Windows NT 7.0)')) ? true : false;
108
},
109
/**
110
* @return {boolean}
111
*/
112
isWin8: function() {
113
return (this.ua.match('(Windows NT 6.2)')) ? true : false;
114
},
115
/**
116
* @return {boolean}
117
*/
118
isWin81: function() {
119
return (this.ua.match('(Windows NT 6.3)')) ? true : false;
120
},
121
/**
122
* @return {boolean}
123
*/
124
isWin10: function() {
125
return (this.ua.match('Windows NT 10.0')) ? true : false;
126
},
127
/**
128
* @return {boolean}
129
*/
130
isOpenBSD: function() {
131
return (this.ua.indexOf('OpenBSD') != -1) ? true : false;
132
},
133
/**
134
* @return {boolean}
135
*/
136
isSunOS: function() {
137
return (this.ua.indexOf('SunOS') != -1) ? true : false;
138
},
139
/**
140
* @return {boolean}
141
*/
142
isLinux: function() {
143
return (this.ua.match('(Linux)|(X11)')) ? true : false;
144
},
145
/**
146
* @return {boolean}
147
*/
148
isMacintosh: function() {
149
return (this.ua.match('(Mac_PowerPC)|(Macintosh)|(MacIntel)')) ? true : false;
150
},
151
/**
152
* @return {boolean}
153
*/
154
isOsxYosemite: function(){ // TODO
155
return (this.ua.match('(OS X 10_10)|(OS X 10.10)')) ? true : false;
156
},
157
/**
158
* @return {boolean}
159
*/
160
isOsxMavericks: function(){ // TODO
161
return (this.ua.match('(OS X 10_9)|(OS X 10.9)')) ? true : false;
162
},
163
/**
164
* @return {boolean}
165
*/
166
isOsxSnowLeopard: function(){ // TODO
167
return (this.ua.match('(OS X 10_8)|(OS X 10.8)')) ? true : false;
168
},
169
/**
170
* @return {boolean}
171
*/
172
isOsxLeopard: function(){ // TODO
173
return (this.ua.match('(OS X 10_7)|(OS X 10.7)')) ? true : false;
174
},
175
/**
176
* @return {boolean}
177
*/
178
isWinPhone: function() {
179
return (this.ua.match('(Windows Phone)')) ? true : false;
180
},
181
/**
182
* @return {boolean}
183
*/
184
isIphone: function() {
185
return (this.ua.indexOf('iPhone') != -1) ? true : false;
186
},
187
/**
188
* @return {boolean}
189
*/
190
isIpad: function() {
191
return (this.ua.indexOf('iPad') != -1) ? true : false;
192
},
193
/**
194
* @return {boolean}
195
*/
196
isIpod: function() {
197
return (this.ua.indexOf('iPod') != -1) ? true : false;
198
},
199
/**
200
* @return {boolean}
201
*/
202
isNokia: function() {
203
return (this.ua.match('(Maemo Browser)|(Symbian)|(Nokia)')) ? true : false;
204
},
205
/**
206
* @return {boolean}
207
*/
208
isAndroid: function() {
209
return (this.ua.match('Android')) ? true : false;
210
},
211
/**
212
* @return {boolean}
213
*/
214
isBlackBerry: function() {
215
return (this.ua.match('BlackBerry')) ? true : false;
216
},
217
/**
218
* @return {boolean}
219
*/
220
isWebOS: function() {
221
return (this.ua.match('webOS')) ? true : false;
222
},
223
/**
224
* @return {boolean}
225
*/
226
isQNX: function() {
227
return (this.ua.match('QNX')) ? true : false;
228
},
229
/**
230
* @return {boolean}
231
*/
232
isBeOS: function() {
233
return (this.ua.match('BeOS')) ? true : false;
234
},
235
/**
236
* @return {boolean}
237
*/
238
isAros: function() {
239
return (this.ua.match('AROS')) ? true : false;
240
},
241
/**
242
* @return {boolean}
243
*/
244
isWindows: function() {
245
return (this.ua.match('Windows')) ? true : false;
246
},
247
/**
248
* @return {string}
249
*/
250
getName: function() {
251
252
if(this.isWindows()){
253
return 'Windows';
254
}
255
256
if(this.isMacintosh()) {
257
return 'OSX';
258
}
259
260
//Nokia
261
if(this.isNokia()) {
262
if (this.ua.indexOf('Maemo Browser') != -1) return 'Maemo';
263
if (this.ua.match('(SymbianOS)|(Symbian OS)')) return 'SymbianOS';
264
if (this.ua.indexOf('Symbian') != -1) return 'Symbian';
265
}
266
267
// BlackBerry
268
if(this.isBlackBerry()) return 'BlackBerry OS';
269
270
// Android
271
if(this.isAndroid()) return 'Android';
272
273
// SunOS
274
if(this.isSunOS()) return 'SunOS';
275
276
//Linux
277
if(this.isLinux()) return 'Linux';
278
279
//iPhone
280
if (this.isIphone()) return 'iOS';
281
//iPad
282
if (this.isIpad()) return 'iOS';
283
//iPod
284
if (this.isIpod()) return 'iOS';
285
286
//others
287
if(this.isQNX()) return 'QNX';
288
if(this.isBeOS()) return 'BeOS';
289
if(this.isWebOS()) return 'webOS';
290
if(this.isAros()) return 'AROS';
291
292
return 'unknown';
293
},
294
295
/**
296
* Get OS architecture.
297
* This may not be the same as the browser arch or CPU arch.
298
* ie, 32bit OS on 64bit hardware
299
*/
300
getArch: function() {
301
var arch = 'unknown';
302
try {
303
var arch = platform.os.architecture;
304
if (!!arch)
305
return arch;
306
} catch (e) {}
307
308
return arch;
309
},
310
311
/**
312
* Get OS family
313
*/
314
getFamily: function() {
315
var family = 'unknown';
316
try {
317
var family = platform.os.family;
318
if (!!family)
319
return family;
320
} catch (e) {}
321
322
return arch;
323
},
324
325
/**
326
* Get OS name
327
* @return {string}
328
*/
329
getVersion: function(){
330
//Windows
331
if(this.isWindows()) {
332
if (this.isWin10()) return '10';
333
if (this.isWin81()) return '8.1';
334
if (this.isWin8()) return '8';
335
if (this.isWin7()) return '7';
336
if (this.isWinVista()) return 'Vista';
337
if (this.isWinXP()) return 'XP';
338
if (this.isWinServer2003()) return 'Server 2003';
339
if (this.isWin2000SP1()) return '2000 SP1';
340
if (this.isWin2000()) return '2000';
341
if (this.isWinME()) return 'Millenium';
342
343
if (this.isWinNT4()) return 'NT 4';
344
if (this.isWinCE()) return 'CE';
345
if (this.isWin95()) return '95';
346
if (this.isWin98()) return '98';
347
}
348
349
// OS X
350
if(this.isMacintosh()) {
351
if (this.isOsxYosemite()) return '10.10';
352
if (this.isOsxMavericks()) return '10.9';
353
if (this.isOsxSnowLeopard()) return '10.8';
354
if (this.isOsxLeopard()) return '10.7';
355
}
356
357
// TODO add Android/iOS version detection
358
}
359
};
360
361
beef.regCmp('beef.net.os');
362
363