Ejemplo n.º 1
0
        public bool ReceivedProtocol(networkServer.networkClientInterface NetworkClient, string protocolString)
        {
            Protocol protocol = new Protocol(protocolString);

            switch (protocol.GetKey())
            {
            case 600:
                return(CheckPing(ref NetworkClient, protocol));

            case 500:
                return(AuthenticateUser(NetworkClient, protocol));

            case 701:
                return(HackDetection_Heuristic(NetworkClient, protocol));

            case 702:
                return(HackDetection_VirtualMemory(NetworkClient, protocol));

            case 703:
                return(HackDetection_File(NetworkClient, protocol));

            default:
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.CLIENT, "Received invalid protocol: " + protocolString);
                return(false);
            }
        }
 //Login
 private void Tel_102_loginUser(List <string> lDataList, ref networkServer.networkClientInterface relatedClient)
 {
     try
     {
         //log
         Logger.writeInLog(true, "Message #102 (LOGIN) received from a client!");
         //Try to login user
         int iUserID          = 0;
         int iLoginStatusCode = DatabaseEngine.loginUser(lDataList[0], lDataList[1], ref iUserID);
         //Send message to client
         if (iLoginStatusCode != 1)
         {
             TcpServer.sendMessage("#103" + cProtocolDelimiter + iLoginStatusCode, relatedClient);
         }
         else
         {
             TcpServer.sendMessage("#103" + cProtocolDelimiter + iLoginStatusCode + cProtocolDelimiter + iUserID, relatedClient);
         }
         Logger.writeInLog(true, "Answered #103 with LoginCode " + iLoginStatusCode + ". The user id is " + iUserID + "!");
     }
     catch (Exception e)
     {
         Logger.writeInLog(true, "ERROR: Something went wrong with telegram (LOGIN)! Message: " + e.ToString());
         return;
     }
 }
Ejemplo n.º 3
0
        public void AuthHackError()
        {
            //CCstData.GetInstance(Core.Application).Logger.Seperate();
            //CCstData.GetInstance(Core.Application).Logger.writeInLog(3, Support.LogCategory.OK, "Test AuthHackError started!");
            Random Ran        = new Random();
            string HardwareID = Ran.Next(1, 50000).ToString();

            networkServer.networkClientInterface dummy = new networkServer.networkClientInterface();
            Core.ProtocolController.ReceivedProtocol(dummy, String.Format("500;{0};{1};Windoofs 7;Deutsch;1", HardwareID, Core.Application.Hash));
            string SessionID = "";

            foreach (var item in Core.ActiveConnections)
            {
                if (item.User.ID == HardwareID &&
                    item.User.Application.ID == 1)
                {
                    SessionID = item.SessionID;
                    dummy     = item;
                }
            }
            bool Test = Core.ProtocolController.ReceivedProtocol(Client, String.Format("701;{0};Process;Window;Class;MD5", SessionID));

            Test = Core.ProtocolController.ReceivedProtocol(Client, String.Format("701;{0};Process;Window;Class;MD5", SessionID));
            Test = Core.ProtocolController.ReceivedProtocol(Client, String.Format("701;{0};Process;Window;Class;MD5", SessionID));
            Test = Core.ProtocolController.ReceivedProtocol(Client, String.Format("701;{0};Process;Window;Class;MD5", SessionID));
            Test = Core.ProtocolController.ReceivedProtocol(Client, String.Format("701;{0};Process;Window;Class;MD5", SessionID));
            Test = Core.ProtocolController.ReceivedProtocol(Client, String.Format("701;{0};Process;Window;Class;MD5", SessionID));
            Core.ActiveConnections.Remove(dummy);
            Assert.AreEqual(Core.ProtocolController.ReceivedProtocol(dummy, String.Format("500;{0};{1};Windoofs 7;Deutsch;1", HardwareID, Core.Application.Hash)), false);

            //CCstData.GetInstance(Core.Application).Logger.writeInLog(3, Support.LogCategory.OK, "Test AuthHackError finished!");
            //CCstData.GetInstance(Core.Application).Logger.Seperate();
        }
