<?php 


 
/***********************************************************/ 
/* last update: 12.17.2002                                 */ 
/* --------------------------------------------------------*/ 
/*                    Inprotect                            */ 
/* --------------------------------------------------------*/ 
/* Copyright (C) 2002 Inprotect.com                        */ 
/*                                                         */ 
/* This program is free software; you can redistribute it  */ 
/* and/or modify it under the terms of version 2 of the    */ 
/* GNU General Public License as published by the Free     */ 
/* Software Foundation.                                    */ 
/* This program is distributed in the hope that it will be */ 
/* useful, but WITHOUT ANY WARRANTY; without even the      */ 
/* implied warranty of MERCHANTABILITY or FITNESS FOR A    */  
/* PARTICULAR PURPOSE. See the GNU General Public License  */  
/* for more details.                                       */ 
/*                                                         */ 
/* You should have received a copy of the GNU General      */  
/* Public License along with this program; if not, write   */ 
/* to the Free Software Foundation, Inc., 59 Temple Place, */  
/* Suite 330, Boston, MA 02111-1307 USA                    */ 
/*                                                         */ 
/* Contact Information:                                    */ 
/* Alex Zimin (alex@inprotect.com)                         */ 
/* http://www.inprotect.com                                */ 
/***********************************************************/ 
/* See the README.txt and/or help files for more           */  
/* information on how to use & config.                     */
/* See the LICENSE.txt file for more information on the    */  
/* License this software is distributed under.             */ 
/*                                                         */ 
/* This program is intended for use in an authorized       */  
/* manner only, and the author can not be held liable for  */  
/* anything done with this program, code, or items         */ 
/* discovered with this program's use.                     */ 
/***********************************************************/ 

include ('header.php'); 


if ($fp<>"") { 
		$query="update nessus_results set falsepositive='Y' where result_id=$fp"; 
		$result=$dbconn->execute($query); 
 
	} 
 
if ($nfp<>"") { 
                $query="update nessus_results set falsepositive='N' where result_id=$nfp"; 
                $result=$dbconn->execute($query); 
 
        } 
	
echo"<form action=\"search.php\" method=\"GET\" enctype=\"text/plain\">";
echo"<table summary=\"Search criteria\" WIDTH=\"100%\" BORDER=2 BGCOLOR=\"#336699\"><tr>";
echo"<td VALIGN=TOP><font color=\"white\"><b>Severity:</b></font> <td> <select NAME=\"severity\"><option VALUE=\"\">{severity}";
echo"	<option VALUE=\"1\" "; if($severity=="1"){echo"selected";}; echo"> Serious";
echo"	 <option VALUE=\"2\" "; if($severity=="2"){echo"selected";}; echo"> High";
echo"	 <option VALUE=\"3\" "; if($severity=="3"){echo"selected";}; echo"> Medium";
echo"	 <option VALUE=\"4\" "; if($severity=="4"){echo"selected";}; echo"> Medium-Low";
echo"	 <option VALUE=\"5\" "; if($severity=="5"){echo"selected";}; echo"> Low-Medium";
echo"	 <option VALUE=\"6\" "; if($severity=="6"){echo"selected";}; echo"> Low";
echo"	<option VALUE=\"7\" "; if($severity=="7"){echo"selected";}; echo"> Info"; 
echo"	</select></tr>";
echo "<tr><td VALIGN=TOP><font color=\"white\"><b>Host Name/IP Address:</b></font></td>";

echo"	<td><select name=\"hostname\"><option value=\"\" label=\"default\">{host}</option>";
$result=$dbconn->Execute("select distinct host from nessus_results where username='$username' order by host ASC");
while (list($hostRes)=$result->fields) { 
	echo"<option value=\"$hostRes\" label=\"$hostRes\""; if($hostname==$hostRes){echo"selected";}; echo">$hostRes</option>";
	$result->MoveNext(); 
}
echo "</select></td></tr>";
echo "<tr><td VALIGN=TOP><font color=\"white\"><b>Service(s):$service</b></font></td>";
echo"	<td><select name=\"service\"><option value=\"\" label=\"default\"> {service}</option>"; 
$result=$dbconn->Execute("select distinct service from nessus_results where username='$username' order by service ASC");
while (list($serviceRes)=$result->fields) { 
	echo"<option value=\"$serviceRes\" label=\"$serviceRes\""; if($service==$serviceRes){echo"selected";}; echo">$serviceRes</option>";
	$result->MoveNext(); 
}
echo"</select></td></tr>	";
echo "<tr><td VALIGN=TOP><font color=\"white\"><b>Nessus Plugin: $plugin</b></font></td>";
echo"   <td><select name=\"plugin\"><option value=\"\" label=\"default\"> {plugin}</option>";
$result=$dbconn->Execute("select distinct scriptid from nessus_results where username='$username' and scriptid <> '' order by scriptid ASC");
while (list($pluginRes)=$result->fields) {
        echo"<option value=\"$pluginRes\" label=\"$pluginRes\""; if($plugin==$pluginRes){echo"selected";}; echo">$pluginRes</option>";
        $result->MoveNext();
}
echo"</select></td></tr>        ";
echo "<tr><td VALIGN=TOP><font color=\"white\"><b>Description (Enter a string to search for in the description):</b></font></td>";
echo"	<td><input type=\"text\" name=\"description\" size=\"56\" maxlength=\"128\" value=\"$description\" ></td></tr>";
echo"<tr><td VALIGN=TOP><font color=\"white\"><b>Show False Positives:</b></font></td>";
echo"<td><input type=\"checkbox\" name=\"showFP\" value=\"true\""; if($showFP){echo" checked";};echo"></td></tr>";
echo"<tr><td VALIGN=TOP><font color=\"white\"><b>Show Information Level Results:</b></font></td>";
echo"<td><input type=\"checkbox\" name=\"showInfo\" value=\"true\""; if($showInfo){echo" checked";};echo"></td></tr>";
echo"<tr><td><input name=\"submit\" value=\"Submit\" type=\"submit\"></tr></table></form>";

