Esempio n. 1
0
        private async Task SendServiceMessage(Message packet)
        {
            var command = packet.Json;
            try
            {
                using (var tcpClient = new TcpClient())
                {
                    await tcpClient.ConnectAsync(IPAddress.Loopback, 22005);
                    using (var stream = tcpClient.GetStream())
                    using (var sw = new StreamWriter(stream, Encoding.UTF8))
                    {

                        if (tcpClient.Connected)
                        {
                            await sw.WriteLineAsync(command);
                            await sw.FlushAsync();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Writes a message to the queue.
        /// </summary>
        /// <param name="data"></param>
        public void WriteMessage(object data)
        {
 
            if (_client != null && data != null)
            {
                var json = JsonConvert.SerializeObject(new
                {
                    endpoint = Endpoint,
                    synckey,
                    results = data
                });
               

                try
                {
                    if (_authClient != null)
                    {
                        if (_authClient.AesShook)
                        {
                            var keyBytes = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(_authClient.AesKey));
                            var keyIv = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(_authClient.AesIv));

                            var encryptedData = Encrypt(Encoding.UTF8.GetBytes(json), keyBytes, keyIv);
                            using (var memoryStream = new MemoryStream())
                            {
                                using (var binaryWriter = new BinaryWriter(memoryStream))
                                {
                                    binaryWriter.Write(Endpoint.Length);
                                    binaryWriter.Write(Encoding.UTF8.GetBytes(Endpoint));
                                    binaryWriter.Write(Encoding.UTF8.GetBytes(EncryptionType.CBC.ToString()));
                                    binaryWriter.Write(encryptedData);
                                }
                                var message = new Message(_client, memoryStream.ToArray(), Message.MessageType.Binary);
                                var targetPort = _client.LocalEndpoint.Port;
                                _authClient?.MessageQueueManagers[targetPort]?.SendQueue.Add(message);
                            }
                            return;
                        }
                    }
                }
                catch (Exception e)
                {

                    Console.WriteLine($"Could not send encrypted message: {e.Message}");
                    Console.WriteLine(e.StackTrace);
                    return;
                }
                var jsonMessage = new Message(_client, json, Message.MessageType.Text);
                if (_authClient != null)
                {
                    var targetPort = _client.LocalEndpoint.Port;
                    _authClient?.MessageQueueManagers[targetPort]?.SendQueue.Add(jsonMessage);
                }
            }
        }
Esempio n. 3
0
        private void HandleAgentMouseUp()
        {
            if (!ScreenShareService.Streams.ContainsKey(_authClient))
            {
                return;
            }
            var command = "mouseup";
            var message = new Message(command, Message.MessageType.Service);

            _authClient?.MessageQueueManagers[22005]?.SendQueue.Add(message);
        }
Esempio n. 4
0
        private void HandleAgentMouseMove()
        {
            if (!ScreenShareService.Streams.ContainsKey(_authClient))
            {
                return;
            }
            int y       = Convert.ToInt16(_packet.Args[0], CultureInfo.InvariantCulture);
            int x       = Convert.ToInt16(_packet.Args[1], CultureInfo.InvariantCulture);
            var command = "mousemove|" + $"{x},{y}";
            var message = new Message(command, Message.MessageType.Service);

            _authClient?.MessageQueueManagers[22005]?.SendQueue.Add(message);
        }
Esempio n. 5
0
        private void HandleAgentMouseScroll()
        {
            if (!ScreenShareService.Streams.ContainsKey(_authClient))
            {
                return;
            }
            var delta     = Convert.ToInt32(_packet.Args[0], CultureInfo.InvariantCulture);
            var arguments = delta + "," + "0";
            var command   = "mousescroll|" + arguments;
            var message   = new Message(command, Message.MessageType.Service);

            _authClient?.MessageQueueManagers[22005]?.SendQueue.Add(message);
        }
Esempio n. 6
0
        private void HandleAgentKeyUp()
        {
            if (!ScreenShareService.Streams.ContainsKey(_authClient))
            {
                return;
            }
            var keyCodes = ((IEnumerable)_packet.Args[0]).Cast <object>()
                           .Select(x => x.ToString())
                           .ToList();
            var codes =
                keyCodes.Select(code => ToHex(int.Parse(code.ToString())))
                .Select(hexString => Convert.ToInt32(hexString, 16))
                .ToList();
            var result  = string.Join(",", codes);
            var command = "keyup|" + result;
            var message = new Message(command, Message.MessageType.Service);

            _authClient?.MessageQueueManagers[22005]?.SendQueue.Add(message);
        }
Esempio n. 7
0
        /// <summary>
        ///     Sends a JSON based packet
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        private async Task SendJsonPacket(Message packet)
        {
            var json = packet.Json;

            var client = packet.RemoteClient;
            if (client != null && client.IsConnected)
            {
                try
                {
                    using (var msg = client.CreateMessageWriter(WebSocketMessageType.Text))
                    using (var writer = new StreamWriter(msg, Encoding.UTF8))
                    {
                        await writer.WriteAsync(json);
                        await writer.FlushAsync();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Esempio n. 8
0
        public void WriteScreenFrame(byte[] data)
        {
            if (_client == null || data == null) return;
            try
            {
                if (_authClient == null) return;
                if (!_authClient.AesShook) return;
                var keyBytes = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(_authClient.AesKey));
                var keyIv = Encoding.UTF8.GetBytes(Rsa.SecureStringToString(_authClient.AesIv));

                var encryptedData = EncryptFrame(data, keyBytes, keyIv);

                using (var memoryStream = new MemoryStream())
                {
                    using (var binaryWriter = new BinaryWriter(memoryStream))
                    {
                        binaryWriter.Write(Endpoint.Length);
                        binaryWriter.Write(Encoding.UTF8.GetBytes(Endpoint));
                        binaryWriter.Write(Encoding.UTF8.GetBytes(EncryptionType.OFB.ToString()));
                        binaryWriter.Write(encryptedData);
                    }
                    var message = new Message(_client, memoryStream.ToArray(), Message.MessageType.Binary);
                    var targetPort = _client.LocalEndpoint.Port;
                    _authClient?.MessageQueueManagers[targetPort]?.SendQueue.Add(message);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Could not send encrypted message: {e.Message}");
                Console.WriteLine(e.StackTrace);

            }
        }
Esempio n. 9
0
 /// <summary>
 ///     Sends an encrypted packet
 /// </summary>
 /// <param name="packet"></param>
 /// <returns></returns>
 private async Task SendBinaryPacket(Message packet)
 {
     var client = packet.RemoteClient;
     if (client != null && client.IsConnected)
     {
         try
         {
             using (var memoryStream = new MemoryStream(packet.Data))
             using (var messageWriter = client.CreateMessageWriter(WebSocketMessageType.Binary))
                 await memoryStream.CopyToAsync(messageWriter);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
         }
     }
 }
Esempio n. 10
0
 private void HandleAgentKeyUp()
 {
     if (!ScreenShareService.Streams.ContainsKey(_authClient)) return;
     var keyCodes = ((IEnumerable) _packet.Args[0]).Cast<object>()
         .Select(x => x.ToString())
         .ToList();
     var codes =
         keyCodes.Select(code => ToHex(int.Parse(code.ToString())))
             .Select(hexString => Convert.ToInt32(hexString, 16))
             .ToList();
     var result = string.Join(",", codes);
     var command = "keyup|" + result;
     var message = new Message(command, Message.MessageType.Service);
     _authClient?.MessageQueueManagers[22005]?.SendQueue.Add(message);
 }
Esempio n. 11
0
 private void HandleAgentMouseMove()
 {
     if (!ScreenShareService.Streams.ContainsKey(_authClient)) return;
     int y = Convert.ToInt16(_packet.Args[0], CultureInfo.InvariantCulture);
     int x = Convert.ToInt16(_packet.Args[1], CultureInfo.InvariantCulture);
     var command = "mousemove|" + $"{x},{y}";
     var message = new Message(command, Message.MessageType.Service);
     _authClient?.MessageQueueManagers[22005]?.SendQueue.Add(message);
 }
Esempio n. 12
0
 private void HandleAgentMouseUp()
 {
     if (!ScreenShareService.Streams.ContainsKey(_authClient)) return;
     var command = "mouseup";
     var message = new Message(command, Message.MessageType.Service);
     _authClient?.MessageQueueManagers[22005]?.SendQueue.Add(message);
 }
Esempio n. 13
0
 private void HandleAgentMouseScroll()
 {
     if (!ScreenShareService.Streams.ContainsKey(_authClient)) return;
     var delta = Convert.ToInt32(_packet.Args[0], CultureInfo.InvariantCulture);
     var arguments = delta + "," + "0";
     var command = "mousescroll|" + arguments;
     var message = new Message(command, Message.MessageType.Service);
     _authClient?.MessageQueueManagers[22005]?.SendQueue.Add(message);
 }