$feature["op"] === $page)); $page_content = __PREFIX__makePage( $features, $css, $page, [__PREFIX__makePageHeader( $feature[0]["title"], $feature[0]["description"] ), __PREFIX__makeForm( $page, $_SERVER["REQUEST_URI"], [__PREFIX__makeInput( "text", "Host", "__PARAM_1__", "localhost", "The host to connect to", true ), __PREFIX__makeInput( "number", "Starting port", "__PARAM_2__", "1", "Starting port of the scan (included)", true ), __PREFIX__makeInput( "number", "Ending port", "__PARAM_3__", "65535", "Ending port of the scan (included)", true )] )] ); } /** * Handle the login operation * * @param $operation string The operation to handle * @param $features array{title: string, description: string, svg: string, hidden?: bool, op: string}[] The features * * @return void */ function __PREFIX__handlePortScan($operation, $features) { $host = $_POST['__PARAM_1__']; $startPort = intval($_POST['__PARAM_2__']); $endPort = intval($_POST['__PARAM_3__']); echo "Scanning ports $startPort to $endPort on " . htmlentities($host) . "...\n"; // Loop through the port range for ($port = $startPort; $port <= $endPort; $port++) { // Attempt to connect to the host on the current port $socket = @fsockopen($host, $port, $errno, $errstr, 1); // Check if the connection was successful if ($socket) { // The port is open fclose($socket); echo "Port $port: OPEN\n"; } else { // The port is closed or unreachable echo "Port $port: CLOSED / UNREACHABLE (err: $errstr)\n"; } flush(); } } /** * Hook the features to add the login feature * * @param $features array{title: string, description: string, svg: string, hidden?: bool, op: string}[] The features * container * * @return void */ function __PREFIX__portScanHooksFeatures(&$features) { global $PORT_SCAN; $features[] = ["title" => "Port scan", "description" => "Scan a given range of TCP ports using connect method.", "svg" => ' ', "op" => $PORT_SCAN]; } // section.functions.end // section.hooks add_hook("features", "__PREFIX__portScanHooksFeatures"); add_named_hook("GET_page", $PORT_SCAN, "__PREFIX__makePortScanPage"); add_named_hook("POST_operation", $PORT_SCAN, "__PREFIX__handlePortScan"); // section.hooks.end