Пример #1
0
 public SSH2DataReader(DataFragment data) : base(data)
 {
 }
Пример #2
0
 public SSH2DataReader(DataFragment data)
     : base(data)
 {
 }
Пример #3
0
 private void SelectedAddressInspector_DataChanged(DataFragment data)
 {
     this.hexView.ApplyEdit(data);
     this.selectedAddressInspector.Target = this.hexView.GetSelectedData();
 }
Пример #4
0
 public void OnData(DataFragment data)
 {
     _connection.AsyncReceivePacket(data);
 }
Пример #5
0
        internal void AsyncReceivePacket(DataFragment data)
        {
            try {
                int            len = 0, channel = 0;
                SSH1DataReader re = new SSH1DataReader(data);
                PacketType     pt = re.ReadPacketType();
                switch (pt)
                {
                case PacketType.SSH_SMSG_STDOUT_DATA:
                    len = re.ReadInt32();
                    _channel_collection.FindChannelEntry(_shellID).Receiver.OnData(re.Image, re.Offset, len);
                    break;

                case PacketType.SSH_SMSG_STDERR_DATA: {
                    _channel_collection.FindChannelEntry(_shellID).Receiver.OnExtendedData((int)PacketType.SSH_SMSG_STDERR_DATA, re.ReadString());
                }
                break;

                case PacketType.SSH_MSG_CHANNEL_DATA:
                    channel = re.ReadInt32();
                    len     = re.ReadInt32();
                    _channel_collection.FindChannelEntry(channel).Receiver.OnData(re.Image, re.Offset, len);
                    break;

                case PacketType.SSH_MSG_PORT_OPEN:
                    ProcessPortforwardingRequest(_eventReceiver, re);
                    break;

                case PacketType.SSH_MSG_CHANNEL_CLOSE: {
                    channel = re.ReadInt32();
                    ISSHChannelEventReceiver r = _channel_collection.FindChannelEntry(channel).Receiver;
                    _channel_collection.UnregisterChannelEventReceiver(channel);
                    r.OnChannelClosed();
                }
                break;

                case PacketType.SSH_MSG_CHANNEL_CLOSE_CONFIRMATION:
                    channel = re.ReadInt32();
                    break;

                case PacketType.SSH_MSG_DISCONNECT:
                    _eventReceiver.OnConnectionClosed();
                    break;

                case PacketType.SSH_SMSG_EXITSTATUS:
                    _channel_collection.FindChannelEntry(_shellID).Receiver.OnChannelClosed();
                    break;

                case PacketType.SSH_MSG_DEBUG:
                    _eventReceiver.OnDebugMessage(false, re.ReadString());
                    break;

                case PacketType.SSH_MSG_IGNORE:
                    _eventReceiver.OnIgnoreMessage(re.ReadString());
                    break;

                case PacketType.SSH_MSG_CHANNEL_OPEN_CONFIRMATION: {
                    int local  = re.ReadInt32();
                    int remote = re.ReadInt32();
                    _channel_collection.FindChannelEntry(local).Receiver.OnChannelReady();
                }
                break;

                case PacketType.SSH_SMSG_SUCCESS:
                    if (_executingShell)
                    {
                        ExecShell();
                        _channel_collection.FindChannelEntry(_shellID).Receiver.OnChannelReady();
                        _executingShell = false;
                    }
                    break;

                default:
                    _eventReceiver.OnUnknownMessage((byte)pt, re.ReadAll());
                    break;
                }
            }
            catch (Exception ex) {
                _eventReceiver.OnError(ex);
            }
        }
Пример #6
0
 private PacketType SneakPacketType(DataFragment data)
 {
     return((PacketType)data.ByteAt(0));
 }