Ejemplo n.º 4
0
 public void NetworkProtocol(ref networkServer.networkClientInterface NetworkClient, string message)
 {
     //Public for the Unit Tests
     CCstData.GetInstance(Application).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Protocol received: " + message);
     try
     {
         //Öañ4\u001b3[\b\nÎbÞö}\u0010VDYZ‚\u009d\u0005sQ˜e@p•\u001e\ab{󥟛¨YÉ`\\wõˆ¹éî\0
         if (message[message.Length - 1] == '\0')
         {
             message = message.Substring(0, message.Length - 1);
         }
         //Decrypt received protocol
         // QUESTION: Can we somehow see if we get something that isn't encrypted like traffic?
         // QUESTION: Is it possible to decrypt something that isn't enchrypted and send it to the ProtocolController?
         // QUESTION: Or does the decryption function checck all this?
         List <char> Chars = message.ToList();
         message = AES_Converter.DecryptFromCBC(CCstData.GetInstance(Application).EncryptionKey, CCstData.GetInstance(Application).EncryptionIV, message);
         if (message[message.Length - 1] == '\0')
         {
             message = message.Substring(0, message.Length - 1);
         }
     }
     catch (Exception e)
     {
         //If decryption failed, something was probably manipulated -> Log it
         CCstData.GetInstance(Application).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.SERVER, "Protocol Decryption failed! Message: " + message + ", Error: " + e.ToString());
         return;
     }
     CCstData.GetInstance(Application).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, "Protocol received decrypted: " + message);
     ProtocolController.ReceivedProtocol(NetworkClient, message);
 }
        private void Tel_209_requestFullExerciseData(List <string> lDataList, ref networkServer.networkClientInterface relatedClient)
        {
            try
            {
                //log
                Logger.writeInLog(true, "Message #209 (REQ_FULLEXERCISEDATA) received from a client!");
                //Get room data
                List <List <string> > llExercises = new List <List <string> >();
                llExercises = DatabaseEngine.getFullExerciseData(Convert.ToInt32(lDataList[0]));
                //Build protocol
                string sProtocol = "#210" + cProtocolDelimiter.ToString();
                sProtocol += llExercises.Count + cProtocolDelimiter.ToString();
                for (int i = 0; i < llExercises.Count; i++)
                {
                    for (int d = 0; d < llExercises[i].Count; d++)
                    {
                        sProtocol += llExercises[i][d] + cDataDelimiter.ToString();
                    }
                    sProtocol += cProtocolDelimiter.ToString();
                    //Remove the last cDataDelimiter
                }
                //Remove last cProtocolDelimiter
                sProtocol = sProtocol.Remove(sProtocol.Length - 1);

                //Send message to client
                TcpServer.sendMessage(sProtocol, relatedClient);
                Logger.writeInLog(true, "Answered #210 with all excercises of a level with ID: " + lDataList[0] + ". " + llExercises.Count + " exercises sent!");
            }
            catch (Exception e)
            {
                Logger.writeInLog(true, "ERROR: Something went wrong with telegram (REQ_FULLEXERCISEDATA)! Message: " + e.ToString());
                return;
            }
        }
Ejemplo n.º 6
0
        private bool AuthenticateUser(networkServer.networkClientInterface ClientInterface, Protocol prot)
        {
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authenticating new user ({0})", prot.GetUserID()));
            ArrayList Objects = prot.GetValues();

            if (Objects.Count != 4)
            {
                //Log error - protocol size not as expected
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.CLIENT, String.Format("Unexpected size of protocol. Expected are 4 but it was {0}. Protocol: {1}", Objects.Count, prot.GetOriginalString()));
                return(false);
            }

            //Computer ID, Computer Architecture, Language, Version
            string ApplicationHash = Objects[1].ToString();
            string architecture    = Objects[2].ToString();
            string language        = Objects[3].ToString();
            double version;

            if (!Double.TryParse(Objects[0].ToString(), out version))
            {
                //Log error - protocol index 3 is not as expected
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.CLIENT, "Double expected but received " + Objects[3].ToString());
                return(false);
            }
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentification protocol correct. ApplicationHash={0}, Architecture={1}, Language={2}, Version={3}", ApplicationHash, architecture, language, version));

            //Check if user exists and add it to the list
            return(AddUserToActiveConnections(ref ClientInterface, ApplicationHash, prot.GetUserID(), architecture, language, version));
        }
        private void Tel_207_requestLevelOverview(List <string> lDataList, ref networkServer.networkClientInterface relatedClient)
        {
            try
            {
                //log
                Logger.writeInLog(true, "Message #207 (REQ_LEVELOVERVIEW) received from a client!");
                //Get room data
                List <List <string> > llLevel = new List <List <string> >();
                llLevel = DatabaseEngine.getLevelOverviewData(Convert.ToInt32(lDataList[0]));
                //Build protocol
                string sProtocol = "#208" + cProtocolDelimiter.ToString();
                //sProtocol += llWorkoutData.Count + cProtocolDelimiter.ToString(); <- Keine Anzahl angegeben
                for (int i = 0; i < llLevel.Count; i++)
                {
                    for (int d = 0; d < llLevel[i].Count; d++)
                    {
                        sProtocol += llLevel[i][d] + cDataDelimiter.ToString();
                    }
                    sProtocol += cProtocolDelimiter.ToString();
                    //Remove the last cDataDelimiter
                }
                //Remove last cProtocolDelimiter
                sProtocol = sProtocol.Remove(sProtocol.Length - 1);

                //Send message to client
                TcpServer.sendMessage(sProtocol, relatedClient);
                Logger.writeInLog(true, "Answered #208 with all levels for workout with ID: " + lDataList[0] + ". " + llLevel.Count + " levels sent!");
            }
            catch (Exception e)
            {
                Logger.writeInLog(true, "ERROR: Something went wrong with telegram (REQ_LEVELOVERVIEW)! Message: " + e.ToString());
                return;
            }
        }
        private void Tel_211_requestRoomOverview(List <string> lDataList, ref networkServer.networkClientInterface relatedClient)
        {
            try
            {
                //log
                Logger.writeInLog(true, "Message #211 (REQ_ROOMOVERVIEWDATA2) received from a client!");
                //Get room data
                List <List <string> > llRoomData = new List <List <string> >();
                llRoomData = DatabaseEngine.getRoomOverViewData2(Convert.ToInt32(lDataList[0]));
                //Build protocol
                string sProtocol = "#212" + cProtocolDelimiter.ToString();
                sProtocol += llRoomData.Count + cProtocolDelimiter.ToString();
                for (int i = 0; i < llRoomData.Count; i++)
                {
                    for (int d = 0; d < llRoomData[i].Count; d++)
                    {
                        sProtocol += llRoomData[i][d] + cDataDelimiter.ToString();
                    }
                    //Remove the last cDataDelimiter
                    sProtocol  = sProtocol.Remove(sProtocol.Length - 1);
                    sProtocol += cProtocolDelimiter.ToString();
                }
                //Remove last cProtocolDelimiter
                sProtocol = sProtocol.Remove(sProtocol.Length - 1);

                //Send message to client
                TcpServer.sendMessage(sProtocol, relatedClient);
                Logger.writeInLog(true, "Answered #212 with specific room data. " + llRoomData.Count + " room entries sent!");
            }
            catch (Exception e)
            {
                Logger.writeInLog(true, "ERROR: Something went wrong with telegram (REQ_ROOMOVERVIEWDATA2)! Message: " + e.ToString());
                return;
            }
        }
