示例#1
0
        private void ProcessAgentForwardRequest(ISSHConnectionEventReceiver receiver, SSH2DataReader reader) {
            int remote_channel = reader.ReadInt32();
            int window_size = reader.ReadInt32(); //skip initial window size
            int servermaxpacketsize = reader.ReadInt32();
            TraceReceptionEvent("agent forward request", "");

            SSH2DataWriter wr = new SSH2DataWriter();
            IAgentForward af = _param.AgentForward;
            if (_agentForwardConfirmed && af != null && af.CanAcceptForwarding()) {
                //send OPEN_CONFIRMATION
                AgentForwardingChannel ch = new AgentForwardingChannel(af);
                SSH2Channel channel = new SSH2Channel(this, ChannelType.AgentForward, this.ChannelCollection.RegisterChannelEventReceiver(null, ch).LocalID, remote_channel, servermaxpacketsize);
                ch.SetChannel(channel);
                wr.WritePacketType(PacketType.SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
                wr.WriteInt32(remote_channel);
                wr.WriteInt32(channel.LocalChannelID);
                wr.WriteInt32(_param.WindowSize); //initial window size
                wr.WriteInt32(_param.MaxPacketSize); //max packet size
                TraceTransmissionEvent("granados confirmed agent-forwarding request", "");
            }
            else {
                wr.WritePacketType(PacketType.SSH_MSG_CHANNEL_OPEN_FAILURE);
                wr.WriteInt32(remote_channel);
                wr.WriteInt32(0);
                wr.WriteString("reject");
                wr.WriteString(""); //lang tag
                TraceTransmissionEvent("granados rejected agent-forwarding request", "");
            }
            TransmitRawPayload(wr.ToByteArray());
        }
示例#2
0
        public override SSHChannel ForwardPort(ISSHChannelEventReceiver receiver, string remote_host, int remote_port, string originator_host, int originator_port) {
            SSH2TransmissionPacket packet = OpenPacket();
            SSH2DataWriter wr = packet.DataWriter;
            wr.WritePacketType(PacketType.SSH_MSG_CHANNEL_OPEN);
            wr.WriteString("direct-tcpip");
            int local_id = this.ChannelCollection.RegisterChannelEventReceiver(null, receiver).LocalID;
            wr.WriteInt32(local_id);
            wr.WriteInt32(_param.WindowSize); //initial window size
            int windowsize = _param.WindowSize;
            wr.WriteInt32(_param.MaxPacketSize); //max packet size
            wr.WriteString(remote_host);
            wr.WriteInt32(remote_port);
            wr.WriteString(originator_host);
            wr.WriteInt32(originator_port);

            SSH2Channel channel = new SSH2Channel(this, ChannelType.ForwardedLocalToRemote, local_id, null);

            TraceTransmissionEvent(PacketType.SSH_MSG_CHANNEL_OPEN, "opening a forwarded port : host={0} port={1}", remote_host, remote_port);
            TransmitPacket(packet);

            return channel;
        }
示例#3
0
        private void ProcessPortforwardingRequest(ISSHConnectionEventReceiver receiver, SSH2DataReader reader) {

            int remote_channel = reader.ReadInt32();
            int window_size = reader.ReadInt32(); //skip initial window size
            int servermaxpacketsize = reader.ReadInt32();
            string host = Encoding.ASCII.GetString(reader.ReadString());
            int port = reader.ReadInt32();
            string originator_ip = Encoding.ASCII.GetString(reader.ReadString());
            int originator_port = reader.ReadInt32();

            TraceReceptionEvent("port forwarding request", String.Format("host={0} port={1} originator-ip={2} originator-port={3}", host, port, originator_ip, originator_port));
            PortForwardingCheckResult r = receiver.CheckPortForwardingRequest(host, port, originator_ip, originator_port);
            SSH2DataWriter wr = new SSH2DataWriter();
            if (r.allowed) {
                //send OPEN_CONFIRMATION
                SSH2Channel channel = new SSH2Channel(this, ChannelType.ForwardedRemoteToLocal, this.ChannelCollection.RegisterChannelEventReceiver(null, r.channel).LocalID, remote_channel, servermaxpacketsize);
                wr.WritePacketType(PacketType.SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
                wr.WriteInt32(remote_channel);
                wr.WriteInt32(channel.LocalChannelID);
                wr.WriteInt32(_param.WindowSize); //initial window size
                wr.WriteInt32(_param.MaxPacketSize); //max packet size
                receiver.EstablishPortforwarding(r.channel, channel);
                TraceTransmissionEvent("port-forwarding request is confirmed", "host={0} port={1} originator-ip={2} originator-port={3}", host, port, originator_ip, originator_port);
            }
            else {
                wr.WritePacketType(PacketType.SSH_MSG_CHANNEL_OPEN_FAILURE);
                wr.WriteInt32(remote_channel);
                wr.WriteInt32(r.reason_code);
                wr.WriteString(r.reason_message);
                wr.WriteString(""); //lang tag
                TraceTransmissionEvent("port-forwarding request is rejected", "host={0} port={1} originator-ip={2} originator-port={3}", host, port, originator_ip, originator_port);
            }
            TransmitRawPayload(wr.ToByteArray());
        }
示例#4
0
        //open channel
        private SSHChannel DoExecCommandInternal(ISSHChannelEventReceiver receiver, ChannelType channel_type, string command, string message) {
            SSH2TransmissionPacket packet = OpenPacket();
            SSH2DataWriter wr = packet.DataWriter;
            wr.WritePacketType(PacketType.SSH_MSG_CHANNEL_OPEN);
            wr.WriteString("session");
            int local_channel = this.ChannelCollection.RegisterChannelEventReceiver(null, receiver).LocalID;

            wr.WriteInt32(local_channel);
            wr.WriteInt32(_param.WindowSize); //initial window size
            int windowsize = _param.WindowSize;
            wr.WriteInt32(_param.MaxPacketSize); //max packet size
            SSH2Channel channel = new SSH2Channel(this, channel_type, local_channel, command);
            TraceTransmissionEvent(PacketType.SSH_MSG_CHANNEL_OPEN, message);
            TransmitPacket(packet);

            return channel;
        }