FreeBSD — 1 vulnerability check
noctis ships 1 vulnerability check for FreeBSD, covering 1 CVE; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
FreeBSD telnetd encryption key ID buffer overflow (encryption option enabled)
| CVE | CVE-2011-4862 |
|---|---|
| Severity | critical · CVSS 10.0 |
| Category | rce — Remote code execution |
| Services | telnet |
| Detection | tcp_open, sleep, tcp_send, script, set_var, tcp_close, match · highest QoD 70 |
| Feed | tests/vulnerabilities/freebsd/CVE-2011-4862.yaml |
Detects a FreeBSD Telnet daemon that has encryption support enabled, the code affected by a buffer overflow in the handling of encryption key IDs (FreeBSD releases before the December 2011 fix, FreeBSD-SA-11:08): an unauthenticated client can run commands as root. The feed opens a Telnet session, refuses every option the server proposes so that it prints its login banner, and checks that the banner names FreeBSD. On a second session it sends the standard encryption start-up message (ENCRYPT IS DES_CFB64 with an initialisation vector) and reports when the server answers it with an ENCRYPT REPLY, which proves the vulnerable encryption code is reachable before login. No overlong key ID is sent and nothing runs on the target. The banner does not give the FreeBSD release, so a fixed system that keeps Telnet encryption enabled is reported as well.
How noctis detects it
- Opens a persistent TCP/TLS socket
- Sends
…on the open socket - Parses / computes the next value with a Rhai script
- Parses / computes the next value with a Rhai script
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Sends a binary frame on the open socket
- Parses / computes the next value with a Rhai script
- Opens a persistent TCP/TLS socket
- Sends a binary frame on the open socket
- … and 3 more steps — see the feed source below
References:
- https://nvd.nist.gov/vuln/detail/CVE-2011-4862
- https://security.freebsd.org/advisories/FreeBSD-SA-11:08.telnetd.asc
- http://www.securityfocus.com/bid/51182
Feed source — tests/vulnerabilities/freebsd/CVE-2011-4862.yaml
# FreeBSD telnetd — encryption option (ENCRYPT) key-ID buffer overflow,
# CVE-2011-4862 (FreeBSD-SA-11:08.telnetd). An overlong ENC_KEYID/DEC_KEYID
# suboption overflows a fixed 64-byte buffer in encrypt_keyid() and lets an
# unauthenticated client run code as root.
#
# Credit: detection logic adapted from Greenbone's
# `2011/freebsd/gb_freebsd_telnetd_51182.nasl` (GPL-2.0-only). That check sends
# memory-corruption shellcode in an overlong ENC_KEYID and runs `id`. The
# exploit is NOT ported: it is remote code execution with a crafted payload
# and, on a mismatched target, crashes the session process.
#
# What is ported, unchanged: the source check's two gates — the Telnet banner
# names FreeBSD, and the daemon answers an ENCRYPT IS DES_CFB64 suboption with
# ENCRYPT REPLY ("fffa260201"), i.e. the encryption code that holds the bug is
# compiled in and reachable before login. The source check stops there for a
# telnetd without encryption ("no need to continue"); this feed reports when
# both gates pass.
#
# Why no exploit proof: the fix only adds a length check that silently drops
# an overlong key ID, so the only observable difference is memory corruption
# (crash or code execution). There is no benign in-band or OOB proof, so this
# is a fingerprint (QoD 70), which the project accepts when no better method
# exists.
# Limitation: the FreeBSD Telnet banner carries no release number, so a FreeBSD
# telnetd that has the fix (7.3/7.4/8.1/8.2 patch levels from December 2011,
# 8.3 and later) is reported as well.
#
# Improvement over the source check: it answers the server's option
# negotiation (WONT/DONT for every DO/WILL, up to four rounds, plus a late read of a slow greeting), which a real
# FreeBSD telnetd needs before it prints the "FreeBSD/<arch> (host) (pts/N)"
# banner — without answers it waits and never shows the banner.
uid: c801fb8a-3611-4556-ab1b-964b2db4e766
name: "FreeBSD telnetd encryption key ID buffer overflow (encryption option enabled)"
description: |
Detects a FreeBSD Telnet daemon that has encryption support enabled, the
code affected by a buffer overflow in the handling of encryption key IDs
(FreeBSD releases before the December 2011 fix, FreeBSD-SA-11:08): an unauthenticated
client can run commands as root. The feed opens a Telnet session, refuses
every option the server proposes so that it prints its login banner, and
checks that the banner names FreeBSD. On a second session it sends the
standard encryption start-up message (ENCRYPT IS DES_CFB64 with an
initialisation vector) and reports when the server answers it with an
ENCRYPT REPLY, which proves the vulnerable encryption code is reachable
before login. No overlong key ID is sent and nothing runs on the target.
The banner does not give the FreeBSD release, so a fixed system that keeps
Telnet encryption enabled is reported as well.
category: rce
cves: [CVE-2011-4862]
cvss: 10.0
severity: critical
confidence_base: 0.30
tags: [freebsd, telnet, telnetd, encryption, buffer-overflow, fingerprint]
services: [telnet]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2011-4862"
- "https://security.freebsd.org/advisories/FreeBSD-SA-11:08.telnetd.asc"
- "http://www.securityfocus.com/bid/51182"
steps:
# ---------------------------------------------------------- session 1: banner
- id: open-banner
action: tcp_open
handle: tn
port: "{{port}}"
read_banner: true
timeout_secs: 10
store_as: conn
# Slow greeting (reverse DNS lookup of the scanner, inetd fork): read it late
# so the negotiation rounds below stay aligned.
- id: greet-wait
action: sleep
condition: 'conn.connected == true && type_of(conn.banner_hex) != "string"'
duration_ms: 3000
- id: greet-late
action: tcp_send
condition: 'conn.connected == true && type_of(conn.banner_hex) != "string"'
handle: tn
send_hex: ""
store_as: g0
- id: greet-merge
action: script
condition: 'conn.connected == true && type_of(conn.banner_hex) != "string"'
store_as: conn
code: |
#{ connected: true, banner: g0.response, banner_hex: g0.response_hex }
# Refuse every option the server asks for (DO x -> WONT x, WILL x -> DONT x).
# Bytes are walked on pair boundaries, so a hex match never straddles two bytes.
- id: refuse-1
action: script
store_as: neg1
code: |
let h = if type_of(conn.banner_hex) == "string" { conn.banner_hex } else { "" };
let out = "";
let i = 0;
let n = strlen(h);
while i + 1 < n {
if substr(h, i, i + 1) == "ff" && i + 5 < n {
let c = substr(h, i + 2, i + 3);
let o = substr(h, i + 4, i + 5);
if c == "fd" { out += "fffc" + o; i += 6; continue; }
if c == "fb" { out += "fffe" + o; i += 6; continue; }
if c == "fc" || c == "fe" || c == "ff" { i += 6; continue; }
}
i += 2;
}
#{ hex: out }
- id: answer-1
action: tcp_send
condition: "conn.connected == true"
handle: tn
send_hex: "{{neg1.hex}}"
store_as: r1
- id: init-r1
action: set_var
condition: "conn.connected != true"
var_name: r1
var_value: {response: "", response_hex: ""}
- id: refuse-2
action: script
store_as: neg2
code: |
let h = if type_of(r1.response_hex) == "string" { r1.response_hex } else { "" };
let out = "";
let i = 0;
let n = strlen(h);
while i + 1 < n {
if substr(h, i, i + 1) == "ff" && i + 5 < n {
let c = substr(h, i + 2, i + 3);
let o = substr(h, i + 4, i + 5);
if c == "fd" { out += "fffc" + o; i += 6; continue; }
if c == "fb" { out += "fffe" + o; i += 6; continue; }
if c == "fc" || c == "fe" || c == "ff" { i += 6; continue; }
}
i += 2;
}
#{ hex: out }
- id: answer-2
action: tcp_send
condition: "conn.connected == true"
handle: tn
send_hex: "{{neg2.hex}}"
store_as: r2
- id: init-r2
action: set_var
condition: "conn.connected != true"
var_name: r2
var_value: {response: "", response_hex: ""}
- id: refuse-3
action: script
store_as: neg3
code: |
let h = if type_of(r2.response_hex) == "string" { r2.response_hex } else { "" };
let out = "";
let i = 0;
let n = strlen(h);
while i + 1 < n {
if substr(h, i, i + 1) == "ff" && i + 5 < n {
let c = substr(h, i + 2, i + 3);
let o = substr(h, i + 4, i + 5);
if c == "fd" { out += "fffc" + o; i += 6; continue; }
if c == "fb" { out += "fffe" + o; i += 6; continue; }
if c == "fc" || c == "fe" || c == "ff" { i += 6; continue; }
}
i += 2;
}
#{ hex: out }
# Third round: real FreeBSD telnetd prints the banner after the answer to
# DO NAWS; the fourth round is margin.
- id: answer-3
action: tcp_send
condition: "conn.connected == true"
handle: tn
send_hex: "{{neg3.hex}}"
store_as: r3
- id: init-r3
action: set_var
condition: "conn.connected != true"
var_name: r3
var_value: {response: ""}
- id: refuse-4
action: script
store_as: neg4
code: |
let h = if type_of(r3.response_hex) == "string" { r3.response_hex } else { "" };
let out = "";
let i = 0;
let n = strlen(h);
while i + 1 < n {
if substr(h, i, i + 1) == "ff" && i + 5 < n {
let c = substr(h, i + 2, i + 3);
let o = substr(h, i + 4, i + 5);
if c == "fd" { out += "fffc" + o; i += 6; continue; }
if c == "fb" { out += "fffe" + o; i += 6; continue; }
if c == "fc" || c == "fe" || c == "ff" { i += 6; continue; }
}
i += 2;
}
#{ hex: out }
- id: answer-4
action: tcp_send
condition: "conn.connected == true"
handle: tn
send_hex: "{{neg4.hex}}"
store_as: r4
- id: init-r4
action: set_var
condition: "conn.connected != true"
var_name: r4
var_value: {response: ""}
- id: close-banner
action: tcp_close
handle: tn
# FreeBSD's default banner (gettytab "im"): "FreeBSD/amd64 (host) (pts/0)".
- id: banner
action: script
store_as: bn
code: |
let t = "";
if type_of(conn.banner) == "string" { t += conn.banner + "\n"; }
if type_of(r1.response) == "string" { t += r1.response + "\n"; }
if type_of(r2.response) == "string" { t += r2.response + "\n"; }
if type_of(r3.response) == "string" { t += r3.response + "\n"; }
if type_of(r4.response) == "string" { t += r4.response + "\n"; }
let m = eregmatch("FreeBSD[^\\r\\n\\x00-\\x08]{0,80}", t);
if type_of(m) == "array" && m.len() > 0 {
#{ fbsd: true, line: m[0] }
} else {
#{ fbsd: false, line: "" }
}
# ------------------------------------------------ session 2: encryption probe
- id: open-enc
action: tcp_open
condition: "bn.fbsd == true"
handle: enc
port: "{{port}}"
read_banner: true
timeout_secs: 10
store_as: econn
# IAC SB ENCRYPT IS DES_CFB64 FB64_IV <8-byte IV> IAC SE — the message a
# Telnet client sends to start DES_CFB64 encryption. Same bytes as the source check.
- id: encrypt-is
action: tcp_send
condition: "bn.fbsd == true && econn.connected == true"
handle: enc
send_hex: "fffa260001011213141516171819fff000"
store_as: e1
- id: init-e2
action: set_var
var_name: e2
var_value: {response_hex: ""}
- id: enc-wait
action: sleep
condition: 'bn.fbsd == true && econn.connected == true && e1.responded != true'
duration_ms: 3000
- id: enc-late
action: tcp_send
condition: 'bn.fbsd == true && econn.connected == true && e1.responded != true'
handle: enc
send_hex: ""
store_as: e2
- id: close-enc
action: tcp_close
handle: enc
# ENCRYPT REPLY DES_CFB64 (fffa260201) on a byte boundary, in the greeting
# read or in the reply.
- id: encrypt-reply
action: script
condition: "bn.fbsd == true && econn.connected == true"
store_as: er
code: |
let h = "";
if type_of(econn.banner_hex) == "string" { h += econn.banner_hex; }
if type_of(e1.response_hex) == "string" { h += e1.response_hex; }
if type_of(e2.response_hex) == "string" { h += e2.response_hex; }
#{ ok: ereg("^(?:[0-9a-f]{2})*?fffa260201", h) }
- id: report
action: match
condition: "bn.fbsd == true && econn.connected == true && er.ok == true"
source: bn.line
pattern: 'FreeBSD'
on_match:
finding:
title: "FreeBSD telnetd with encryption enabled (key ID buffer overflow)"
description: "The Telnet service is FreeBSD's telnetd and it answers an ENCRYPT IS DES_CFB64 suboption before login, so the encryption code affected by the key ID buffer overflow (CVE-2011-4862, FreeBSD-SA-11:08.telnetd) is reachable by unauthenticated clients. On FreeBSD releases without the December 2011 fix this allows remote code execution as root. The FreeBSD release cannot be read from the banner, so a fixed system is reported too."
remediation: "Apply FreeBSD-SA-11:08.telnetd or upgrade FreeBSD, and disable telnetd (use SSH instead) or restrict the Telnet port to trusted networks."
confidence_delta: 0.45
qod: 70
evidence: "Telnet banner: {{bn.line}}; ENCRYPT IS DES_CFB64 answered with ENCRYPT REPLY (fffa260201)"