Ejemplo n.º 9
0
 public void Authentification()
 {
     //CCstData.GetInstance(Core.Application).Logger.Seperate();
     ////CCstData.GetInstance(Core.Application).Logger.writeInLog(3, Support.LogCategory.OK, "Test Authentification started!");
     networkServer.networkClientInterface dummy = new networkServer.networkClientInterface();
     Assert.AreEqual(Core.ProtocolController.ReceivedProtocol(dummy, String.Format("500;12312315;{0};1;Windoofs 7;Deutsch", Core.Application.Hash)), true);
     ////CCstData.GetInstance(Core.Application).Logger.writeInLog(3, Support.LogCategory.OK, "Test Authentification finished!");
     //CCstData.GetInstance(Core.Application).Logger.Seperate();
 }
        //Konstruktor
        public ControllerCore(short _iPort, char _cProtocolDelimiter, char _cDataDelimiter, string _sAesKey, string _sDatabaseDriver,
                              string _sDBHostIp, short _sDBPort, string _sDBUser, string _sDBPass, string _sDBDefaultDB, string _sLogPath)
        {
            //Logging initialisations
            Logger = new logWriter(_sLogPath);
            Logger.writeInLog(true, "Logging class initialized!");
            //Database Initialisations
            if (_sDatabaseDriver == "mysql")
            {
                DatabaseEngine = new DBMysqlDataManager(_sDBHostIp, _sDBUser, _sDBPass, _sDBPort, _sDBDefaultDB);
            }
            else if (_sDatabaseDriver == "mssql")
            {
                DatabaseEngine = new DBMssqlDataManager(_sDBHostIp, _sDBUser, _sDBPass, _sDBPort, _sDBDefaultDB);
            }
            //Database test
            if (DatabaseEngine.testDBConnection())
            {
                Logger.writeInLog(true, "Database test successfull!");
            }
            else
            {
                Logger.writeInLog(true, "ERROR: Database test was not successfull!");
                return;
            }

            //Network Initialisations
            ActiveConnections       = new List <networkServer.networkClientInterface>();
            sAesKey                 = _sAesKey;
            this.cProtocolDelimiter = _cProtocolDelimiter;
            this.cDataDelimiter     = _cDataDelimiter;
            TcpServer               = new networkServer(NetworkProtocol, _sAesKey, IPAddress.Any, _iPort, AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            Logger.writeInLog(true, "TCP Server ready for start!");


            //TESTCASE
            networkServer.networkClientInterface dummy = new networkServer.networkClientInterface();
            //Auth
            //  networkProtocol("#104;Anderson2;Lars;Pickelin;miau1234;[email protected]", ref dummy);
            //  networkProtocol("#102;Anderson2;miau1x234", ref dummy);
            //Content
            //Get all rooms
            //  networkProtocol("#201", ref dummy);
            //Get all rooms of a specific user
            //  NetworkProtocol("#211;18", ref dummy);
            //Add new or update room
            //NetworkProtocol("#203;5;1;Avelinas Test raum;Hallo Welt;1;http://www.AvelinaLerntArrays.net", ref dummy);
            //Get all workouts of room id 2
            //  NetworkProtocol("#205;Hadd e", ref dummy);
            //Get Levels of workout with id 1
            //  NetworkProtocol("#207;1", ref dummy);
            //Get all excercises of workout 1
            //  NetworkProtocol("#209;1", ref dummy);
            //Delete room
            //NetworkProtocol("#213;114", ref dummy);
        }
Ejemplo n.º 11
0
        private bool HackDetection_File(networkServer.networkClientInterface Client, Protocol prot)
        {
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, "File-Detection received. User: "******"F-Detection: User found in the active connections");
                ArrayList Objects = prot.GetValues();
                if (Objects.Count != 2)
                {
                    //Log error - protocol size not as expected
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.CLIENT, String.Format("F-Detection: Unexpected size of protocol. Expected are 4 but it was {0}. Protocol: {1}", Objects.Count, prot.GetOriginalString()));
                    SendProtocol("401;5", ClientInterface);
                    KickUser(ClientInterface);
                    return(false);
                }

                //The section ID defines which hack detection method triggered
                int SectionID;
                if (!Int32.TryParse(Objects[0].ToString(), out SectionID))
                {
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.CLIENT, String.Format("F-Detection: Unexpected size of protocol. Expected are 4 but it was {0}. Protocol: {1}", Objects.Count, prot.GetOriginalString()));
                    SendProtocol("401;16", ClientInterface);
                    KickUser(ClientInterface);
                }

                string Content = Convert.ToString(Objects[1]);

                CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "F-Detection: Saved protocol values: CaseID: " + SectionID + ", Content: " + Content);

                int Counter = 0;
                while (!SHackFile.Insert(ClientInterface.User.ID, ClientInterface.User.Application.ID, SectionID, Content))
                {
                    Counter++;
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.DATABASE, String.Format("F-Detection: Insertion in database failed! Attempt: {0}, Protocol: {1}", Counter, prot.GetOriginalString()));
                    if (Counter > 3)
                    {
                        SendProtocol("401;15", ClientInterface);
                        KickUser(ClientInterface);
                        return(false);
                    }
                }

                CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.DATABASE, "F-Detection: Database interaction successful");
                SendProtocol("400;14", ClientInterface);

                KickUser(ClientInterface);
                return(true);
            }
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.SERVER, "F-Detection: User not found in active connections!");
            SendProtocol("401;17", ClientInterface);
            KickUser(ClientInterface);
            return(false);
        }
