This is a basic tutorial for reverse engineering Java Applets. This has many functions to it, so I will not cover every single possible function for reverse engineering an applet, but in this tutorial we will simply be using this method to simply understand how another applet works. Let us begin...
I will be doing this method from my OS (which is Ubuntu) so I will be doing a lot of command line for my compiling (because frankly I don't care enough to get a compiler. For these steps, use your own method of compiling a Java applet, there is not really one specific way to follow this tutorial)
For this tutorial you will need
- JDK (Java Development Kit), you can download this from Sun Microsystems' Website
- JAD (Java Decompiler), you can download this
here
- Basic knowledge of Java
- Java Compiler (you can use your own, or do it from command line, it's still simple from command line, but most people want a GUI)
Once you've downloaded the JDK (if you didn't already have it) and the Java Decompiler, you're going to need to find an applet that you want to reverse engineer. I found (through searching "java applet examples" on Google) an applet that I thought would be perfect for this tutorial
here
Basically, I just wanted to see how this applet works. So, I decided I'd crack it open and get to it.
First, we need to actually get the class file. The class file is a binary file that makes it so that the interpreter (probably used the wrong word, but whatever) can display the applet (since it can't read plain text like we can). To get this class file, we need to find out where the class file is located
Note: Almost all class files will be in the same directory as the applet you're viewing
But, to be sure, we're going to right click the page and select the "View Source" option. Once we do that, we need to press Ctrl+F and search for "APPLET" (make sure that match case is off when you do this)
You want to keep searching until you find a tag that looks something like this
<APPLET CODE="image3dcube.class" WIDTH=250 HEIGHT=250>
Now, if you're not on the same website as me, then this will look different. But, the class file that we're looking for is located after "CODE=". In this case, we can see that the class file is "image3dcube.class". So, to get this file we need go into the url bar, get rid of "applet2.html" and put in "image3dcube.class" like so
You should then get a prompt asking you if you want to download the file. Obviously, you'll want to say yes. Now, the best place to save the file is in the folder or location where your Java Decompiler is. So, go and do that now. This is where the command line stuff will come in. What you'll want to do is change to the directory where your image3dcube.class file and your Java Decompiler are and then you'll want to run your compiler from command line.
To do this in Linux or Mac, you'll just type this
./jad image3dcube.class
And it should end up looking like this
Now, in Windows, I'm assuming you just simply need to type "jad image3dcube.class" in your Command Prompt and it should work the same way.
Either way you do it, you should end up getting a file named "image3dcube.jad". Just open this with a text editor and now you can see the code that is inside. Now, in order to run this file we need a few things.
- A new Java and Class file
- An applet for viewing
To create our new Java file, we select the code (ignoring the comments at the top) and copy it. Then, we create a new file (with the same name as the original file) but make it a .java extension. Then, paste the code from .jad file into our new .java file and save it. Next, delete our old class file (the image3dcube.class) and we will run our compiler on our new Java file. To do this from command line (which is easier because you should already be in the same directory. Type:
javac image3dcube.java
This will compile the code and give you a new image3d.class file. You can now modify the code from the image3dcube.java file, compile, and then run it. But, we need a way to actually view the applet. Unfortunately for us, the source code from the original applet uses Parameters. So, in order for this code to run properly, we need to copy the applet code from the original site's source file and change some values.
The original code for the applet is this:
<APPLET CODE="image3dcube.class" WIDTH=250 HEIGHT=250>
<PARAM name="background" value="FFFFFF">
<PARAM name="shadowcolor" value="FFFFFF">
<PARAM name="textcolor" value="000000">
<PARAM name="spotlight" value="no">
<PARAM name="showlightbutton" value="no">
<PARAM name="sleeptime" value="5">
<PARAM name="target" value="_self">
<PARAM name="anglestep" value="8">
<PARAM name="mouseresponse" value="6">
<PARAM name="zoomspeed" value="4">
<PARAM name="image0" value="2comp1.gif">
<PARAM name="image1" value="2comp2.gif">
<PARAM name="image2" value="2comp3.gif">
<PARAM name="image3" value="2comp4.gif">
<PARAM name="image4" value="2comp5.gif">
<PARAM name="image5" value="2comp6.gif">
<PARAM name="url0" value="http://oran.k12.mo.us/fbla/index.html">
<PARAM name="url1" value="http://oran.k12.mo.us/fbla/index.html">
<PARAM name="url2" value="http://oran.k12.mo.us/fbla/index.html">
<PARAM name="url3" value="http://oran.k12.mo.us/fbla/index.html">
<PARAM name="url4" value="http://oran.k12.mo.us/fbla/index.html">
<PARAM name="url5" value="http://oran.k12.mo.us/fbla/index.html">
</APPLET>
Now, what you'll need to do, is copy the applet code then create a new .html file. I generally name this file "applet.html" because it's a general name. Once you've made this file, paste the code into the applet.
For applets that don't use parameters, you can simply copy and paste this:
<applet code="CLASS FILE HERE" width="WIDTH OF APPLET" height="HEIGHT OF APPLET"> </applet>
change the values, and it will run. But, since this applet uses parameters, we need to satisfy these parameters or change them if necessary. If we were trying to reverse engineer a real applet, we'd want all of the pictures that the applet originally used, but for this, the general idea of this applet is so that you can put your own images. For the Linux users, you can use wget and usually get all of the images you need. For a guide to wget, go
here. If you end up getting not-needed images, then try changing the level.
Luckily for us, this applet is very flexible about our images, and our original goal was to see how this worked, maybe improve it, and then put in our own images. So, to do this, all you need to do is put images (maximum of 6) on your server or in your folder (the same folder as your applet) and then change the applet's parameters to be the file name of those images. Then, open the applet or use "appletviewer YOUR FILE NAME HERE.html" and see if it works.
There are many uses for reverse engineering a Java applet. To crack a password, to see where files are stored, or just to see how an applet works so that you can maybe improve your own code or heaven forbid leech the source. Anyway, I hope you enjoyed this tutorial, and you will hopefully be seeing some more useful tutorials later on in the future.
Thanks,
- Clocwork