Nettacker icon indicating copy to clipboard operation
Nettacker copied to clipboard

SslLibrary crashes with unhandled OSError: port/proto not found on non-standard SSL ports

Open himanchalkaushale opened this issue 3 weeks ago • 4 comments

Summary

SslLibrary.ssl_certificate_scan() and SslLibrary.ssl_version_and_cipher_scan() in nettacker/core/lib/ssl.py raise an unhandled OSError: port/proto not found when scanning SSL services on non-standard ports such as 8443, 9443, 4443, 8080, and 10443.

This occurs because socket.getservbyport() cannot resolve ports that are not registered in the system's services database. As a result, SSL scans on these ports silently fail instead of returning certificate and cipher information.

Current Behavior

Three locations in nettacker/core/lib/ssl.py (lines 166, 206, and 211) call:

"service": socket.getservbyport(int(port))

When the requested port has no registered service name, Python raises:

OSError: port/proto not found

In BaseEngine.run(), this exception is caught by the generic retry handler, resulting in response = [].

Consequently, SSL certificate and cipher scans may return empty results without reporting certificate details, expiration dates, or related vulnerabilities.

Expected Behavior

SSL scans should handle service lookup failures gracefully.

If socket.getservbyport() raises OSError, the service name should fall back to "unknown", allowing the SSL scan to continue.

This would also align with the existing fallback implementation in nettacker/core/lib/socket.py:51-54:

try:
    service = socket.getservbyport(port)
except OSError:
    service = "unknown"

Root Cause

socket.getservbyport() raises OSError when a port is not registered in the operating system's services database.

Although nettacker/core/lib/socket.py already handles this case, nettacker/core/lib/ssl.py performs three service lookups without exception handling.

Additionally, tests/unit/core/lib/test_ssl.py uses PORT = 80 in connection_params, which does not expose the issue with unmapped ports.

Steps to Reproduce

Run an SSL certificate scan against a host serving HTTPS on port 8443:

poetry run nettacker -i example.com -m ssl_certificate_scan -g 8443

Observe that the SSL scan returns no certificate results because the service lookup raises an exception that is subsequently swallowed by the engine's retry handler.

The underlying issue can also be reproduced independently:

import socket

socket.getservbyport(8443)
# OSError: port/proto not found

Proposed Solution

Introduce a helper in nettacker/core/lib/ssl.py to handle unmapped service ports:

def get_service_name(port):
    try:
        return socket.getservbyport(int(port))
    except OSError:
        return "unknown"

Replace the three direct socket.getservbyport(int(port)) calls at lines 166, 206, and 211 with this helper.

This would ensure that an unavailable service-name mapping does not interrupt SSL scanning.

Testing

Add regression tests in tests/unit/core/lib/test_ssl.py covering:

  1. SSL certificate scanning on port 8443 without mocking socket.getservbyport(), verifying that the unmapped port is handled gracefully.
  2. The service name falls back to "unknown" when the lookup raises OSError.
  3. Both certificate and version/cipher scanning paths handle unmapped ports without failing.
  4. Existing behavior for standard ports remains unchanged.

Additional Context

  • Affected file: nettacker/core/lib/ssl.py
  • Affected methods: ssl_certificate_scan() and ssl_version_and_cipher_scan()
  • Affected locations: Lines 166, 206, and 211
  • Existing fallback implementation: nettacker/core/lib/socket.py:51-54
  • Existing tests: tests/unit/core/lib/test_ssl.py

This issue is specific to service-name resolution and should not require changes to the underlying SSL certificate or cipher scanning logic.

himanchalkaushale avatar Nov 13 '26 16:11 himanchalkaushale

I would like to work on this issue!, Thanks!

himanchalkaushale avatar Nov 13 '26 16:11 himanchalkaushale

@himanchalkaushale - what platform/OS are you using?

securestep9 avatar Nov 13 '26 17:11 securestep9

@himanchalkaushale - what platform/OS are you using?

I am using kali linux using wsl

himanchalkaushale avatar Nov 13 '26 17:11 himanchalkaushale

Hi @securestep9, could you please assign this issue to me? I'd like to work on it and submit a PR. Thank you!

himanchalkaushale avatar Nov 15 '26 06:11 himanchalkaushale