Ejemplo n.º 12
0
        public void SendMessage()
        {
            networkServer.networkClientInterface dummy = new networkServer.networkClientInterface();
            string Test  = "Test\0\0";
            string Test2 = Test.TrimEnd('\0');

            if (Test.EndsWith("\0"))
            {
                Test2 = Test.Substring(0, Test.Length - 1);
            }
            //Core.TcpServer.sendMessage("Test", Client);
        }
        private void Tel_003_testPackage(List <string> lDataList, ref networkServer.networkClientInterface relatedClient)
        {
            Logger.writeInLog(true, "Message #003 (TESTPACKET_LARGE) received from a client!");
            string sDataPackage = "#004;";
            int    iForCounter  = 40;

            for (int i = 0; i < iForCounter; i++)
            {
                sDataPackage = sDataPackage + "Package number: " + (i + 1) + ". This is a large datapackage to test the network tcp/ip receive function. You should get " + iForCounter + " of these packages! Good luck, programmer!\n";
            }
            TcpServer.sendMessage(sDataPackage, relatedClient);
            Logger.writeInLog(true, "Answered #004 with the large datapacket!");
        }
Ejemplo n.º 14
0
        private bool CheckPing(ref networkServer.networkClientInterface Client, Protocol prot)
        {
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Ping: Protocol received. User: "******"Ping: User found in the list.");

                int    AdditionalInfos = prot.HasValues() ? Convert.ToInt32(prot.GetValues()[0]) : -1;
                string AdditionalInfo  = "";
                switch (AdditionalInfos)
                {
                case 1:
                    AdditionalInfo = ";123";
                    break;

                default:
                    break;
                }

                //Reset the Ping timer

                CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Ping: Resetting timer.");
                Client.ResetPingTimer();
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Ping resetted.");

                //zhCCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, "Additional Infos: "+AdditionalInfo);
                if (AdditionalInfo.Length == 0)
                {
                    SendProtocol("300", Client);
                }
                else
                {
                    SendProtocol(String.Format("301;{0}", AdditionalInfo), Client);
                }

                return(true);
            }

            CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.CLIENT, String.Format("Ping: User does not exist in the active connections ({0})", prot.GetUserID()));
            try
            {
                Client.Dispose();
            }
            catch (Exception)
            {
            }
            return(false);
        }
Ejemplo n.º 15
0
        public void SendProtocol(string Protocol, networkServer.networkClientInterface ClientInterface)
        {
            //encrypt protocol
            string EncryptedProt  = AES_Converter.EncryptWithCBC(CCstData.GetInstance(Application).EncryptionKey, CCstData.GetInstance(Application).EncryptionIV, Protocol);
            string LengthAddition = EncryptedProt.Length.ToString();

            while (LengthAddition.Length < 3)
            {
                LengthAddition = "0" + LengthAddition;
            }
            EncryptedProt = LengthAddition + EncryptedProt;
            CCstData.GetInstance(Application).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Protocol encrypted: {0} ({1})", EncryptedProt, Protocol));

            TcpServer.sendMessage(EncryptedProt, ClientInterface);
        }
        private void NetworkProtocol(string message, ref networkServer.networkClientInterface relatedClient)
        {
            string sProtocolShortcut = GetProtocolShortcut(message);
            // Put data in array
            List <string> lDataList = new List <string>();

            lDataList = GetProtocolData(GetProtocolMessage(message));

            switch (sProtocolShortcut)
            {
            case "#001":
                Tel_001_testPackage(ref relatedClient); break;

            case "#003":
                Tel_003_testPackage(lDataList, ref relatedClient); break;

            case "#102":
                Tel_102_loginUser(lDataList, ref relatedClient); break;

            case "#104":
                Tel_104_registerUser(lDataList, ref relatedClient); break;

            case "#201":
                Tel_201_requestRoomOverview(ref relatedClient); break;

            case "#203":
                Tel_203_requestRoomAddorUpdate(lDataList, ref relatedClient); break;

            case "#205":
                Tel_205_requestWorkoutOverview(lDataList, ref relatedClient); break;

            case "#207":
                Tel_207_requestLevelOverview(lDataList, ref relatedClient); break;

            case "#209":
                Tel_209_requestFullExerciseData(lDataList, ref relatedClient); break;

            case "#211":
                Tel_211_requestRoomOverview(lDataList, ref relatedClient); break;

            case "#213":
                Tel_213_requestRoomDelete(lDataList, ref relatedClient); break;

            default:
                Logger.writeInLog(true, "Unknown package protocol/data received: " + message);
                break;
            }
        }
