public static bool isRecordLoginFailure(OneRecord _record) { if (_record.request_file_name == "login.php") { if (_record.response != 200) { return(true); } } return(false); }
public static bool IsRecordCanBeCreated(string _logString) { string logEntryPattern = "^([\\d.]+) (\\S+) (\\S+) \\[([\\w:/]+\\s[+\\-]\\d{4})\\] \"(.+?)\" (\\d{3}) (\\d+)"; Dictionary <int, string> HTTPResultTypes = OneRecord.GetHTTPResultValidTypes(); Match theMatch = Regex.Match(_logString, logEntryPattern); if (theMatch.Success && HTTPResultTypes.ContainsKey(Int32.Parse(theMatch.Groups[6].Value))) { return(true); } else { return(false); } }
//public void delegate AppentTextDelegate(string text); //class floid //{ // public static void FlMethod(AppentTextDelegate AppentText) // { // /* прочий код */ // AppentText("{0} " + array[i, j]); // /* прочий код */ // } //} public void writeFileToWindow(System.Windows.Forms.DataGridView dgv) { try { dgv.Rows.Clear(); using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default)) { int lineNumbers = 0; int outputLineNumbers = 0; int wrongRecords = 0; string line; wrongRecordsList = new List <string>(); while ((line = sr.ReadLine()) != null) { lineNumbers++; if (OneRecord.IsRecordCanBeCreated(line)) { outputLineNumbers++; OneRecord record = new OneRecord(line); //richTextBox1.Text += String.Format("[{0}] {1}\n", lineNumbers, record.logString); var index = dgv.Rows.Add(); //dgv.Rows[index].Cells["NumberOfLine"].Value = index+1; dgv.Rows[index].Cells["IP"].Value = record.ip; dgv.Rows[index].Cells["DateTime"].Value = record.date; dgv.Rows[index].Cells["Request"].Value = record.request; dgv.Rows[index].Cells["AnswerNumber"].Value = record.response; dgv.Rows[index].Cells["BytesSent"].Value = record.bytesSent; //richTextBox1.AppendText("aaa"); } else { wrongRecords++; wrongRecordsList.Add(line); } } fileInfo["Колличество строк"] = lineNumbers; fileInfo["Выведено строк"] = outputLineNumbers; fileInfo["Некорректные запросы"] = wrongRecords; } } catch (FileNotFoundException ioEx) { Console.WriteLine(ioEx.Message); } }
private bool isLastRecordAdded() { string record = BackgroundWatcher.ReadLastLine(logfile.fileName); if (record != "" && record != filteredRecords.FilteredRecordsList.Last().logString) { if (OneRecord.IsRecordCanBeCreated(record)) { OneRecord _record = new OneRecord(record); filteredRecords.deleteFirstRecord(); filteredRecords.AddRecord(_record); return(true); } return(false); } else { return(false); } }
public void writeFileToConsole() { try { using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default)) { string line; while ((line = sr.ReadLine()) != null) { if (OneRecord.IsRecordCanBeCreated(line)) { OneRecord record = new OneRecord(line); record.WriteToConsole(); Console.WriteLine(""); } } } } catch (FileNotFoundException ioEx) { Console.WriteLine(ioEx.Message); } }
public DangerousHTTPRequests SecureFilterAndScanAllFile() { DangerousHTTPRequests dangerousRequests = new DangerousHTTPRequests(); FilteredRecords filtered = new FilteredRecords(); try { using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default)) { string line; //long bytesSeek = 0; while ((line = sr.ReadLine()) != null) { if (OneRecord.IsRecordCanBeCreated(line)) { OneRecord record = new OneRecord(line); //filteredList.AddRecord(record); if (DangerousHTTPRequests.isRecordLoginFailure(record)) { filtered.AddRecord(record); } } } } } catch (FileNotFoundException ioEx) { Console.WriteLine(ioEx.Message); } dangerousRequests = filtered.AttackDetector(); return(dangerousRequests); }
private FilteredRecords Filter(DateTime min, DateTime max, string _name, int _resultType, string _ip, int _lastRecords, bool isMinDateFilterActive, bool IsMaxDateFilterActive, bool isNameFilterActive, bool isResultFilterActive, bool isIpFilterActive, bool isLastRecordsFilterActive) { FilteredRecords filteredList = new FilteredRecords(); wrongRecordsList = new List <string>(); try { int lineNumbersInFile = 0; using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default)) { string line; while ((line = sr.ReadLine()) != null) { ++lineNumbersInFile; } } fileInfo["Колличество строк"] = lineNumbersInFile; if (!isLastRecordsFilterActive) { using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default)) { string line; int lineNumbers = 0; int wrongRecords = 0; while ((line = sr.ReadLine()) != null) { if (OneRecord.IsRecordCanBeCreated(line)) { OneRecord record = new OneRecord(line); bool allFiltersOK = true; if (isMinDateFilterActive) { if (!record.isRecordMinDateValid(min)) { allFiltersOK = false; } } if (IsMaxDateFilterActive) { if (!record.isRecordMaxDateValid(max)) { allFiltersOK = false; } } if (isNameFilterActive) { if (!record.isRecordFileNameValid(_name.Trim())) { allFiltersOK = false; } } if (isResultFilterActive) { if (!record.isRecordsResultTypeValid(_resultType)) { allFiltersOK = false; } } if (isIpFilterActive) { if (!record.isRecordIPValid(_ip.Trim())) { allFiltersOK = false; } } if (allFiltersOK) { filteredList.AddRecord(record); lineNumbers++; } } else { wrongRecords++; wrongRecordsList.Add(line); } } fileInfo["Выведено строк"] = lineNumbers; fileInfo["Некорректные запросы"] = wrongRecords; } } else { //int lineNumbersInFile = 0; //using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default)) //{ // string line; // while ((line = sr.ReadLine()) != null) // { // ++lineNumbersInFile; // } //} if (_lastRecords > lineNumbersInFile) { _lastRecords = lineNumbersInFile; } using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default)) { string line; int lineNumber = 0; int outputLineNumbers = 0; int wrongRecords = 0; while ((line = sr.ReadLine()) != null) { ++lineNumber; if (lineNumber >= lineNumbersInFile - _lastRecords) { if (OneRecord.IsRecordCanBeCreated(line)) { OneRecord record = new OneRecord(line); bool allFiltersOK = true; if (isMinDateFilterActive) { if (!record.isRecordMinDateValid(min)) { allFiltersOK = false; } } if (IsMaxDateFilterActive) { if (!record.isRecordMaxDateValid(max)) { allFiltersOK = false; } } if (isNameFilterActive) { if (!record.isRecordFileNameValid(_name)) { allFiltersOK = false; } } if (isResultFilterActive) { if (!record.isRecordsResultTypeValid(_resultType)) { allFiltersOK = false; } } if (isIpFilterActive) { if (!record.isRecordIPValid(_ip)) { allFiltersOK = false; } } if (allFiltersOK) { filteredList.AddRecord(record); outputLineNumbers++; } } else { wrongRecords++; wrongRecordsList.Add(line); } } } fileInfo["Выведено строк"] = outputLineNumbers; fileInfo["Некорректные запросы"] = wrongRecords; } } } catch (FileNotFoundException ioEx) { Console.WriteLine(ioEx.Message); } return(filteredList); }
public void AddRecord(OneRecord _record) { this.FilteredRecordsList.Add(_record); }