###############################################################################
# OpenVAS Vulnerability Test
# $Id: gb_jetty_detect.nasl 5206 2009-10-12 11:33:54Z oct $
#
# Jetty Version Detection
#
# Authors:
# Nikita MR <rnikita@secpod.com>
#
# Copyright:
# Copyright (c) 2009 Intevation GmbH, http://www.intevation.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# (or any later version), 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
###############################################################################

if(description)
{
  script_id(800953);
  script_version("$Revision: 1.0 $");
  script_tag(name:"risk_factor", value:"None");
  script_name("Jetty Version Detection");
  desc = "
  Overview: This script detects the installed version of Jetty WebServer
  and sets the result in KB.

  Risk factor: None";

  script_description(desc);
  script_summary("Sets the KB for the version of Jetty");
  script_category(ACT_GATHER_INFO);
  script_copyright("Copyright (C) 2009 Intevation GmbH");
  script_family("Service detection");
  script_dependencies("http_version.nasl");
  script_require_ports("Services/www", 8080);
  exit(0);
}


include("http_func.inc");

jettyPort = get_http_port(default:8080);
if(!jettyPort){
  jettyPort = 8080;
}

if(!get_port_state(jettyPort)){
  exit(0);
}

banner = get_http_banner(port:jettyPort);

if("Server: Jetty" >< banner)
{
  jettyVer = eregmatch(pattern:"Jetty.([0-9.]+)([a-zA-Z]+[0-9]+)?",
                       string:banner);
  if(jettyVer[1] != NULL)
  {
    if(jettyVer[2] != NULL){
      jettyVer = jettyVer[1] + "." + jettyVer[2];
    }
    else
      jettyVer = jettyVer[1];

    set_kb_item(name:"www/" + jettyPort + "/Jetty", value:jettyVer);
    security_note(data:"Jetty Server version " + jettyVer + " was detected on the host"); 
  }
}