Ejemplo n.º 17
0
 public bool CheckIfUserExists(string SessionID, ref networkServer.networkClientInterface ClientInterface)
 {
     //Checks if that connection exists already. Gives back the amount of matching ClientInterfaces
     for (int i = 0; i < ActiveConnections.Count; i++)
     {
         if (ActiveConnections[i].SessionID == SessionID)
         {
             ActiveConnections[i].networkSocket.Close();
             ActiveConnections[i].networkSocket.Dispose();
             ActiveConnections[i].networkSocket = ClientInterface.networkSocket;
             ClientInterface = ActiveConnections[i];
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 18
0
        private bool HackDetection_VirtualMemory(networkServer.networkClientInterface Client, Protocol prot)
        {
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Virtual-Detection received. User: "******"V-Detection: Unexpected size of protocol. Expected are 4 but it was {0}. Protocol: {1}", Objects.Count, prot.GetOriginalString()));
                    SendProtocol("401;9", ClientInterface);
                    KickUser(ClientInterface);
                    return(false);
                }

                string BaseAddress   = Convert.ToString(Objects[0]);
                string Offset        = Convert.ToString(Objects[1]);
                string DetectedValue = Convert.ToString(Objects[2]);
                string DefaultValue  = Convert.ToString(Objects[3]);

                CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, "V-Detection: Saved protocol successfully. Values: BaseAddress: " + BaseAddress + ", Offset: " + Offset + ", DetectedValue: " + DetectedValue + ", DefaultValue: " + DefaultValue);

                int Counter = 0;
                while (!SHackVirtual.Insert(ClientInterface.User.ID, ClientInterface.User.Application.ID, BaseAddress, Offset, DetectedValue, DefaultValue))
                {
                    Counter++;
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.DATABASE, String.Format("V-Detection: Insertion in database failed! Protocol: {0}", prot.GetOriginalString()));
                    if (Counter > 3)
                    {
                        SendProtocol("401;10", ClientInterface);
                        KickUser(ClientInterface);
                        return(false);
                    }
                }
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "V-Detection: Database interaction successful");

                SendProtocol("400;11", ClientInterface);
                KickUser(ClientInterface);
                return(true);
            }
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.SERVER, "V-Detection: User not found in active connections!");
            SendProtocol("401;12", ClientInterface);
            KickUser(ClientInterface);
            return(false);
        }
 //Signup
 private void Tel_104_registerUser(List <string> lDataList, ref networkServer.networkClientInterface relatedClient)
 {
     try
     {
         //log
         Logger.writeInLog(true, "Message #104 (SIGNUP) received from a client!");
         //register user
         int iSignUpStatusCode = DatabaseEngine.signUpRegisterUser(lDataList[0], lDataList[1], lDataList[2], lDataList[3], lDataList[4], Convert.ToInt16(lDataList[5]));
         //send message to client
         TcpServer.sendMessage("#105" + cProtocolDelimiter + iSignUpStatusCode, relatedClient);
         Logger.writeInLog(true, "Answered #105 with SignUpCode " + iSignUpStatusCode + "!");
     }
     catch (Exception e)
     {
         Logger.writeInLog(true, "ERROR: Something went wrong with telegram (SIGNUP)! Message: " + e.ToString());
         return;
     }
 }
 private void Tel_213_requestRoomDelete(List <string> lDataList, ref networkServer.networkClientInterface relatedClient)
 {
     try
     {
         //log
         Logger.writeInLog(true, "Message #213 (REQ_ROOMDELETE) received from a client!");
         //Get room data
         int    iRoomDeleteStatusCode = DatabaseEngine.deleteRoom(Convert.ToInt32(lDataList[0]));
         string sProtocol             = "#214" + cProtocolDelimiter + iRoomDeleteStatusCode;
         //Send message to client
         TcpServer.sendMessage(sProtocol, relatedClient);
         Logger.writeInLog(true, "Answered #214 with status code: " + iRoomDeleteStatusCode);
     }
     catch (Exception e)
     {
         Logger.writeInLog(true, "ERROR: Something went wrong with telegram (REQ_ROOMDELETE)! Message: " + e.ToString());
         return;
     }
 }
        private void Tel_203_requestRoomAddorUpdate(List <string> lDataList, ref networkServer.networkClientInterface relatedClient)
        {
            int    iRoomStatus      = 0;
            string sAddorUpdateText = "";

            try
            {
                //log
                Logger.writeInLog(true, "Message #203 (REQ_ROOMADDorUPDATE) received from a client!");

                //Check if its a update or a add request
                //IMPORTANT -> Check length of ldatalistcount

                if (Convert.ToInt32(lDataList[0]) != 0)
                {
                    iRoomStatus = DatabaseEngine.updateRoom(Convert.ToInt32(lDataList[0]),
                                                            lDataList[2], lDataList[3],
                                                            Convert.ToInt16(lDataList[4]),
                                                            lDataList[5]);

                    sAddorUpdateText = "UPDATE";
                }
                else
                {
                    //Try to add room + add trainer to room
                    iRoomStatus = DatabaseEngine.addNewRoom(Convert.ToInt32(lDataList[1]),
                                                            lDataList[2], lDataList[3],
                                                            Convert.ToInt16(lDataList[4]),
                                                            lDataList[5]);
                    sAddorUpdateText = "ADD";
                }

                //Send message to client
                TcpServer.sendMessage("#204" + cProtocolDelimiter + iRoomStatus, relatedClient);
                Logger.writeInLog(true, "Answered #205. It was a " + sAddorUpdateText + " order with status code " + iRoomStatus + "!");
            }
            catch (Exception e)
            {
                Logger.writeInLog(true, "ERROR: Something went wrong with telegram (REQ_ROOMADDorUPDATE)! Message: " + e.ToString());
                return;
            }
        }
        private void Tel_205_requestWorkoutOverview(List <string> lDataList, ref networkServer.networkClientInterface relatedClient)
        {
            //Try catch auf llWorkoutData anpassen, sodass im fall eines falschen protokols trozdem daten Runtergesendet werden.
            try {
                //log
                Logger.writeInLog(true, "Message #205 (REQ_WORKOUTOVERVIEWDATA) received from a client!");
                //Get room data
                List <List <string> > llWorkoutData = new List <List <string> >();
                //If the id is not a ID, skip the workout gathering
                try
                {
                    llWorkoutData = DatabaseEngine.getWorkoutOverViewData(Convert.ToInt32(lDataList[0]));
                }
                catch (Exception e) { }
                //Build protocol
                string sProtocol = "#206" + cProtocolDelimiter.ToString();
                sProtocol += llWorkoutData.Count + cProtocolDelimiter.ToString();
                for (int i = 0; i < llWorkoutData.Count; i++)
                {
                    for (int d = 0; d < llWorkoutData[i].Count; d++)
                    {
                        sProtocol += llWorkoutData[i][d] + cDataDelimiter.ToString();
                    }
                    //Remove the last cDataDelimiter
                    sProtocol = sProtocol.Remove(sProtocol.Length - 1);

                    sProtocol += cProtocolDelimiter.ToString();
                }
                //Remove last cProtocolDelimiter
                sProtocol = sProtocol.Remove(sProtocol.Length - 1);

                //Send message to client
                TcpServer.sendMessage(sProtocol, relatedClient);
                Logger.writeInLog(true, "Answered #206 with all workout overview data. " + llWorkoutData.Count + " workout entries sent!");
            }
            catch (Exception e)
            {
                Logger.writeInLog(true, "ERROR: Something went wrong with telegram (REQ_ROOMOVERVIEWDATA)! Message: " + e.ToString());
                return;
            }
        }
