###############################################################################
# OpenVAS Vulnerability Test
# $Id: secpod_wingate_detect.nasl 760 2009-03-18 11:58:02Z mar $
#
# Qbik WinGate Version Detection
#
# Authors:
# Sharath S <sharaths@secpod.com>
#
# Copyright:
# Copyright (c) 2009 SecPod, http://www.secpod.com
#
# 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(900324);
  script_version("$Revision: 1.0 $");
  script_tag(name:"risk_factor", value:"None");
  script_name("Qbik WinGate Version Detection");
  desc = "
  Overview: This script detects the version of WinGate and sets the
  result in KB.

  Risk factor: None";

  script_description(desc);
  script_summary("Set KB for the version of WinGate");
  script_category(ACT_GATHER_INFO);
  script_copyright("Copyright (C) 2009 SecPOd");
  script_family("General");
  script_dependencies("secpod_reg_enum.nasl");
  script_require_keys("SMB/WindowsVersion");
  script_require_ports(139, 445);
  exit(0);
}


include("smb_nt.inc");
include("secpod_smb_func.inc");

if(!get_kb_item("SMB/WindowsVersion")){
  exit(0);
}

path = registry_get_sz(key:"SOFTWARE\Microsoft\Windows\CurrentVersion" +
                           "\App Paths\gatekeeper.exe", item:"Path");
if(path)
{
  path = path - "\Gatekeeper.exe" + "\WinGate.exe";
  share = ereg_replace(pattern:"([A-Za-z]):.*", replace:"\1$", string:path);
  file =  ereg_replace(pattern:"[A-Za-z]:(.*)", replace:"\1", string:path);
  winGateVer = GetVer(file:file, share:share);

  if(winGateVer != NULL){
    set_kb_item(name:"WinGate/Ver", value:winGateVer);
    security_note(data:"Qbik WinGate version " + winGateVer + " running at " +
                       "location " + path +  " was detected on the host");
  }
}
