Add detect_media_devices browser module#3565
Open
sethumadh wants to merge 1 commit into
Open
Conversation
Implements navigator.mediaDevices.enumerateDevices() detection. Groups results by kind (audioinput, audiooutput, videoinput) and returns counts unconditionally + labels when permissions allow. Handles the no-API case explicitly via beef.status.error(). Closes beefproject#3542
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Category
Module
Feature/Issue Description
Q: Please give a brief summary of your feature/fix
A: Adds a new browser-side recon module,
Detect Media Devices, wrappingnavigator.mediaDevices.enumerateDevices()to enumerate the hooked browser's microphones, cameras, and speakers. Fully passive — no permission prompt, no device opened, camera/mic indicator stays off. Returns counts unconditionally; labels appear post-permission. Closes #3542 (raised by @bcoles).Q: Give a technical rundown of what you have changed (if applicable)
A: Three new files in the standard 3-file module pattern (
command.js/module.rb/config.yaml), templated aftermodules/browser/detect_lastpass/.command.jscallsenumerateDevices(), groups results bykind, and POSTs viabeef.net.send. Missing-API and exception paths report viabeef.status.error().module.rbstores six form-body keys into@datastoreandsaves them. No new dependencies;rubocopclean.Two design notes:
Multi-key form body, not a single JSON value. BeEF's display layer (
core/main/handlers/commands.rb:83) wraps every result body under a'data':key. A URL-encoded JSON blob renders as%7B%22audioinput%22...— unreadable. Switched toaudioinput_count=...&audioinput_labels=...(one key per data point), matchingwebcam_html5's multi-key pattern.Permission-state insight in the count. Pre-permission,
enumerateDevices()returns one placeholder per kind that exists; post-permission, the full inventory. So the count alone is a permission-state signal, independent of labels — a 1 → many jump between executions indicates the origin gained media consent. There's also a vendor signal in the pre-permission shape: Chrome lists all 3 kinds, while Firefox 115+ and Safari 14+ list only 2 (noaudiooutput), per Mozilla Bug #1528042. Both are spec-compliant under W3C Media Capture and Streams. See the first comment on this PR for the detailed cross-browser write-up (intended wiki content per CONTRIBUTING.md step 9).Test Cases
Q: Describe your test cases, what you have covered and if there are any use cases that still need addressing.






A: Tested manually on macOS against BeEF's
/demos/basic.htmlhooked demo page. Screenshots inline below.(Built-in)/(Virtual)/(Aggregate)suffixesaudiooutput)Defaultaudiooutput dedupedDefault - <device>audiooutput prefix; surfaces Continuity Camera Desk ViewManual reproduction (5 steps):
http://<beef>:3000/demos/basic.htmlto hook a browser.Detect Media Devices→ Execute. Observe the pre-permission result in Module Results History.navigator.mediaDevices.getUserMedia({audio:true, video:true}).then(s => s.getTracks().forEach(t => t.stop()))and click Allow. Tracks stop immediately; camera light does not persist.Wiki Page
See the first comment on this PR for the wiki page draft — operator-facing cross-browser behavior reference with primary-source citations. Posted as a PR comment per CONTRIBUTING.md step 9, since external contributors don't have wiki edit rights.
Closes #3542