Ejemplo n.º 23
0
        bool AddUserToActiveConnections(ref networkServer.networkClientInterface ClientInterface, string ApplicationHash, string ComputerID, string architecture, String language, double version)
        {
            if (!CCstData.InstanceExists(ApplicationHash))
            {
                //Instance does not exist. The player must have manipulated the protocol!
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.SERVER, String.Format("Invalid application hash received in authentification protocol! ComputerID: {0}, ApplicationHash: {1}", ComputerID, ApplicationHash));
                return(false);
            }

            if (CCstData.GetInstance(ApplicationHash).LatestClientVersion != version)
            {
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.ERROR, Support.LoggerType.CLIENT, String.Format("Invalid version! Having {0}, expected {1}. Hardware ID {2}", version, CCstData.GetInstance(ApplicationHash).LatestClientVersion, ComputerID));
                SendProtocol("201;35;Antihack Client version outdated!", ClientInterface);
                return(false);
            }

            ////Check if user is already connected
            //foreach (networkServer.networkClientInterface item in ActiveConnections)
            //{
            //    if(item.User.ID==ComputerID
            //        && item.User.Application.Hash==ApplicationHash)
            //    {
            //        //User is already registered
            //        CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.CLIENT, "Authentification: User is already added to list!");
            //        SendProtocol("201;2;Still logged in. Please try again", ClientInterface);
            //        return false;
            //    }
            //}

            CCstData.GetInstance(ApplicationID).Logger.writeInLog(4, LogCategory.OK, Support.LoggerType.DATABASE, "Authentification: Checking user in the database");
            EPlayer dataClient = SPlayer.Authenticate(ComputerID, ApplicationHash, architecture, language, ClientInterface.IP.ToString());

            CCstData.GetInstance(ApplicationID).Logger.writeInLog(4, LogCategory.OK, Support.LoggerType.DATABASE, "Authentification: User found!");

            if (dataClient == null)
            {
                //If a computer ID exists multiple times in the database, a null object is returned
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.DATABASE, "Authentification: Hardware ID exists multiple times in the database");
                SendProtocol("201;3;Contact Admin", ClientInterface);
                return(false);
            }
            dataClient.Application.Hash = ApplicationHash;

            //Check if user is banned
            if (dataClient.isBanned == true)
            {
                //Do something and dont let him enter
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentification: Banned user tried to authentificate. User: {0}", dataClient.ID));
                //Send protocol to client that user is banned
                SendProtocol("201;4;Too many hacks", ClientInterface);
                return(false);
            }

            //Add EPlayer to ClientInterface and to the list
            ClientInterface.User = dataClient;

            //Generate unique Session ID for network communication
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Authentification: Start creating a unique session ID");
            while (true)
            {
                string SessionID = AdditionalFunctions.GenerateSessionID(CCstData.GetInstance(ApplicationHash).SessionIDLength);
                //Checks if that connection exists already. Gives back the amount of matching ClientInterfaces
                if (ActiveConnections.Where(Client => Client.SessionID == SessionID).ToList().Count == 0)
                {
                    ClientInterface.SessionID = SessionID;
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, String.Format("New user authentificated! HardwareID: {0}, Session ID: {1}", dataClient.ID, SessionID));
                    break;
                }
            }

            //Add the new connection to the list of connected connections
            ClientInterface.SetPingTimer(CCstData.GetInstance(dataClient.Application.ID).PingTimer, KickUser);

            bool IpExistsAlready = false;

            foreach (var Client in ActiveConnections)
            {
                if (Client.IP == ClientInterface.IP)
                {
                    IpExistsAlready = true;
                }
            }


            //Linux takes ages to connect. Therefore contact the client before it sends another request

            if (!IpExistsAlready)
            {
                if (!CCstData.GetInstance(ApplicationID).GameDLL.AllowUser(ClientInterface.IP, ClientInterface.User.ID))
                {
                    //Do something and dont let him enter
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.GAMEDLL, String.Format("Linux exception failed. User: {0}", dataClient.ID));
                    //Send protocol to client that user is banned
                    SendProtocol("201;30;Access verification failed", ClientInterface);
                    return(false);
                }
            }
            else
            {
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentication: IP already exists ({0})", ClientInterface.IP.ToString()));
            }

            ActiveConnections.Add(ClientInterface);

            SendProtocol("200;" + ClientInterface.SessionID, ClientInterface);
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authenticated new user. Computer ID: {0}, Session ID: {1}", ClientInterface.User.ID, ClientInterface.SessionID));

            /*if (!IpExistsAlready)
             * {
             *  //If there is already an IP exception, we dont need another
             *  try
             *  {
             *      ClientInterface.unixSshConnectorAccept.Connect();
             *  }
             *  catch (Exception)
             *  {
             *
             *  }
             *  if (ClientInterface.unixSshConnectorAccept.IsConnected)
             *  {
             *      List<int> Ports = new List<int>();
             *      Ports.Add(50001);
             *      Ports.Add(50002);
             *      Ports.Add(50003);
             *      Ports.Add(50004);
             *      Ports.Add(50005);
             *      Ports.Add(50006);
             *      Ports.Add(50007);
             *      Ports.Add(50008);
             *      Ports.Add(50009);
             *      Ports.Add(50010);
             *      Ports.Add(50011);
             *      Ports.Add(50012);
             *      Ports.Add(50013);
             *      Ports.Add(50014);
             *      Ports.Add(50015);
             *      Ports.Add(50016);
             *      Ports.Add(50017);
             *      Ports.Add(50018);
             *      Ports.Add(50019);
             *      Ports.Add(50020);
             *      string LinuxPorts = "";
             *      foreach (int item in Ports)
             *      {
             *          LinuxPorts += "iptables -I INPUT -p tcp -s " + ClientInterface.IP + " --dport " + item + " -j ACCEPT && ";
             *      }
             *      if(LinuxPorts.Length > 0)
             *      {
             *          LinuxPorts = LinuxPorts.TrimEnd(' ');
             *          LinuxPorts = LinuxPorts.TrimEnd('&');
             *          using (SshCommand Result = ClientInterface.unixSshConnectorAccept.RunCommand(LinuxPorts))
             *          {
             *              if (Result.Error.Length > 0)
             *                  CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.GAMEDLL, "Linux exception failed! Session ID: " + ClientInterface.SessionID + ", Error: " + Result.Error);
             *              else
             *                  CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.GAMEDLL, "Linux exception successful. Session ID: " + ClientInterface.SessionID + ", Result: " + Result.Result);
             *          }
             *      }
             *
             *      ClientInterface.unixSshConnectorAccept.Disconnect();
             *  }
             *  else
             *  {
             *      //Fehlerinfo
             *      CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.CLIENT, "Client could not be connected to the Linux Server. Session ID: " + ClientInterface.SessionID);
             *      return false;
             *  }
             * }
             * else
             * {
             *  string AllIPs = "";
             *  foreach (var item in ActiveConnections)
             *  {
             *      AllIPs += String.Format(" User: {0}, IP: {1} -", item.User.ID, item.IP);
             *  }
             *  CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentication: IP already exists ({0})", AllIPs));
             * }*/

            return(true);
        }
