Skip to content

Instantly share code, notes, and snippets.

@kaldas
Created September 27, 2010 03:08
Show Gist options
  • Select an option

  • Save kaldas/598545 to your computer and use it in GitHub Desktop.

Select an option

Save kaldas/598545 to your computer and use it in GitHub Desktop.
<?php /* launch it from apache, but it's cooler if from CLI hahahhh */
error_reporting(0);
set_time_limit(0);
ini_set("default_socket_timeout",5);
$host = $_POST['host'];
$port = $_POST['port'];
$path = $_POST['path'];
$dirs = $_POST['dirs'];
$cl="<br>"; //substitua por \n se preferir
echo"+-----------------------------------------------------------------+".$cl;
echo"| (Yet another) HTTP RESPONSE SCANNER ".$cl;
echo"| by rcaldasmd @ http://duarte.eti.br ".$cl;
echo"+-----------------------------------------------------------------+".$cl;
echo'<br><form name="form" method="post" action="">
Host: <input type="text" name="host" /> Port: <input name="port"
type="text" value="80" size="6" /> Path: <input name="path" type="text"
value="/" /><br><br>Dirs: (one per line)<br><br> <textarea name="dirs"
cols="45" rows="5">admin/</textarea><br><br><input type="submit"
name="button" id="button" value="Submit" /></form>
';
$dirlist = explode("\n",$dirs); //um dir por linha
if(empty($host))
exit;
//nosso packet comum
$packet.="Host: ".$host."\r\n";
$packet.="Connection: Close\r\n";
$packet.="Accept-Encoding: text/html\r\n\r\n";
echo $cl."Starting response scan at ".$host.$cl;
$ip=gethostbyname($host); //resolvemos o dominio
foreach($dirlist as $currdir)
{
$sock = fsockopen($ip, $port);
while(!$sock)
{
echo $cl."Failed to connect to host. Trying again. =(".$cl;
$sock = fsockopen($ip, $port);
}
$spacket ="GET ".$path."/".$currdir." HTTP/1.1\r\n".$packet;
fputs($sock,$spacket);
while (!feof($sock))
{
if(stristr($html,"\n")) //termina o loop se um newline for encontrado
break;
$html .= fgets($sock, 64);
}
$output = explode("\n",$html);
/* Nós não queremos respostas do tipo..
400 (packet nao foi entendido pelo servidor)
404 (objeto requisitado não existe)
*/
if(stristr($html,"400")) //retorna erro
{
fclose($sock);
die($cl."DIR: ".$currdir." ERROR: MALFORMED PACKET");
}
if (!stristr($html,"404")) //suprime erro
{
echo $cl."DIR: ".$currdir." RESULT: ".$output[0];
}
unset($html);
fclose($sock); //desnecessario mas boa pratica
}
/* eu realmente nao tinha nada melhor pra fazer */
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment