Lucene search
+L

Prefix Truncation Attacks in SSH Specification (Terrapin Attack)

🗓️ 20 Dec 2023 00:00:00Reported by Copyright (C) 2023 Greenbone AGType 
openvas
 openvas
🔗 plugins.openvas.org👁 47 Views

The remote SSH server is vulnerable to prefix truncation attacks (Terrapin Attack) due to specific encryption algorithm or MAC support, potentially allowing a man-in-the-middle attacker to downgrade connection security

Related
Refs
Code
ReporterTitlePublishedViews
Family
osv
OSV
CGA-8843-X75P-F8HF
6 Jun 202412:25
osv
osv
OSV
CGA-893G-VJVJ-JCCM
30 Oct 202522:25
osv
osv
OSV
CGA-899Q-92C7-43J4
30 Oct 202522:16
osv
osv
OSV
CGA-89FQ-2X54-VVM8
30 Oct 202522:25
osv
osv
OSV
CGA-8CC2-V9P5-7298
6 Jun 202412:25
osv
osv
OSV
CGA-8CVQ-W625-HC7X
6 Jun 202412:25
osv
osv
OSV
CGA-8F7J-VQFJ-CMC6
30 Oct 202518:58
osv
osv
OSV
CGA-8FJ5-V46F-W38X
30 Oct 202519:58
osv
osv
OSV
CGA-8FQH-6MF2-M632
30 Oct 202520:38
osv
osv
OSV
CGA-8FX5-6WJ9-CFV5
30 Oct 202519:26
osv
Rows per page
# SPDX-FileCopyrightText: 2023 Greenbone AG
# Some text descriptions might be excerpted from (a) referenced
# source(s), and are Copyright (C) by the respective right holder(s).
#
# SPDX-License-Identifier: GPL-2.0-only

