Vulnerabilities > CVE-2009-0641 - Configuration vulnerability in Freebsd

047910
CVSS 0.0 - NONE
Attack vector
UNKNOWN
Attack complexity
UNKNOWN
Privileges required
UNKNOWN
Confidentiality impact
UNKNOWN
Integrity impact
UNKNOWN
Availability impact
UNKNOWN
freebsd
CWE-16
nessus
exploit available

Summary

sys_term.c in telnetd in FreeBSD 7.0-RELEASE and other 7.x versions deletes dangerous environment variables with a method that was valid only in older FreeBSD distributions, which might allow remote attackers to execute arbitrary code by passing a crafted environment variable from a telnet client, as demonstrated by an LD_PRELOAD value that references a malicious library.

Common Weakness Enumeration (CWE)

Exploit-Db

descriptionFreeBSD 7.0-RELEASE Telnet Daemon Local Privilege Escalation Exploit. CVE-2009-0641. Local exploit for freebsd platform
fileexploits/freebsd/local/8055.txt
idEDB-ID:8055
last seen2016-02-01
modified2009-02-16
platformfreebsd
port
published2009-02-16
reporterkingcope
sourcehttps://www.exploit-db.com/download/8055/
titleFreeBSD 7.0-RELEASE Telnet Daemon - Local Privilege Escalation Exploit
typelocal

Nessus

NASL familyGain a shell remotely
NASL idFREEBSD_TELNETD_CODE_EXEC.NASL
descriptionA flaw in the environment-handling code used by the telnet server running on the remote host fails to scrub the environment of variables such as
last seen2020-06-01
modified2020-06-02
plugin id35700
published2009-02-17
reporterThis script is Copyright (C) 2009-2018 Tenable Network Security, Inc.
sourcehttps://www.tenable.com/plugins/nessus/35700
titleFreeBSD telnetd sys_term.c Environment Variable Handling Privilege Escalation (FreeBSD-SA-09:05)
code
#
# (C) Tenable Network Security, Inc.
#

include("compat.inc");

if (description)
{
  script_id(35700);
  script_version("1.19");
  script_set_attribute(attribute:"plugin_modification_date", value:"2020/06/12");

  script_cve_id("CVE-2009-0641");
  script_bugtraq_id(33777);
  script_xref(name:"EDB-ID", value:"8055");

  script_name(english:"FreeBSD telnetd sys_term.c Environment Variable Handling Privilege Escalation (FreeBSD-SA-09:05)");
  script_summary(english:"Tries to pass LD_DUMP_REL_POST=1 when calling login");

  script_set_attribute(attribute:"synopsis", value:"The remote telnet server is vulnerable to a code execution attack.");
  script_set_attribute(attribute:"description", value:
"A flaw in the environment-handling code used by the telnet server
running on the remote host fails to scrub the environment of variables
such as 'LD_PRELOAD' before calling the login program. An attacker who
can place an arbitrary library on the remote host, either as a local
user or remotely through some other means, can leverage this issue to
execute arbitrary code subject to the privileges under which the
service runs, typically 'root'.");
  script_set_attribute(attribute:"see_also", value:"https://www.freebsd.org/security/advisories/FreeBSD-SA-09:05.telnetd.asc");
  script_set_attribute(attribute:"see_also", value:"https://seclists.org/bugtraq/2009/Feb/150");
  script_set_attribute(attribute:"solution", value:
"Patch or upgrade the affected system as described in the project's
advisory above.");
  script_set_cvss_base_vector("CVSS2#AV:N/AC:H/Au:N/C:C/I:C/A:C");
  script_set_cvss_temporal_vector("CVSS2#E:F/RL:OF/RC:C");
  script_set_attribute(attribute:"exploitability_ease", value:"Exploits are available");
  script_set_attribute(attribute:"exploit_available", value:"true");
  script_set_attribute(attribute:"exploit_framework_core", value:"true");
  script_cwe_id(16, 264);

  script_set_attribute(attribute:"plugin_publication_date", value:"2009/02/17");

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

  script_category(ACT_ATTACK);
  script_family(english:"Gain a shell remotely");
  script_copyright(english:"This script is Copyright (C) 2009-2020 Tenable Network Security, Inc.");

  script_dependencies("find_service1.nasl");
  script_require_ports("Services/telnet", 23);

  exit(0);
}


include("global_settings.inc");
include("byte_func.inc");
include("misc_func.inc");
include("telnet2_func.inc");


port = get_kb_item("Services/telnet");
if (!port) port = 23;
if (!get_port_state(port)) exit(0);


global_var rcvdata;


function local_telnet_callback()
{
  local_var data;

  data = _FCT_ANON_ARGS[0];

  # Accumulate each byte as it's received.
  if (data && ord(data[0]) != 0x00 && ord(data[0]) != 0x0d) rcvdata += data[0];

  # There's a problem if we were able to see info about symbol
  # bindings and relocations.
  if (
    'login", relocbase ' >< rcvdata &&
    'libbz2.so", relocbase ' >< rcvdata
  )
  {
    security_hole(port);
    exit(0);
  }
  if ("login: " >< rcvdata || "assword:" >< rcvdata )
  {
    exit(0);
  }
}


# Set up the environment.
env_data =
  mkbyte(0) +
  mkbyte(3) + "LD_DUMP_REL_POST" +
    mkbyte(1) + "1" +
  mkbyte(3) + "LD_PRELOAD" +
    mkbyte(1) + "/usr/lib/libbz2.so" +
  mkbyte(0) + "USER" +
    mkbyte(1) + "nessus";

options = NULL;
options[0] = make_list(OPT_NEW_ENV, env_data);


# Connect and process options.
if (!telnet2_init(port:port, options:options, timeout:5*get_read_timeout()))
  exit(0);

rcvdata = NULL;
telnet_loop(telnet_callback_fn:@local_telnet_callback);