Пример #1
0
        public static byte[] GetAuthenticationData(TacacsAuthenticationService service, string user,
                                                   SecureString password)
        {
            var userBuf = user.GetUserBuffer();

            var authenticationHeader = new TacacsAuthenticationRequestHeader()
            {
                Action             = TacacsAction.Login,
                PrivilegeLevel     = 0x01,
                AuthenticationType = TacacsAuthenticationType.MsChap,
                Service            = service,
                UserLength         = ((byte)userBuf.Length),
                PortLength         = ((byte)ClientPortName.Length),
                RemoteLength       = 0x00, // optional -- excluded
                DataLength         = 0x42  // 66 bytes
            };

            var challenge = new byte[8];

            Rng.GetBytes(challenge, 0, 8);

            var lmChallengeResponse = GetLmChallengeResponse(challenge, password);
            var ntChallengeResponse = GetNtChallengeResponse(challenge, password);

            // MS-CHAPv1 response (49 bytes) -- see RFC 2433
            var challengeResponse = new byte[49];

            Buffer.BlockCopy(lmChallengeResponse, 0, challengeResponse, 0, 24);
            Buffer.BlockCopy(ntChallengeResponse, 0, challengeResponse, 24, 24);
            Buffer.BlockCopy(new byte[] { 0x01 }, 0, challengeResponse, 48, 1);

            // ppp id
            var identifier = new byte[1];

            Rng.GetBytes(identifier, 0, 1);

            // draft 18 -- 5.4.2.4
            var data = new byte[66];

            Buffer.BlockCopy(identifier, 0, data, 0, 1);
            Buffer.BlockCopy(challenge, 0, data, 1, 16);
            Buffer.BlockCopy(challengeResponse, 0, data, 17, 49);

            // tacacs data
            var authenticationDataLength =
                8 /* header */ + userBuf.Length + ClientPortName.Length + 0 /* remote */ + 66 /* MsChapV2 length */;
            var authenticationData = new byte[authenticationDataLength];
            var headerBuf          = StructConverter.StructToBytes(authenticationHeader);

            Buffer.BlockCopy(headerBuf, 0, authenticationData, 0, 8);
            Buffer.BlockCopy(userBuf, 0, authenticationData, 8, userBuf.Length);
            Buffer.BlockCopy(ClientPortName, 0, authenticationData, 8 + userBuf.Length, ClientPortName.Length);
            Buffer.BlockCopy(data, 0, authenticationData, 8 + userBuf.Length + ClientPortName.Length, data.Length);

            return(authenticationData);
        }