if(description)
{
  script_oid("1.3.6.1.4.1.25623.1.0.114238");
  script_version("2025-04-23T05:39:47+0000");
  # nb: https://github.com/apache/mina-sshd/pull/449 shows that Apache MINA also implemented the
  # mitigation via [email protected] (checked below) so the relevant CVE could be added
  # here as well.
  script_cve_id("CVE-2023-48795", "CVE-2024-41909");
  script_tag(name:"last_modification", value:"2025-04-23 05:39:47 +0000 (Wed, 23 Apr 2025)");
  script_tag(name:"creation_date", value:"2023-12-20 10:10:53 +0000 (Wed, 20 Dec 2023)");
  script_tag(name:"cvss_base", value:"5.4");
  script_tag(name:"cvss_base_vector", value:"AV:N/AC:H/Au:N/C:N/I:C/A:N");
  script_tag(name:"severity_vector", value:"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:N");
  script_tag(name:"severity_origin", value:"NVD");
  script_tag(name:"severity_date", value:"2023-12-29 03:15:00 +0000 (Fri, 29 Dec 2023)");
  script_name("Prefix Truncation Attacks in SSH Specification (Terrapin Attack)");
  script_copyright("Copyright (C) 2023 Greenbone AG");
  script_category(ACT_GATHER_INFO);
  script_family("General");
  script_dependencies("gb_ssh_algos.nasl");
  script_require_ports("Services/ssh", 22);
  script_mandatory_keys("ssh/algos_available");

  script_xref(name:"URL", value:"https://terrapin-attack.com");
  script_xref(name:"URL", value:"https://www.openssh.com/txt/release-9.6");
  script_xref(name:"URL", value:"https://lists.apache.org/thread/vwf1ot8wx1njyy8n19j5j2tcnjnozt3b");
  script_xref(name:"URL", value:"https://github.com/apache/mina-sshd/issues/445");
  script_xref(name:"URL", value:"https://github.com/apache/mina-sshd/pull/449");

  script_tag(name:"summary", value:"The remote SSH server is supporting an specific encryption
  algorithm or MAC. Parts of their SSH specification are vulnerable to a novel prefix truncation
  attack (a.k.a. Terrapin attack).");

  script_tag(name:"vuldetect", value:"Checks the supported algorithms and MACs of the remote SSH
  server.

  Note: This VT has a low QoD because mitigation is possible / available via software updates.");

  script_tag(name:"insight", value:"Parts of the SSH specification are vulnerable to a novel prefix
  truncation attack (a.k.a. Terrapin attack), which allows a man-in-the-middle attacker to strip an
  arbitrary number of messages right after the initial key exchange, breaking SSH extension
  negotiation (RFC8308) in the process and thus downgrading connection security.");

  script_tag(name:"affected", value:"Systems supporting the following encryption algorithm and/or
  MACs:

  - ChaCha20-Poly1305 ([email protected]) encryption algorithm

  - CBC encryption algorithm and Encrypt-then-MAC (*[email protected]) MAC");

  script_tag(name:"solution", value:"- Update OpenSSH to version 9.6 or later

  - Update Apache MINA SSHD to version 2.12.0 or later

  - For other products please contact the vendor for possible fixes / updates

  Mitigation:

  - To mitigate this protocol vulnerability, OpenSSH suggested a so-called 'strict kex' which alters
  the SSH handshake to ensure a Man-in-the-Middle attacker cannot introduce unauthenticated messages
  as well as convey sequence number manipulation across handshakes. Support for strict key exchange
  has been added to a variety of SSH implementations, including OpenSSH itself, PuTTY, libssh, and
  more.

  Warning: To take effect, both the client and server must support this countermeasure.

  As a stop-gap measure, peers may also (temporarily) disable the affected algorithms and use
  unaffected alternatives like AES-GCM instead until patches are available.");

  script_tag(name:"qod_type", value:"remote_banner_unreliable");
  script_tag(name:"solution_type", value:"VendorFix");

  exit(0);
}

include("ssh_func.inc");
include("port_service_func.inc");
include("misc_func.inc");
include("host_details.inc");

function check_algo( port, type, check_for, part_match ) {

  local_var port, type, check_for, part_match;
  local_var to_check_list, report, to_check;

  if( ! type || ! port || ! check_for )
    return;

  if( ! to_check_list = get_kb_list( "ssh/" + port + "/" + type ) )
    return;

  report = "";

  # Sort to not report changes on delta reports if just the order is different
  to_check_list = sort( to_check_list );

  foreach to_check( to_check_list ) {

    if( part_match ) {

      if( check_for >< to_check )
        report += to_check + '\n';

    } else {

      if( check_for == to_check )
        report += to_check + '\n';
    }
  }

  if( strlen( report ) > 0 )
    return report;
}

port = ssh_get_port( default:22 );

if( rep_mac = check_algo( port:port, type:"mac_algorithms_client_to_server", check_for:"[email protected]", part_match:TRUE ) ) {

  if( rep_enc_algo = check_algo( port:port, type:"encryption_algorithms_client_to_server", check_for:"-cbc", part_match:TRUE ) ) {

    report = 'The remote SSH server supports the following possible affected client-to-server MAC algorithm(s):\n\n' + rep_mac + '\n';
    report += 'together with the following possible affected client-to-server encryption algorithm(s):\n\n' + rep_enc_algo + '\n';
  }
}

if( rep_mac = check_algo( port:port, type:"mac_algorithms_server_to_client", check_for:"[email protected]", part_match:TRUE ) ) {

  if( rep_enc_algo = check_algo( port:port, type:"encryption_algorithms_server_to_client", check_for:"-cbc", part_match:TRUE ) ) {

    report += 'The remote SSH server supports the following possible affected server-to-client MAC algorithm(s):\n\n' + rep_mac + '\n';
    report += 'together with the following possible affected server-to-client encryption algorithm(s):\n\n' + rep_enc_algo + '\n';
  }
}

if( rep_enc_algo = check_algo( port:port, type:"encryption_algorithms_client_to_server", check_for:"[email protected]", part_match:FALSE ) )
  report += 'The remote SSH server supports the following possible affected client-to-server encryption algorithm(s):\n\n' + rep_enc_algo + '\n';

if( rep_enc_algo = check_algo( port:port, type:"encryption_algorithms_server_to_client", check_for:"[email protected]", part_match:FALSE ) )
  report += 'The remote SSH server supports the following possible affected server-to-client encryption algorithm(s):\n\n' + rep_enc_algo  + '\n';

if( report ) {

  # nb:
  # - Store the reference from this one to gb_ssh_algos.nasl to show a cross-reference within the
  #   reports
  # - We don't want to use get_app_* functions as we're only interested in the cross-reference here
  register_host_detail( name:"detected_by", value:"1.3.6.1.4.1.25623.1.0.105565" ); # gb_ssh_algos.nasl
  register_host_detail( name:"detected_at", value:port + "/tcp" );

  # nb: Only "[email protected]" is currently tested here because the "c" in
  # "[email protected]" seems to stand for "Client" but we're only scanning / testing the
  # Server part (represented by the "s") here.
  rep_mitigation = check_algo( port:port, type:"kex_algorithms", check_for:"[email protected]", part_match:FALSE );
  if( rep_mitigation )
    report += 'The remote SSH server supports the following "strict kex" algorithm as a possible mitigation:\n\n' + rep_mitigation;

  security_message( port:port, data:chomp( report ) );
  exit( 0 );
}

exit( 99 );

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation