private void FlooderStatusDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { // We are starting or stopping a flooder var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { bool IsStarting = false; int col = e.ColumnIndex; int row = e.RowIndex; _SelectedRow = e.RowIndex; // Verify that flooder data has been entered if (_FlooderStatusDataGridView.Rows[row].Cells["FlooderIpAddress"].Value == null) { MessageBox.Show("Flooder IP address required", "Flooder IP Address"); _FlooderStatusDataGridView.Rows[row].Cells["FlooderIpAddress"].Selected = true; } else if (_FlooderStatusDataGridView.Rows[row].Cells["FlooderPort"].Value == null) { MessageBox.Show("Flooder port number required", "Flooder Port Number"); _FlooderStatusDataGridView.Rows[row].Cells["FlooderPort"].Selected = true; } else if (_FlooderStatusDataGridView.Rows[row].Cells["FlooderDestination"].Value == null) { MessageBox.Show("Flooder destination IP address required", "Flooder Destination IP Address"); _FlooderStatusDataGridView.Rows[row].Cells["FlooderDestination"].Selected = true; } else { // Get the process ID int flooderPid = Convert.ToInt32(_FlooderStatusDataGridView.Rows[row].Cells["PID"].Value.ToString()); // Get the flooder connection information string flooderIpAddress = _FlooderStatusDataGridView.Rows[row].Cells["FlooderIpAddress"].Value.ToString(); int flooderConnectionPortNumber = Convert.ToInt32(_FlooderStatusDataGridView.Rows[row].Cells["FlooderPort"].Value.ToString()); string flooderDestinationIpAddress = _FlooderStatusDataGridView.Rows[row].Cells["FlooderDestination"].Value.ToString(); // Hardcode flooder source and destination ports int flooderSourcePortNumber = 403; int flooderDestinationPortNumber = 80; // Convert the IP Address string into a byte array string[] sourceIpAddress = flooderIpAddress.Split(new char[1] { '.' }); byte[] remoteHostIpAddrByteArr = new byte[4]; // Parse the flooder source IP address if (flooderIpAddress != "") { if (sourceIpAddress.Length != 4) { MessageBox.Show("Error parsing Flooder IP Address: " + flooderIpAddress + "Please check the Flooder IP Address.", "Parse Remote Host IP Address", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { for (int i = 0; i < 4; i++) { remoteHostIpAddrByteArr[i] = byte.Parse(sourceIpAddress[i]); } } } // Assign the flooder IP address IPAddress connectionIp = new IPAddress(remoteHostIpAddrByteArr); Flooder flooder = new COWE.Client.Flooder(flooderPid, connectionIp, flooderConnectionPortNumber, flooderIpAddress, flooderSourcePortNumber, flooderDestinationIpAddress, flooderDestinationPortNumber); // Add the flooder to the _Flooders collection if it isn't already a member bool IsMember = false; foreach (Flooder f in _Flooders) { if (flooder.Pid == f.Pid) { IsMember = true; } } if (!IsMember) { _Flooders.Add(flooder); } var cellButton = (DataGridViewButtonCell)senderGrid[col, row]; if (cellButton.Value.ToString() == "Start") { DisableConfigurationControls(); DisableFlooderControls(); FileQueue.Clear(); AnalysisConfiguration.FoundCoresidentVm = false; if(_ProcessedFileNotifierThread == null) { _ProcessedFileNotifier = new ProcessedFileNotifier(_ProcessedFilesPath); } _ProcessedFileNotifierThread = new Thread(new ThreadStart(_ProcessedFileNotifier.Start)); _ProcessedFileNotifierThread.Start(); if(_CreateIntervalsAndAnalysisController == null) { _CreateIntervalsAndAnalysisController = new CreateIntervalsAndAnalysisController(); } _CreateIntervalsAndAnalysisControllerThread = new Thread(new ThreadStart(_CreateIntervalsAndAnalysisController.ProcessFiles)); _CreateIntervalsAndAnalysisControllerThread.Start(); if (DatabaseResetCheckBox.Checked == true) { ResetDatabaseAndDeleteCaptureFiles(); } IsStarting = true; // Check to see if the flooder is running Ping verifyPing = new Ping(); PingReply reply = verifyPing.Send(flooderIpAddress, 1000); if (reply.Status.ToString() != "TimedOut") { // Get the timer interval (start/stop interval for flooder) _FlooderTimerInterval = Convert.ToInt32(FlooderIntervalTextBox.Text); AnalysisConfiguration.TimerInterval = _FlooderTimerInterval; bool success = false; // Open the socket connection to the flooder if (OpenFlooderConnection(IsStarting, flooder, _FlooderTimerInterval)) { cellButton.UseColumnTextForButtonValue = false; cellButton.Value = "Stop"; cellButton.Style.BackColor = System.Drawing.Color.Red; // Update the status column for this row (i.e., this flooder instance) _FlooderStatusDataGridView.Rows[row].Cells["FlooderStatus"].Value = "Running"; _FlooderStatusDataGridView.Rows[row].Cells["FlooderStatus"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; _FlooderStatusDataGridView["FlooderStatus", row].Style.BackColor = NonResident; success = true; IsFlooding = true; IsMarked = true; } else { MessageBox.Show("Unable to start flooder", "Start Flooder"); } if (success) { // Start the packet capture // Get our local IP address _HostIpAddress = _SelectedNetworkInterface.IpAddress; // Note: source host is web server (target), local host is client if (StartPacketCapture(TargetIpAddressTextBox.Text.Trim(), _HostIpAddress, _FlooderTimerInterval)) { // Packet capture started successfully DisplayProgressMessage("Capturing marked packet data..."); InitializeFileCount(); DisplayCapturedFileCount(); Application.DoEvents(); //// Start the timer (ms increments) //_FlooderIntervalTimer = new System.Timers.Timer(_FlooderTimerInterval * 1000); //_FlooderIntervalTimer.Elapsed += new ElapsedEventHandler(OnFlooderTimerElapsedEvent); //_FlooderIntervalTimer.Start(); //StopWatchStart(); TimerStart(_FlooderTimerInterval); } } } else { MessageBox.Show("Unable to ping flooder!\r\n\r\nCheck to be sure flooder is up and icmp is not blocked.", "Verify Flooder is Reachable", MessageBoxButtons.OK, MessageBoxIcon.Hand); } EnableConfigurationControls(); EnableFlooderControls(); } else { // First stop the capture process if it is running if (_CaptureProcessId > 0) { try { Process process = new Process(); process = Process.GetProcessById(_CaptureProcessId); process.Kill(); } catch { // Ignore any errors - means process has already exited } } // Delete any partial capture files try { // Allow time for process cleanup Thread.Sleep(500); if (File.Exists(_CaptureFolderPath + "\\" + _CurrentCaptureFileName)) { File.Delete(_CaptureFolderPath + "\\" + _CurrentCaptureFileName); } } catch (Exception ex) { MessageBox.Show("Error deleting partial capture file [" + _CaptureFolderPath + "\\" + _CurrentCaptureFileName + "]: " + ex.Message, "Stop Flooder - Capture File Cleanup"); } // Stop flooder IsStarting = false; cellButton.UseColumnTextForButtonValue = false; cellButton.Value = "Start"; cellButton.FlatStyle = FlatStyle.Standard; cellButton.Style.BackColor = System.Drawing.SystemColors.Control; _FlooderStatusDataGridView.Rows[row].Cells["FlooderStatus"].Value = "Not Connected"; _FlooderStatusDataGridView.Rows[row].Cells["FlooderStatus"].Style.BackColor = NotConnected; _FlooderStatusDataGridView.Rows[row].Cells["FlooderStatus"].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; // Note - original cell color name was "0" or "Empty" _FlooderStatusDataGridView.Rows[row].Cells["FlooderStatus"].Style.BackColor = NotConnected; // Open the socket connection to the flooder if (OpenFlooderConnection(IsStarting, flooder, 0)) { IsFlooding = false; // Stop the packet capture and reset the capture message HideProgressMessage(); _FlooderIntervalTimer.Stop(); StopWatchStop(); } else { MessageBox.Show("Unable to stop flooder", "Stop Flooder"); } // Move the last packet capture file MovePacketCaptureFile(_CurrentCaptureFileName); EnableConfigurationControls(); EnableFlooderControls(); // Finish processing anything in the queue while (IsStarting && FileQueue.Count != 0) { Thread.Sleep(3000); } //_ProcessedFileNotifierThread.Abort(); _ProcessedFileNotifier.Stop(); _ProcessedFileNotifierThread.Join(); _CreateIntervalsAndAnalysisController.Stop(); _CreateIntervalsAndAnalysisControllerThread.Join(); //_CreatIntervalsAndAnalysisControllerThread.Abort(); } } } }
int _UnmarkedFileCount = 0; // Number of unmarked capture files #endregion Fields #region Constructors public Client() { InitializeComponent(); LoadFileSystemConfiguration(); InitializeForm(); InitializeFlooderStatusDataGridViewControl(); InitializeNetworkInterfacesComboBox(); GetParseCaptureFilesServiceStatus(); timer.Tick += new EventHandler(timer_Tick); timer.Interval = new TimeSpan(0, 0, 0, 1); this.bgWorker = new BackgroundWorker(); this.bgWorker.WorkerReportsProgress = true; this.bgWorker.WorkerSupportsCancellation = true; InitializeBackgroundWorkerTheads(); // Only need this thread when a flooder is running so move it to the start flooder method InitializeProgressSpinner(); InitializeProgressLabel(); this.ClockButton.Visible = false; this.ProcessCaptureDataButton.Visible = true; this.StartTimerButton.Visible = true; UpdateParseFilesServiceStatus(); DatabaseResetCheckBox.Checked = true; _AnalysisControl = new AnalysisControl(); _ProcessedFileNotifier = new ProcessedFileNotifier(_ProcessedFilesPath); _CreateIntervalsAndAnalysisController = new CreateIntervalsAndAnalysisController(); }