Ejemplo n.º 24
0
        void KickUser(networkServer.networkClientInterface ClientInterface)
        {
            //System.Threading.Thread.Sleep(1000);

            bool IpExistsAlready = false;

            foreach (var item in ActiveConnections)
            {
                if (item.IP == ClientInterface.IP)
                {
                    if (item.SessionID != ClientInterface.SessionID)
                    {
                        IpExistsAlready = true;
                    }
                }
            }

            string t1 = ClientInterface.User.ID;
            string t2 = ClientInterface.SessionID;

            CCstData.GetInstance(ClientInterface.User.Application.ID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("User disconnected. {0} - {1}", t1, t2));
            ActiveConnections.Remove(ClientInterface);

            if (!IpExistsAlready)
            {
                if (!CCstData.GetInstance(ApplicationID).GameDLL.KickUser(ClientInterface.IP, ClientInterface.User.ID))
                {
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.GAMEDLL, String.Format("Linux exception removal failed. IP {0}, User: {1}", ClientInterface.IP, ClientInterface.User.ID));
                }
            }

            /*if (!IpExistsAlready)
             * {
             *  //If there is another user with the same IP, we have to keep it in the IPTables
             *  try
             *  {
             *      ClientInterface.unixSshConnectorAccept.Connect();
             *  }
             *  catch (Exception e)
             *  {
             *  }
             *  if (!ClientInterface.unixSshConnectorAccept.IsConnected)
             *  {
             *      //Log error
             *
             *  }
             *  List<int> Ports = new List<int>();
             *  Ports.Add(50001);
             *  Ports.Add(50002);
             *  Ports.Add(50003);
             *  Ports.Add(50004);
             *  Ports.Add(50005);
             *  Ports.Add(50006);
             *  Ports.Add(50007);
             *  Ports.Add(50008);
             *  Ports.Add(50009);
             *  Ports.Add(50010);
             *  Ports.Add(50011);
             *  Ports.Add(50012);
             *  Ports.Add(50013);
             *  Ports.Add(50014);
             *  Ports.Add(50015);
             *  Ports.Add(50016);
             *  Ports.Add(50017);
             *  Ports.Add(50018);
             *  Ports.Add(50019);
             *  Ports.Add(50020);
             *
             *  string LinuxPorts = "";
             *  foreach (int item in Ports)
             *  {
             *      LinuxPorts += "iptables -D INPUT -p tcp -s " + ClientInterface.IP + " --dport " + item + " -j ACCEPT && ";
             *  }
             *  if (LinuxPorts.Length > 0)
             *  {
             *      LinuxPorts=LinuxPorts.TrimEnd(' ');
             *      LinuxPorts=LinuxPorts.TrimEnd('&');
             *      using (SshCommand Result = ClientInterface.unixSshConnectorAccept.RunCommand(LinuxPorts))
             *      {
             *          if (Result.Error.Length > 0)
             *              CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.GAMEDLL, "Linux exception deny failed! Session ID: " + ClientInterface.SessionID + ", Error: " + Result.Error);
             *          else
             *              CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.GAMEDLL, "Linux exception deny successful. Session ID: " + ClientInterface.SessionID+", Result: "+Result.Result);
             *      }
             *  }
             *  ClientInterface.unixSshConnectorAccept.Disconnect();
             * }*/

            ClientInterface.Dispose();
        }
