Esempio n. 1
0
        public Client(Protocol protocol, string dns, int port, string password, CryptoServiceAlgorithm algorithm)
        {
            Protocol = protocol;
            IP       = dns;
            Port     = port;
            Password = password;

            _cryptoService = new CryptoService(algorithm, password);
        }
Esempio n. 2
0
        public Client(Protocol protocol, Socket socket, string password, CryptoServiceAlgorithm algorithm)
        {
            Protocol = protocol;
            _socket  = socket;
            Password = password;

            IP   = ((IPEndPoint)socket.RemoteEndPoint).Address.ToString();
            Port = ((IPEndPoint)socket.LocalEndPoint).Port;

            _cryptoService = new CryptoService(algorithm, password);
        }
Esempio n. 3
0
        private void RunBenchmarks()
        {
            int bufferSize = (int)(1024 * numBuffer.Value);
            CryptoServiceAlgorithm algorithm = GetAlgorithm();

            new Thread(() =>
            {
                CryptoService cryptoService = new CryptoService(algorithm, Guid.NewGuid().ToString());
                Random random      = new Random();
                Stopwatch sw       = new Stopwatch();
                byte[] buffer      = new byte[bufferSize];
                long dataProcessed = 0;
                long duration      = 3; // 1 second

                random.NextBytes(buffer);

                sw.Start();
                while (sw.ElapsedMilliseconds < duration * 1000)
                {
                    cryptoService.Encrypt(buffer);
                    dataProcessed += buffer.Length;
                }
                sw.Stop();

                buffer = cryptoService.Encrypt(buffer);

                Invoke((MethodInvoker) delegate
                {
                    lblEncryption.Text = $"Encryption: {Explorer.GetSize((double)dataProcessed / duration)}/S";
                });

                sw.Restart();

                while (sw.ElapsedMilliseconds < duration * 1000)
                {
                    cryptoService.Decrypt(buffer);
                    dataProcessed += buffer.Length;
                }

                sw.Stop();

                Invoke((MethodInvoker) delegate
                {
                    lblDec.Text              = $"Decryption: {Explorer.GetSize((double)dataProcessed / duration)}/S";
                    btnBenchmark.Enabled     = true;
                    numBuffer.Enabled        = true;
                    cbEncryptionMode.Enabled = true;
                });

                buffer = null;
            }).Start();
        }
Esempio n. 4
0
 private void SetCryptoServiceAlgorithm(CryptoServiceAlgorithm alg)
 {
     if (alg == CryptoServiceAlgorithm.AES)
     {
         radEncAES.Checked = true;
     }
     else if (alg == CryptoServiceAlgorithm.RC4)
     {
         radEncRC4.Checked = true;
     }
     else if (alg == CryptoServiceAlgorithm.XOR)
     {
         radEncXOR.Checked = true;
     }
     else if (alg == CryptoServiceAlgorithm.TripleDES)
     {
         radDES.Checked = true;
     }
     else
     {
         radEncNone.Checked = true;
     }
 }
Esempio n. 5
0
 public CryptoService(CryptoServiceAlgorithm algorithm, string password)
 {
     Algorithm = algorithm;
     key       = Encoding.ASCII.GetBytes(password);
 }
Esempio n. 6
0
        static int ParseArgs(string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                PrintUsage();
                return(-1);
            }
            else
            {
                string endpoint       = args[0].ToLower();
                string password       = args[1];
                string encryptionMode = args.Length == 3 ? args[2].ToLower() : "";

                if (encryptionMode != "aes" && encryptionMode != "rc4" && encryptionMode != "xor")
                {
                    Console.WriteLine($"Invalid encryption mode provided: '{encryptionMode}'.\nValid options: AES | RC4 | XOR.");
                    return(-1);
                }


                try
                {
                    // Finish parsing information
                    string[] epInfo            = endpoint.Split(":");
                    string   dns               = epInfo[0];
                    int      port              = int.Parse(epInfo[1]);
                    CryptoServiceAlgorithm alg = CryptoServiceAlgorithm.Disabled;

                    // Set crypto mode
                    if (encryptionMode == "aes")
                    {
                        alg = CryptoServiceAlgorithm.AES;
                    }
                    else if (encryptionMode == "rc4")
                    {
                        alg = CryptoServiceAlgorithm.RC4;
                    }
                    else if (encryptionMode == "xor")
                    {
                        alg = CryptoServiceAlgorithm.XOR;
                    }

                    // Create new client
                    Client client = new Client(Protocol.FFTSI, dns, port, Hashing.SHA(password), alg);

                    // Listen to events
                    client.Disconnected   += Client_Disconnected;
                    client.PacketReceived += Client_PacketReceived;
                    client.Ready          += Client_Ready;

                    // Connect
                    client.Connect(1024 * 1024); // TODO: Make buffer size an optional parameter

                    if (client.Connected)
                    {
                        System.Diagnostics.Process.GetCurrentProcess().WaitForExit();
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.Message);
                    return(-1);
                }
            }

            return(0);
        }