コード例 #1
0
        /// <summary>
        /// Expect client to connect share "$IPC", tcp or netbios connect is not included
        /// </summary>
        /// <param name="timeout">timeout</param>
        /// <returns>The client endpoint</returns>
        public override FsEndpoint ExpectConnectIpcShare(TimeSpan timeout)
        {
            CifsServerPerConnection   connection;
            SmbNegotiateRequestPacket negotiateRequest = this.cifsServer.ExpectPacket(
                timeout, out connection) as SmbNegotiateRequestPacket;

            //ushort uid = (ushort)Interlocked.Increment(ref nextUid);

            SmbNegotiateResponsePacket negotiateResponse =
                this.cifsServer.CreateNegotiateResponse(connection, negotiateRequest, SecurityModes.NONE);

            this.cifsServer.SendPacket(negotiateResponse, connection);

            SmbSessionSetupAndxRequestPacket sessionSetupRequest =
                this.cifsServer.ExpectPacket(timeout, out connection) as SmbSessionSetupAndxRequestPacket;

            SmbSessionSetupAndxResponsePacket sessionSetupResponse =
                this.cifsServer.CreateSessionSetupAndxResponse(connection, sessionSetupRequest, ActionValues.NONE,
                                                               null);

            this.cifsServer.SendPacket(sessionSetupResponse, connection);

            SmbTreeConnectAndxRequestPacket treeConnectRequest =
                this.cifsServer.ExpectPacket(timeout, out connection) as SmbTreeConnectAndxRequestPacket;


            SmbTreeConnectAndxResponsePacket treeConnectResponse =
                this.cifsServer.CreateTreeConnectAndxResponse(connection, treeConnectRequest, OptionalSupport.NONE,
                                                              IPC_SERVICE_NAME, null);

            this.cifsServer.SendPacket(treeConnectResponse, connection);

            return(this.fsEndpoints[connection.Identity]);
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbNegotiateResponsePacket(SmbNegotiateResponsePacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.DialectIndex = packet.SmbParameters.DialectIndex;
            this.smbParameters.SecurityMode = packet.SmbParameters.SecurityMode;
            this.smbParameters.MaxMpxCount = packet.SmbParameters.MaxMpxCount;
            this.smbParameters.MaxNumberVcs = packet.SmbParameters.MaxNumberVcs;
            this.smbParameters.MaxBufferSize = packet.SmbParameters.MaxBufferSize;
            this.smbParameters.MaxRawSize = packet.SmbParameters.MaxRawSize;
            this.smbParameters.SessionKey = packet.SmbParameters.SessionKey;
            this.smbParameters.Capabilities = packet.SmbParameters.Capabilities;
            this.smbParameters.SystemTime = new FileTime();
            this.smbParameters.SystemTime.Time = packet.SmbParameters.SystemTime.Time;
            this.smbParameters.ServerTimeZone = packet.SmbParameters.ServerTimeZone;
            this.smbParameters.ChallengeLength = packet.SmbParameters.ChallengeLength;
            this.smbData.ByteCount = packet.SmbData.ByteCount;

            if (packet.smbData.Challenge != null)
            {
                this.smbData.Challenge = new byte[packet.smbData.Challenge.Length];
                Array.Copy(packet.smbData.Challenge, this.smbData.Challenge, packet.smbData.Challenge.Length);
            }
            else
            {
                this.smbData.Challenge = new byte[0];
            }

            if (packet.smbData.DomainName != null)
            {
                this.smbData.DomainName = new byte[packet.smbData.DomainName.Length];
                Array.Copy(packet.smbData.DomainName, this.smbData.DomainName, packet.smbData.DomainName.Length);
            }
            else
            {
                this.smbData.DomainName = new byte[0];
            }
        }
コード例 #3
0
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbNegotiateResponsePacket(SmbNegotiateResponsePacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount       = packet.SmbParameters.WordCount;
            this.smbParameters.DialectIndex    = packet.SmbParameters.DialectIndex;
            this.smbParameters.SecurityMode    = packet.SmbParameters.SecurityMode;
            this.smbParameters.MaxMpxCount     = packet.SmbParameters.MaxMpxCount;
            this.smbParameters.MaxNumberVcs    = packet.SmbParameters.MaxNumberVcs;
            this.smbParameters.MaxBufferSize   = packet.SmbParameters.MaxBufferSize;
            this.smbParameters.MaxRawSize      = packet.SmbParameters.MaxRawSize;
            this.smbParameters.SessionKey      = packet.SmbParameters.SessionKey;
            this.smbParameters.Capabilities    = packet.SmbParameters.Capabilities;
            this.smbParameters.SystemTime      = new FileTime();
            this.smbParameters.SystemTime.Time = packet.SmbParameters.SystemTime.Time;
            this.smbParameters.ServerTimeZone  = packet.SmbParameters.ServerTimeZone;
            this.smbParameters.ChallengeLength = packet.SmbParameters.ChallengeLength;
            this.smbData.ByteCount             = packet.SmbData.ByteCount;

            if (packet.smbData.Challenge != null)
            {
                this.smbData.Challenge = new byte[packet.smbData.Challenge.Length];
                Array.Copy(packet.smbData.Challenge, this.smbData.Challenge, packet.smbData.Challenge.Length);
            }
            else
            {
                this.smbData.Challenge = new byte[0];
            }

            if (packet.smbData.DomainName != null)
            {
                this.smbData.DomainName = new byte[packet.smbData.DomainName.Length];
                Array.Copy(packet.smbData.DomainName, this.smbData.DomainName, packet.smbData.DomainName.Length);
            }
            else
            {
                this.smbData.DomainName = new byte[0];
            }
        }
コード例 #4
0
        public SmbNegotiateResponsePacket CreateNegotiateResponse(
            CifsServerPerConnection connection,
            SmbNegotiateRequestPacket request,
            SecurityModes securityMode)
        {
            SmbNegotiateResponsePacket response = new SmbNegotiateResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            Stack<string> dialectStrings = new Stack<string>();

            for (int offset = 0; offset < request.SmbData.Dialects.Length; offset++)
            {
                string dialectString = CifsMessageUtils.ToSmbString(request.SmbData.Dialects, offset, true);
                dialectStrings.Push(dialectString);
                offset += sizeof(byte) + dialectString.Length;
            }

            while(dialectStrings.Count > 0)
            {
                string dialectString = dialectStrings.Pop();
                if(dialectString == CifsMessageUtils.DIALECT_NTLANMAN)
                {
                    SMB_COM_NEGOTIATE_NtLanManagerResponse_SMB_Parameters smbParameters = response.SmbParameters;
                    smbParameters.WordCount = (byte)((Marshal.SizeOf(response.SmbParameters) - sizeof(byte)) / 2);
                    smbParameters.DialectIndex = (ushort)dialectStrings.Count;
                    smbParameters.SecurityMode = securityMode;
                    smbParameters.MaxMpxCount = (ushort)this.context.MaxMpxCount;
                    smbParameters.MaxNumberVcs = (ushort)this.context.MaxNumberVcs;
                    smbParameters.MaxBufferSize = (ushort)this.context.MaxBufferSize;
                    smbParameters.MaxRawSize = (ushort)this.context.MaxRawSize;
                    smbParameters.SessionKey = 0;
                    smbParameters.Capabilities = this.context.Capabilities;
                    FileTime fileTime = new FileTime();
                    fileTime.Time = (ulong)DateTime.Now.ToFileTime();
                    smbParameters.SystemTime = fileTime;

                    smbParameters.ServerTimeZone = (short)TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Minutes;
                    smbParameters.ChallengeLength = (byte)connection.NTLMChallenge.Length;
                    response.SmbParameters = smbParameters;

                    SMB_COM_NEGOTIATE_NtLanManagerResponse_SMB_Data smbData = response.SmbData;
                    smbData.Challenge = connection.NTLMChallenge;
                    smbData.DomainName = CifsMessageUtils.ToSmbStringBytes(this.context.DomainName, true);
                    smbData.ByteCount = (ushort)(smbData.Challenge.Length + smbData.DomainName.Length);
                    response.SmbData = smbData;

                    return response;
                }
                else if (dialectString == CifsMessageUtils.DIALECT_PCLAN
                    || dialectString == CifsMessageUtils.DIALECT_PCNETWORK_PROGRAM)
                {
                    SMB_COM_NEGOTIATE_NtLanManagerResponse_SMB_Parameters smbParameters = response.SmbParameters;
                    smbParameters.WordCount = 0x1;
                    smbParameters.DialectIndex = (ushort)dialectStrings.Count;
                    response.SmbParameters = smbParameters;

                    SMB_COM_NEGOTIATE_NtLanManagerResponse_SMB_Data smbData = response.SmbData;
                    smbData.Challenge = connection.NTLMChallenge;
                    smbData.DomainName = CifsMessageUtils.ToSmbStringBytes(this.context.DomainName, true);
                    smbData.ByteCount = (ushort)(smbData.Challenge.Length + smbData.DomainName.Length);
                    response.SmbData = smbData;

                    return response;
                }
            }

            throw new NotSupportedException("None of these dialects is supported.");
        }