|
This chapter is a basic introduction to the format of java binary class files. The following code was assembled with the JDK's javac compiler to produce a class file. A hex dump of the file is represented below as well as an analysis of the class file. You should view this code in conjunction with a copy of the Java Virtual Machine specification, more importantly the java class file specification. To effectively infect class files one must be able to understand the way in which they are constructed and executed. analysis
Compile java source files
with the javac command
Disassemble java class
files with the javap command
public class HelloWorld {
public synchronized class
HelloWorld extends java.lang.Object
Method void main(java.lang.String[])
Method HelloWorld()
147B:0110 07 00 1A 07 00 1B 07 00-1C 0A 00 04 00 09 09 00 ................ 147B:0120 05 00 0A 0A 00 03 00 0B-0C 00 0F 00 0C 0C 00 1E ................ 147B:0130 00 17 0C 00 1F 00 0D 01-00 03 28 29 56 01 00 15 ..........()V... 147B:0140 28 4C 6A 61 76 61 2F 6C-61 6E 67 2F 53 74 72 69 (Ljava/lang/Stri 147B:0150 6E 67 3B 29 56 01 00 16-28 5B 4C 6A 61 76 61 2F ng;)V...([Ljava/ 147B:0160 6C 61 6E 67 2F 53 74 72-69 6E 67 3B 29 56 01 00 lang/String;)V.. 147B:0170 06 3C 69 6E 69 74 3E 01-00 04 43 6F 64 65 01 00 .<init>...Code.. 147B:0180 0D 43 6F 6E 73 74 61 6E-74 56 61 6C 75 65 01 00 .ConstantValue.. 147B:0190 0A 45 78 63 65 70 74 69-6F 6E 73 01 00 0C 48 65 .Exceptions...He 147B:01A0 6C 6C 6F 20 57 6F 72 6C-64 21 01 00 0A 48 65 6C llo World!...Hel 147B:01B0 6C 6F 57 6F 72 6C 64 01-00 0F 48 65 6C 6C 6F 57 loWorld...HelloW 147B:01C0 6F 72 6C 64 2E 6A 61 76-61 01 00 0F 4C 69 6E 65 orld.java...Line 147B:01D0 4E 75 6D 62 65 72 54 61-62 6C 65 01 00 15 4C 6A NumberTable...Lj 147B:01E0 61 76 61 2F 69 6F 2F 50-72 69 6E 74 53 74 72 65 ava/io/PrintStre 147B:01F0 61 6D 3B 01 00 0E 4C 6F-63 61 6C 56 61 72 69 61 am;...LocalVaria 147B:0200 62 6C 65 73 01 00 0A 53-6F 75 72 63 65 46 69 6C bles...SourceFil 147B:0210 65 01 00 13 6A 61 76 61-2F 69 6F 2F 50 72 69 6E e...java/io/Prin 147B:0220 74 53 74 72 65 61 6D 01-00 10 6A 61 76 61 2F 6C tStream...java/l 147B:0230 61 6E 67 2F 4F 62 6A 65-63 74 01 00 10 6A 61 76 ang/Object...jav 147B:0240 61 2F 6C 61 6E 67 2F 53-79 73 74 65 6D 01 00 04 a/lang/System... 147B:0250 6D 61 69 6E 01 00 03 6F-75 74 01 00 07 70 72 69 main...out...pri 147B:0260 6E 74 6C 6E 00 21 00 02-00 04 00 00 00 00 00 02 ntln.!.......... 147B:0270 00 09 00 1D 00 0E 00 01-00 10 00 00 00 25 00 02 .............%.. 147B:0280 00 01 00 00 00 09 B2 00-07 12 01 B6 00 08 B1 00 ................ 147B:0290 00 00 01 00 16 00 00 00-0A 00 02 00 00 00 0D 00 ................ 147B:02A0 08 00 0B 00 01 00 0F 00-0C 00 01 00 10 00 00 00 ................ 147B:02B0 1D 00 01 00 01 00 00 00-05 2A B7 00 06 B1 00 00 .........*...... 147B:02C0 00 01 00 16 00 00 00 06-00 01 00 00 00 09 00 01 ................ 147B:02D0 00 19 00 00 00 02 00 15
magic 0xCAFEBABE
conclusion To reiterate once more, to successfully infect any file whether it be a PE executable or a shell script you must be able to understand the format of the file. By examining this HelloWorld text a couple of times you should have some sort of a feel for the way in which a java binary class file looks on the inside. |