Пример #7
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int totalRead = 0;

            // Determine fragment
            while (count > 0 && _position < _length)
            {
                long         fragmentOffset;
                DataFragment fragment = FindFragment(_position, out fragmentOffset);

                long diskOffset     = fragment.LCN * _bytesPrCluster;
                long fragmentLength = fragment.Clusters * _bytesPrCluster;

                int actualRead;
                if (fragment.IsCompressed)
                {
                    // Read and decompress
                    byte[] compressedData = new byte[fragmentLength];
                    _diskStream.Seek(diskOffset, SeekOrigin.Begin);
                    _diskStream.Read(compressedData, 0, compressedData.Length);

                    int decompressedLength = (int)((fragment.Clusters + fragment.CompressedClusters) * _bytesPrCluster);
                    int toRead             = (int)Math.Min(decompressedLength - fragmentOffset, Math.Min(_length - _position, count));

                    // Debug.Assert(decompressedLength == _compressionClusterCount * _bytesPrCluster);

                    if (fragmentOffset == 0 && toRead == decompressedLength)
                    {
                        // Decompress directly (we're in the middle of a file and reading a full 16 clusters out)
                        actualRead = _compressor.Decompress(compressedData, 0, compressedData.Length, buffer, offset);
                    }
                    else
                    {
                        // Decompress temporarily
                        byte[] tmp          = new byte[decompressedLength];
                        int    decompressed = _compressor.Decompress(compressedData, 0, compressedData.Length, tmp, 0);

                        toRead = Math.Min(toRead, decompressed);

                        // Copy wanted data
                        Array.Copy(tmp, fragmentOffset, buffer, offset, toRead);

                        actualRead = toRead;
                    }
                }
                else if (fragment.IsSparseFragment)
                {
                    // Fill with zeroes
                    // How much to fill?
                    int toFill = (int)Math.Min(fragmentLength - fragmentOffset, count);

                    Array.Clear(buffer, offset, toFill);

                    actualRead = toFill;
                }
                else
                {
                    // Read directly
                    // How much can we read?
                    int toRead = (int)Math.Min(fragmentLength - fragmentOffset, Math.Min(_length - _position, count));

                    // Read it
                    _diskStream.Seek(diskOffset + fragmentOffset, SeekOrigin.Begin);
                    actualRead = _diskStream.Read(buffer, offset, toRead);
                }

                // Increments
                count  -= actualRead;
                offset += actualRead;

                _position += actualRead;

                totalRead += actualRead;

                // Check
                if (actualRead == 0)
                {
                    break;
                }
            }

            return(totalRead);
        }
Пример #8
0
        private void ReceiveServerKeys()
        {
            DataFragment   packet = ReceivePacket();
            SSH1DataReader reader = new SSH1DataReader(packet);
            PacketType     pt     = reader.ReadPacketType();

            if (pt != PacketType.SSH_SMSG_PUBLIC_KEY)
            {
                throw new SSHException("unexpected SSH SSH1Packet type " + pt, reader.ReadAll());
            }

            _cInfo._serverinfo = new SSHServerInfo(reader);
            _cInfo._hostkey    = new RSAPublicKey(_cInfo._serverinfo.host_key_public_exponent, _cInfo._serverinfo.host_key_public_modulus);

            //read protocol support parameters
            int protocol_flags         = reader.ReadInt32();
            int supported_ciphers_mask = reader.ReadInt32();

            _cInfo.SetSupportedCipherAlgorithms(supported_ciphers_mask);
            int supported_authentications_mask = reader.ReadInt32();

            //Debug.WriteLine(String.Format("ServerOptions {0} {1} {2}", protocol_flags, supported_ciphers_mask, supported_authentications_mask));

            if (reader.Rest > 0)
            {
                throw new SSHException("data length mismatch", reader.ReadAll());
            }

            bool found = false;

            foreach (CipherAlgorithm a in _param.PreferableCipherAlgorithms)
            {
                if (a != CipherAlgorithm.Blowfish && a != CipherAlgorithm.TripleDES)
                {
                    continue;
                }
                else if (a == CipherAlgorithm.Blowfish && (supported_ciphers_mask & (1 << (int)CipherAlgorithm.Blowfish)) == 0)
                {
                    continue;
                }
                else if (a == CipherAlgorithm.TripleDES && (supported_ciphers_mask & (1 << (int)CipherAlgorithm.TripleDES)) == 0)
                {
                    continue;
                }

                _cInfo._algorithmForReception = _cInfo._algorithmForTransmittion = a;
                found = true;
                break;
            }

            if (!found)
            {
                throw new SSHException(String.Format(Strings.GetString("ServerNotSupportedX"), "Blowfish/TripleDES"));
            }

            if (_param.AuthenticationType == AuthenticationType.Password && (supported_authentications_mask & (1 << (int)AuthenticationType.Password)) == 0)
            {
                throw new SSHException(String.Format(Strings.GetString("ServerNotSupportedPassword")), reader.ReadAll());
            }
            if (_param.AuthenticationType == AuthenticationType.PublicKey && (supported_authentications_mask & (1 << (int)AuthenticationType.PublicKey)) == 0)
            {
                throw new SSHException(String.Format(Strings.GetString("ServerNotSupportedRSA")), reader.ReadAll());
            }

            TraceReceptionEvent(pt, "received server key");
        }
Пример #9
0
 public void Send(DataFragment data)
 {
 }
Пример #10
0
 public void OnUnhandledPacket(byte packetType, DataFragment data)
 {
 }
Пример #11
0
 public void OnExtendedData(uint type, DataFragment data)
 {
 }
Пример #12
0
 public void OnEstablished(DataFragment data)
 {
 }
Пример #13
0
 // for debug
 private void Dump(string caption, DataFragment data)
 {
     Dump(caption, data.Data, data.Offset, data.Length);
 }