Beispiel #1
0
        private void validation_button(object sender, RoutedEventArgs e)
        {
            LogsDAO logdb = new LogsDAO();

            //Validation
            if ((Log_Name.Text.Equals(oldName)) || (logdb.checkIfLogs(Log_Name.Text)) || !(String.IsNullOrEmpty(Log_Name.Text)))
            {
                if (!(String.IsNullOrEmpty(Log_Desc.Text)))
                {
                    Boolean checker = logdb.UpdateToTable(Log_Name.Text, Log_Desc.Text, oldName);
                    if (checker)
                    {
                        SY_TagDAO tagdb = new SY_TagDAO();

                        tagdb.UpdateLogName(Log_Name.Text, oldName);

                        Console.WriteLine("WE DID IT!");
                        SY_ViewSpecificCase wnd = new SY_ViewSpecificCase(caseName);
                        wnd.Show();
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("Please fill up the Log Description");
                }
            }
            else
            {
                MessageBox.Show("Please fill up in the Log Name");
            }
        }
        private void Remove_Item(object sender, RoutedEventArgs e)
        {
            var button = sender as DependencyObject;

            while ((button != null) && !(button is DataGridRow))
            {
                button = VisualTreeHelper.GetParent(button);
            }

            if (button is DataGridRow)
            {
                Console.WriteLine("YESH");
                DataGridRow cell    = button as DataGridRow;
                TextBlock   potatoe = LogTable.Columns[0].GetCellContent(cell) as TextBlock;
                LogsDAO     logsdb  = new LogsDAO();
                Boolean     checker = logsdb.deleteLogFromTable(potatoe.Text);

                if (checker)
                {
                    SY_TagDAO tagdb = new SY_TagDAO();
                    tagdb.deleteTagFile(potatoe.Text);

                    Console.WriteLine("It works!");
                    FillDataGrid();
                }
                else
                {
                    Console.WriteLine("It does not work");
                }
            }
        }
        private void validation_button(object sender, RoutedEventArgs e)
        {
            LogsDAO logdb = new LogsDAO();

            //Validation
            if (!(String.IsNullOrEmpty(Log_Name.Text)) && (logdb.checkIfLogs(Log_Name.Text)))
            {
                if (!(String.IsNullOrEmpty(Log_Desc.Text)))
                {
                    if (!(String.IsNullOrEmpty(filePath)))
                    {
                        if (formatBox.SelectedIndex > -1 && formatBox.SelectedIndex == 0)
                        {
                            CaseDAO casedb = new CaseDAO();
                            int     caseId = casedb.getCaseId(c_name);


                            Boolean checker = logdb.addLogToTable(Log_Name.Text, Log_Desc.Text, caseId, filePath, formatBox.Text);



                            if (checker)
                            {
                                int logId = logdb.getLogId(Log_Name.Text);

                                SY_TagDAO tagdb = new SY_TagDAO();
                                tagdb.addTagToTable(Log_Name.Text, logId);

                                Console.WriteLine("WE DID IT!");
                                SY_ViewSpecificCase wnd = new SY_ViewSpecificCase(c_name);
                                wnd.Show();
                                Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please select a file format");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please upload a path to load into");
                    }
                }
                else
                {
                    MessageBox.Show("Please fill up the Log Description");
                }
            }
            else
            {
                MessageBox.Show("Please fill up in the Log Name");
            }
        }
        private void Remove_Row(object sender, RoutedEventArgs e)
        {
            var button = sender as DependencyObject;

            while ((button != null) && !(button is DataGridRow))
            {
                button = VisualTreeHelper.GetParent(button);
            }

            if (button is DataGridRow)
            {
                Console.WriteLine("YOSH");
                DataGridRow cell     = button as DataGridRow;
                TextBlock   potatoe  = CaseTable.Columns[0].GetCellContent(cell) as TextBlock;
                CaseDAO     Case     = new CaseDAO();
                int         caseId   = Case.getCaseId(potatoe.Text);
                LogsDAO     logs     = new LogsDAO();
                SY_TagDAO   tagdb    = new SY_TagDAO();
                String      logName  = logs.getLogName(caseId);
                Boolean     checker3 = tagdb.deleteTagFile(logName);
                Boolean     checker  = logs.deleteThroughIdFromTable(caseId);
                Boolean     checker2 = Case.deleteCaseFromTable(potatoe.Text);



                if (checker && checker2 && checker3)
                {
                    Console.WriteLine("WORKS");
                    FillDataGrid();
                }
            }
            else
            {
                Console.WriteLine("No Works");
            }
        }
        private void validation_button(object sender, RoutedEventArgs e)
        {
            //Validation
            if (!(String.IsNullOrEmpty(Log_Name.Text)))
            {
                if (!(String.IsNullOrEmpty(Log_Desc.Text)))
                {
                    if (!(String.IsNullOrEmpty(filePath)))
                    {
                        if (formatBox.SelectedIndex > -1)
                        {
                            LogsDAO logDb = new LogsDAO();

                            if (logDb.checkIfLogs(Log_Name.Text))
                            {
                                CaseDAO db = new CaseDAO();

                                SY_TagDAO tagdb = new SY_TagDAO();

                                Boolean checker = db.addCaseToTable(c_name, c_desc, investList);

                                Boolean checker2 = false;

                                Boolean checker3 = false;



                                if (checker)
                                {
                                    int caseId = db.getCaseId(c_name);
                                    checker2 = logDb.addLogToTable(Log_Name.Text, Log_Desc.Text, caseId, filePath, formatBox.Text);
                                }



                                if (checker2)
                                {
                                    int logId = logDb.getLogId(Log_Name.Text);
                                    checker3 = tagdb.addTagToTable(Log_Name.Text, logId);

                                    Console.WriteLine("WE DID IT!");


                                    SY_CreatedSuccessCase wnd = new SY_CreatedSuccessCase();
                                    wnd.Show();
                                    Close();
                                }
                                else
                                {
                                    Console.WriteLine("Its not there");
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please select a file format");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please upload a path to load into");
                    }
                }
                else
                {
                    MessageBox.Show("Please fill up the Log Description");
                }
            }
            else
            {
                MessageBox.Show("Please fill up in the Log Name");
            }
        }
        private void ScanForDDoS()
        {
            if (list.Any())
            {
                int packetPerRoll = 3;

                if (list.Count() % 8 == 0)
                {
                    packetPerRoll = 8;
                }
                else if (list.Count() % 7 == 0)
                {
                    packetPerRoll = 7;
                }
                else if (list.Count() % 6 == 0)
                {
                    packetPerRoll = 6;
                }
                else if (list.Count % 5 == 0)
                {
                    packetPerRoll = 5;
                }
                else if (list.Count % 4 == 0)
                {
                    packetPerRoll = 4;
                }


                int packetCounter = 0;

                List <SY_Sort_Windows> perNumber = new List <SY_Sort_Windows>();

                foreach (SY_Sort_Windows item in list)
                {
                    if (packetCounter == packetPerRoll)
                    {
                        packetCounter = 0;

                        List <SY_Sort_Windows> retrivedPacket = new List <SY_Sort_Windows>();
                        //See which ones are receieved packets
                        foreach (SY_Sort_Windows packetItem in perNumber)
                        {
                            if (packetItem.Path.Equals("RECEIVE"))
                            {
                                retrivedPacket.Add(packetItem);
                            }
                        }

                        int    skip        = 0;
                        int    probability = 0;
                        String prevIp      = "";
                        String prevPort    = "";

                        foreach (SY_Sort_Windows receivedPacket in retrivedPacket)
                        {
                            if (skip != 0)
                            {
                                if (!(receivedPacket.SRCIP.Equals(prevIp)) && receivedPacket.DSTPort.Equals(prevPort))
                                {
                                    probability++;
                                }

                                prevIp   = receivedPacket.SRCIP;
                                prevPort = receivedPacket.DSTPort;
                            }
                            else
                            {
                                skip     = 1;
                                prevIp   = receivedPacket.SRCIP;
                                prevPort = receivedPacket.DSTPort;
                            }
                        }

                        if (probability >= (packetPerRoll / 2))
                        {
                            Console.WriteLine("Port Scanned Detected");
                            DateTime StartOf = perNumber[0].dateSpecific;
                            DateTime EndTime = perNumber[perNumber.Count - 1].dateSpecific;

                            SY_Tag newTag = new SY_Tag("Possible DDoS", "Possible Distributed Denial of Service is detected. DDoS is one of the causes of services being down. Severity: High", StartOf, EndTime);

                            SY_TagDAO     tagdb = new SY_TagDAO();
                            String        file  = tagdb.GetTaggingPath(logName);
                            List <SY_Tag> items = new List <SY_Tag>();

                            using (StreamReader r = new StreamReader(file))
                            {
                                string json = r.ReadToEnd();
                                items = JsonConvert.DeserializeObject <List <SY_Tag> >(json);
                            }

                            if (items != null && (!items.Any()))
                            {
                                items.Add(newTag);
                            }
                            else
                            {
                                items = new List <SY_Tag>();
                                items.Add(newTag);
                            }

                            using (StreamWriter newTask = new StreamWriter(file, false))
                            {
                                JsonSerializer serializer = new JsonSerializer();
                                serializer.Serialize(newTask, items);
                            }
                        }
                    }
                    else
                    {
                        perNumber.Add(item);
                        packetCounter++;
                    }
                }
            }
            else if (list2.Any())
            {
            }
        }
        private void ScanForPortScan()
        {
            if (list.Any())
            {
                //Window Firewall Method

                //Check how much packet can checker per loop

                int packetPerRoll = 3;

                if (list.Count() % 8 == 0)
                {
                    packetPerRoll = 8;
                }
                else if (list.Count() % 7 == 0)
                {
                    packetPerRoll = 7;
                }
                else if (list.Count() % 6 == 0)
                {
                    packetPerRoll = 6;
                }
                else if (list.Count % 5 == 0)
                {
                    packetPerRoll = 5;
                }
                else if (list.Count % 4 == 0)
                {
                    packetPerRoll = 4;
                }


                int packetCounter = 0;

                List <SY_Sort_Windows> perNumber = new List <SY_Sort_Windows>();
                foreach (SY_Sort_Windows item in list)
                {
                    if (packetCounter == packetPerRoll)
                    {
                        packetCounter = 0;
                        List <SY_Sort_Windows> retrivedPacket = new List <SY_Sort_Windows>();
                        //See which ones are receieved packets
                        foreach (SY_Sort_Windows packetItem in perNumber)
                        {
                            if (packetItem.Path.Equals("RECEIVE"))
                            {
                                retrivedPacket.Add(packetItem);
                            }
                        }

                        int    skip        = 0;
                        String prevIp      = "";
                        String prevPort    = "";
                        int    probability = 0;

                        foreach (SY_Sort_Windows receivedPacket in retrivedPacket)
                        {
                            if (skip != 0)
                            {
                                if (!(receivedPacket.SRCIP.Equals(prevIp)) && receivedPacket.DSTPort.Equals(prevPort))
                                {
                                    probability++;
                                    prevIp   = receivedPacket.SRCIP;
                                    prevPort = receivedPacket.DSTPort;
                                }
                            }
                            else
                            {
                                skip     = 1;
                                prevIp   = receivedPacket.SRCIP;
                                prevPort = receivedPacket.DSTPort;
                            }
                        }


                        if (probability >= ((packetPerRoll / 2) + 2))
                        {
                            Console.WriteLine("Port Scanned Detected");
                            DateTime StartOf = perNumber[0].dateSpecific;
                            DateTime EndTime = perNumber[perNumber.Count - 1].dateSpecific;

                            SY_Tag newTag = new SY_Tag("Possible Port Scan", "Under Reconnaissance, it seems that someone is researching on how to attack your machine. Severity: Mild ", StartOf, EndTime);

                            SY_TagDAO tagdb = new SY_TagDAO();
                            String    file  = tagdb.GetTaggingPath(logName);
                            Console.WriteLine(file);
                            List <SY_Tag> items = new List <SY_Tag>();

                            using (StreamReader r = new StreamReader(file))
                            {
                                string json = r.ReadToEnd();
                                items = JsonConvert.DeserializeObject <List <SY_Tag> >(json);
                            }

                            items.Add(newTag);

                            if (items != null && (!items.Any()))
                            {
                                items.Add(newTag);
                            }
                            else
                            {
                                items = new List <SY_Tag>();
                                items.Add(newTag);
                            }

                            using (StreamWriter newTask = new StreamWriter(file, false))
                            {
                                JsonSerializer serializer = new JsonSerializer();
                                serializer.Serialize(newTask, items);
                            }
                        }
                    }
                    else
                    {
                        perNumber.Add(item);
                        packetCounter++;
                    }
                }
            }
            else if (list2.Any())
            {
            }
        }
        private void Validation_Click(object sender, RoutedEventArgs e)
        {
            if (!(String.IsNullOrEmpty(TagName.Text)) && !(String.IsNullOrEmpty(TagDescription.Text)))
            {
                if (!(datePicker.SelectedDate == null) && !(datePickerEnd.SelectedDate == null))
                {
                    if (!(StartHour.Text.Count() > 2) && !(String.IsNullOrEmpty(StartHour.Text)) && !(Int32.Parse(StartHour.Text) > 23))
                    {
                        if (!(StartMinute.Text.Count() > 2) && !(String.IsNullOrEmpty(StartMinute.Text)) && !(Int32.Parse(StartMinute.Text) > 59))
                        {
                            if (!(StartSeconds.Text.Count() > 2) && !(String.IsNullOrEmpty(StartSeconds.Text)) && !(Int32.Parse(StartHour.Text) > 59))
                            {
                                if (!(EndHour.Text.Count() > 2) && !(String.IsNullOrEmpty(EndHour.Text)) && !(Int32.Parse(EndHour.Text) > 23))
                                {
                                    if (!(EndMinute.Text.Count() > 2) && !(String.IsNullOrEmpty(EndMinute.Text)) && !(Int32.Parse(EndMinute.Text) > 59))
                                    {
                                        if (!(EndSeconds.Text.Count() > 2) && !(String.IsNullOrEmpty(EndSeconds.Text)) && !(Int32.Parse(EndSeconds.Text) > 59))
                                        {
                                            DateTime?selectedDate = datePicker.SelectedDate;
                                            string   formatted    = selectedDate.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                                            string[] splitted     = formatted.Split(new char[] { '-' });
                                            Console.WriteLine(splitted[0]);

                                            DateTime?endDate    = datePickerEnd.SelectedDate;
                                            string   formatted2 = selectedDate.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                                            string[] splitted2  = formatted.Split(new char[] { '-' });
                                            Console.WriteLine(splitted2[0]);

                                            DateTime startTime = new DateTime(Int32.Parse(splitted[0]), Int32.Parse(splitted[1]), Int32.Parse(splitted[2]), Int32.Parse(StartHour.Text), Int32.Parse(StartMinute.Text), Int32.Parse(StartSeconds.Text));
                                            DateTime endTime   = new DateTime(Int32.Parse(splitted2[0]), Int32.Parse(splitted2[1]), Int32.Parse(splitted2[2]), Int32.Parse(EndHour.Text), Int32.Parse(EndMinute.Text), Int32.Parse(EndSeconds.Text));

                                            SY_TagDAO     tagdb    = new SY_TagDAO();
                                            String        filepath = tagdb.GetTaggingPath(logName);
                                            List <SY_Tag> list;
                                            using (StreamReader r = new StreamReader(filepath)) {
                                                String json = r.ReadToEnd();
                                                list = JsonConvert.DeserializeObject <List <SY_Tag> >(json);
                                            }
                                            if (list != null && (!list.Any()))
                                            {
                                                list.Add(new SY_Tag(TagName.Text, TagDescription.Text, startTime, endTime));
                                            }
                                            else
                                            {
                                                list = new List <SY_Tag>();
                                                list.Add(new SY_Tag(TagName.Text, TagDescription.Text, startTime, endTime));
                                            }


                                            using (StreamWriter newTask = new StreamWriter(filepath, false))
                                            {
                                                JsonSerializer serializer = new JsonSerializer();
                                                serializer.Serialize(newTask, list);
                                            }


                                            SY_ViewSpecificTeam wnd = new SY_ViewSpecificTeam(logName, CName);
                                            wnd.Show();
                                            Close();
                                        }
                                        else
                                        {
                                            MessageBox.Show("Incorrect Input");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Incorrect Input");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Incorrect Input");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Incorrect Input");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Incorrect Input");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Incorrect Input");
                    }
                }
                else
                {
                    MessageBox.Show("Please Fill in the Blanks");
                }
            }
            else
            {
                MessageBox.Show("Please Fill in the Blanks");
            }
        }