PHP Site Scanner

Posted by Tully on Mon 27 July 2009

This is a script I wrote to go through a list of URLS and return the Server Response code. This can be used to look for site vulnerabilities such as hidden directories.

This example only has a few pages in the array. If you have a big list of common directories, the best way would be to have the script load those directories line by line from the file.

Also, if you were looking for a particular response code you could either pipe the output to grep, or add the response code after the "HTTP/1.1" in the strstr function.

PHP Site Scanner

<?php
$host = "www.google.com";
$port = 80;
$pages = array("/cgi-bin","/admin","/test","/beta");

foreach ($pages as $page) {
    $fp = fsockopen($host,$port,$errno,$errstr,30);

    if (!$fp) {
        echo "$errstr ($errno)";
    } else {
        $out = "GET $page HTTP/1.1\r\n";
        $out.= "Host: $host\r\n";
        $out .= "Connection: Close\r\n\r\n";
        fwrite($fp,$out);
        while (!feof($fp)) {
            $data = fread($fp, 20);
            if (strstr($data,'HTTP/1.1')) {
                echo " Site: $host \n Page: $page \n Code: $data \n\n";
            } 
        }

        unset($data);
        unset($out);
        fclose($fp);
    }
}