Пример #2
0
        public static byte[] CreatePacket(TacacsHeader header, byte[] data, SecureString sharedSecret)
        {
            header.Length = data.Length;
            var packetLength = 12 /* tacacs header len */ + data.Length;
            var packet       = new byte[packetLength];
            var headerBuf    = StructConverter.StructToBytes(header);

            Buffer.BlockCopy(headerBuf, 0, packet, 0, 12);
            var obfuscated = ObfuscateData(header, data, sharedSecret);

            Buffer.BlockCopy(obfuscated, 0, packet, 12, obfuscated.Length);
            return(packet);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        public void QueryTopInfo()
        {
            MsgHeader mh = new MsgHeader();

            //参数赋值
            mh.MsgID = ConstIDs.O_TDMOM_TOP_INFO_REQ;

            mh.puData  = 0;
            mh.DataLen = 0;
            mh.MsgLen  = (uint)Marshal.SizeOf(mh);

            byte[] res_mh = StructConverter.StructToBytes(mh);
        }
Пример #4
0
        public static byte[] GetAuthenticationData(TacacsAuthenticationService service, string user,
                                                   SecureString password)
        {
            var userBuf = user.GetUserBuffer();

            var authenticationHeader = new TacacsAuthenticationRequestHeader()
            {
                Action             = TacacsAction.Login,
                PrivilegeLevel     = 0x01,
                AuthenticationType = TacacsAuthenticationType.Chap,
                Service            = service,
                UserLength         = ((byte)userBuf.Length),
                PortLength         = ((byte)ClientPortName.Length),
                RemoteLength       = 0x00, // optional -- excluded
                DataLength         = 0x42  // 66 bytes -- big challenge
            };

            var identifier = new byte[1];

            Rng.GetBytes(identifier, 0, 1);
            //var challenge = new byte[49];
            //Rng.GetBytes(challenge, 0, 32);
            var challenge = Encoding.ASCII.GetBytes("1234567890123456789012345678901234567890123456789");

            var response = GetResponse(identifier, challenge, password);
            var data     = new byte[1 /* identifier */ + 49 /* challenge */ + 16 /* response */];

            Buffer.BlockCopy(identifier, 0, data, 0, 1);
            Buffer.BlockCopy(challenge, 0, data, 1, 49);
            Buffer.BlockCopy(response, 0, data, 50, 16);

            var authenticationDataLength =
                8 /* header */ + userBuf.Length + ClientPortName.Length + 0 /* remote */ + 66 /* CHAP length */;
            var authenticationData = new byte[authenticationDataLength];
            var headerBuf          = StructConverter.StructToBytes(authenticationHeader);

            Buffer.BlockCopy(headerBuf, 0, authenticationData, 0, 8);
            Buffer.BlockCopy(userBuf, 0, authenticationData, 8, userBuf.Length);
            Buffer.BlockCopy(ClientPortName, 0, authenticationData, 8 + userBuf.Length, ClientPortName.Length);
            Buffer.BlockCopy(data, 0, authenticationData, 8 + userBuf.Length + ClientPortName.Length, data.Length);

            return(authenticationData);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        public void SendIpInfo()
        {
            MsgHeader mh = new MsgHeader();

            //参数赋值
            mh.MsgID = ConstIDs.O_TDMOM_IP_PORT_CFG;

            mh.puData  = 0;
            mh.DataLen = 0;
            mh.MsgLen  = (uint)Marshal.SizeOf(mh);

            byte[] res_mh = StructConverter.StructToBytes(mh);

            IpPortCFCStruct ips = new IpPortCFCStruct();

            byte[] strbytes = System.Text.Encoding.Unicode.GetBytes(_configService.ConfigInfos.TermialIP);
            Buffer.BlockCopy(strbytes, 0, ips.IpAddr, 0, ips.IpAddr.Length > strbytes.Length ? strbytes.Length : ips.IpAddr.Length);
            ips.PortNum = (uint)_configService.ConfigInfos.TerminalPort;

            //发送
        }
Пример #6
0
 public static byte[] WriteSimpleStruct <T>(T obj) where T : struct
 {
     return(StructConverter.StructToBytes(obj));
 }
Пример #7
0
        public static byte[] GetAuthenticationData(TacacsAuthenticationService service, string user,
                                                   SecureString password)
        {
            var userBuf = user.GetUserBuffer();

            var authenticationHeader = new TacacsAuthenticationRequestHeader()
            {
                Action             = TacacsAction.Login,
                PrivilegeLevel     = 0x01,
                AuthenticationType = TacacsAuthenticationType.MsChapV2,
                Service            = service,
                UserLength         = ((byte)userBuf.Length),
                PortLength         = ((byte)ClientPortName.Length),
                RemoteLength       = 0x00, // optional -- excluded
                DataLength         = 0x42  // 66 bytes
            };

            var authenticatorChallenge = new byte[16];
            var peerChallenge          = new byte[16];

            Rng.GetBytes(authenticatorChallenge, 0, 16);
            Rng.GetBytes(peerChallenge, 0, 16);

            // see RFC 2433
            var challengeResponse = new byte[49];

            // challenge -- 16 bytes
            Buffer.BlockCopy(peerChallenge, 0, challengeResponse, 0, 16);
            // reserved -- 8 bytes (zeroes)
            for (var i = 16; i < 24; i++)
            {
                Buffer.SetByte(challengeResponse, i, 0x00);
            }
            // NT-response -- 24 bytes
            var ntResponse = GetNtResponse(authenticatorChallenge, peerChallenge, userBuf, password);

            Buffer.BlockCopy(ntResponse, 0, challengeResponse, 24, 24);
            // flags -- 1 byte (zero)
            Buffer.SetByte(challengeResponse, 48, 0);

            var identifier = new byte[1];

            Rng.GetBytes(identifier, 0, 1);

            // draft 18 -- 5.4.2.5
            var data = new byte[66];

            Buffer.BlockCopy(identifier, 0, data, 0, 1);
            Buffer.BlockCopy(authenticatorChallenge, 0, data, 1, 16);
            Buffer.BlockCopy(challengeResponse, 0, data, 17, 49);

            // tacacs data
            var authenticationDataLength =
                8 /* header */ + userBuf.Length + ClientPortName.Length + 0 /* remote */ + 66 /* MsChapV2 length */;
            var authenticationData = new byte[authenticationDataLength];
            var headerBuf          = StructConverter.StructToBytes(authenticationHeader);

            Buffer.BlockCopy(headerBuf, 0, authenticationData, 0, 8);
            Buffer.BlockCopy(userBuf, 0, authenticationData, 8, userBuf.Length);
            Buffer.BlockCopy(ClientPortName, 0, authenticationData, 8 + userBuf.Length, ClientPortName.Length);
            Buffer.BlockCopy(data, 0, authenticationData, 8 + userBuf.Length + ClientPortName.Length, data.Length);

            return(authenticationData);
        }
Пример #8
0
        public void WriteSimpleStruct <T>(T obj) where T : struct
        {
            byte[] bytes = StructConverter.StructToBytes(obj);

            Write(bytes);
        }