PHP: Scanner de ports

Reading time: 2 – 3 minutes

Donant voltes per la Linux Security vaig trobar la referència d’un
document molt curiós, es tracta d’implementar un scanner de ports en
PHP, de fet el document comenta com d’un scanner de ports fet en C s’extreu el
codi en PHP.

L’article sencer esta a la web de PHPWizard i és titula: “Securing Servers
With PHP” però no tinc el link a mà.

Per si algú encara no ha vist q ens pot permetre fer això, doncs
penseu q podriem fer un scaner de ports a un site
des de la IP de qualsevol servidor PHP sense mostrar la nostra IP, seria com
tenir un scaner de ports online q no revela la nostre identitat 😉

Doncs per si algú necessita el codi urgent aquí va:



// port.php,v 1.3 2001/08/21 19:54:19 barce Exp
//
// A basic port scanner written in PHP.
//

/****************************************
* *
* $min is the first port scanned *
* $max is the last port scanned *
* *
****************************************/

$timeout = 1; // Use a timeout with a short duration
if ($pressed)
{
set_time_limit(0);
echo “Scanning $target” . “…
n”; flush();
for ($i = $min; $i <= $max; $i++)
{
/*********************************************************
* *
* Open a Socket Connection with fsockopen *
* *
*********************************************************/
$handle = fsockopen($target, $i, $errno, $errstr, $timeout);

/*********************************************************
* *
* Test connection to see if port is open *
* *
*********************************************************/
if (!$handle)
{
echo “No connection at port $i
n”; flush();
} else {
echo “Open port at $i
n”; flush();
fclose($handle);
}
}
} else {

/*********************************************************
* *
* A form to ask user for a host to target *
* *
*********************************************************/
echo “

n”;
echo “Host to portscan: “;
echo “
n”;
echo “Starting port number: “;
echo “
n”;
echo “Ending port number: “;
echo “
n”;
echo “n”;
echo “n”;
echo “

n”;
}
?>