echo "<br/><br/><table summary=\"Vulnerability List\" border=\"1\">";
echo "<tr><td colspan=4>Vulnerabilities found:"; 
$query="Select count(risk) as count, risk from nessus_results where username='$username' and";
$boolAnd=FALSE;
if($severity<>""){
	$query=$query." risk='$severity'";
	$boolAnd=TRUE;
}
if($hostname<>""){
	if($boolAnd){$query=$query." and";}
	$query=$query." host='$hostname'";
	$boolAnd=TRUE;
}
if($service<>""){
	if($boolAnd){$query=$query." and";}
	$query=$query." service='$service'";
	$boolAnd=TRUE;
}
if($plugin<>""){
        if($boolAnd){$query=$query." and";}
        $query=$query." scriptid='$plugin'";
        $boolAnd=TRUE;
}
if($description<>""){
	if($boolAnd){$query=$query." and";}
	$query=$query." msg LIKE '%$description%'";
	$boolAnd=TRUE;
}
if(!$showFP){
	if($boolAnd){$query=$query." and";}
	$query=$query." falsepositive='N'";
	$boolAnd=TRUE;
}
if(!$showInfo){
	if($boolAnd){$query=$query." and";}
	$query=$query." risk!='7'";
}
$query=$query." group by risk";

$result=$dbconn->Execute($query); 
while (list($riskcount, $risk)=$result->fields) {
	echo "<br>".getrisk($risk)." : $riskcount";
	$result->MoveNext();
}
//echo"$query";
echo "</td></tr>";
$query="select distinct result_id, host, service, risk, msg, scriptid, falsepositive, scantime, scantype, sched_id from nessus_results where username='$username' and";
$boolAnd=FALSE;if($severity<>""){
	$query=$query." risk='$severity'";
	$boolAnd=TRUE;
}
if($hostname<>""){
	if($boolAnd){$query=$query." and";}
	$query=$query." host='$hostname'";
	$boolAnd=TRUE;
}
if($service<>""){
	if($boolAnd){$query=$query." and";}
	$query=$query." service='$service'";
	$boolAnd=TRUE;
}
if($plugin<>""){
        if($boolAnd){$query=$query." and";}
        $query=$query." scriptid='$plugin'";
        $boolAnd=TRUE;
}
if($description<>""){
	if($boolAnd){$query=$query." and";}
	$query=$query." msg LIKE '%$description%'";
	$boolAnd=TRUE;
}
if(!$showFP){
	if($boolAnd){$query=$query." and";}
	$query=$query." falsepositive='N'";
	$boolAnd=TRUE;
}
if(!$showInfo){
	if($boolAnd){$query=$query." and";}
	$query=$query." risk!='7'";
}
$query=$query." order by risk ASC";
//echo"<tr><td>$query</td></tr>";
$result=$dbconn->Execute($query); 

 echo "<tr><td><b>Host IP</b> </td><td><b>Service</b></td><td><b>Severity</b></td><td><b>Description</b></td></tr>"; 
        $bgcolor="#f6f7eb"; 
        while (list($resid, $host, $service, $risk, $msg, $scriptid, $falsepositive, $scantime, $scantype, $schedid, $resid)=$result->fields) { 
                
		$msg=htmlspecialchars($msg);
		$msg=preg_replace("/\n/","<br>",$msg); 


                if ($bgcolor=="#dededf") { 
                        $bgcolor="#ffffff"; 
                } 
                else { 
                        $bgcolor="#dededf"; 
                }; 
                echo "<tr bgcolor=\"$bgcolor\"><td>$host</td><td>$service</td><td>".getrisk($risk)."</td>"; 
                if ($msg=="") { 
                        $msg="Port is open"; 
                 }; 
                echo "<td>$msg"; 
 
		if ($scriptid <>"") { 
                        echo "<br><a href=\"lookup.php?id=$scriptid\">More...</a>"; 
		echo " <a href=\"notes.php?op=add&amp;pid=$scriptid\">Add Note</a>"; 
                } 
	 
		if ($falsepositive=="Y") { 
 
		echo " <B>This result is false positive </B><a href=\"search.php?severity=$severity&amp;ostname=$hostname&amp;service=$service&amp;description=$description&amp;nfp=$resid\">Clear false positive</A>";  
		} 
		else { 
 
		echo " <a href=\"search.php?severity=$severity&amp;hostname=$hostname&amp;service=$service&amp;description=$description&amp;fp=$resid\">Mark as false positive</A>"; 
 
		} 
 
		echo "</td></tr>"; 
                $result->MoveNext(); 
                } 
 
        echo "</table>"; 
        //} 

        
include ('footer.php'); 


function getrisk($risk) { 
 
switch ($risk) { 
    case 1: 
        $risk="Serious"; 
        break; 
    case 2: 
        $risk="High"; 
        break; 
    case 3: 
        $risk="Medium"; 
        break; 
    case 4: 
	$risk="Medium/Low"; 
	break; 
    case 5: 
	$risk="Low/Medium"; 
	break; 
    case 6: 
	$risk="Low"; 
	break; 
    case 7: 
	$risk="Info"; 
	break; 
} 
 
return $risk; 
} 
?> 