Ejemplo n.º 25
0
        private bool HackDetection_Heuristic(networkServer.networkClientInterface Client, Protocol prot)
        {
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Heuristic-Detection received. User: "******"H-Detection: User found in the active connections");
                ArrayList Objects = prot.GetValues();
                if (Objects.Count != 2)
                {
                    //Log error - protocol size not as expected
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.CLIENT, String.Format("H-Detection: Unexpected size of protocol. Expected are 4 but it was {0}. Protocol: {1}", Objects.Count, prot.GetOriginalString()));
                    SendProtocol("401;5", ClientInterface);
                    KickUser(ClientInterface);
                    return(false);
                }

                //The section ID defines which hack detection method triggered
                int SectionID;
                if (!Int32.TryParse(Objects[0].ToString(), out SectionID))
                {
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.CLIENT, String.Format("H-Detection: Unexpected size of protocol. Expected are 4 but it was {0}. Protocol: {1}", Objects.Count, prot.GetOriginalString()));
                    SendProtocol("401;13", ClientInterface);
                    KickUser(ClientInterface);
                }

                string ProcessName = null;
                string WindowName  = null;
                string ClassName   = null;
                string MD5Value    = null;

                switch (SectionID)
                {
                case 1:
                    ProcessName = Convert.ToString(Objects[1]);
                    break;

                case 2:
                    MD5Value = Convert.ToString(Objects[1]);
                    break;

                default:
                    break;
                }

                CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, "H-Detection: Saved protocol values: ProcessName: " + ProcessName + ", WindowName: " + WindowName + ", ClassName: " + ClassName + ", MD5Value: " + MD5Value);

                int Counter = 0;
                while (!SHackHeuristic.Insert(ClientInterface.User.ID, ClientInterface.User.Application.ID, ProcessName, WindowName, ClassName, MD5Value))
                {
                    Counter++;
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.DATABASE, String.Format("H-Detection: Insertion in database failed! Attempt: {0}, Protocol: {1}", Counter, prot.GetOriginalString()));
                    if (Counter > 3)
                    {
                        SendProtocol("401;6", ClientInterface);
                        KickUser(ClientInterface);
                        return(false);
                    }
                }

                CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.DATABASE, "H-Detection: Database interaction successful");
                SendProtocol("400;8", ClientInterface);

                KickUser(ClientInterface);
                return(true);
            }
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.SERVER, "H-Detection: User not found in active connections!");
            SendProtocol("401;7", ClientInterface);
            KickUser(ClientInterface);
            return(false);
        }
 //Testpackages
 private void Tel_001_testPackage(ref networkServer.networkClientInterface relatedClient)
 {
     Logger.writeInLog(true, "Message #001 (TESTPACKET_NORMAL) received from a client!");
     TcpServer.sendMessage("#002;Greetings from Controller :)", relatedClient);
     Logger.writeInLog(true, "Answered #002 with the greetings message!");
 }