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

Open Beginner friendly
#1,884 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@himanchalkaushale is already working on this.

Since Nov 13, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
security, testing

Research direction

Start with nettacker/core/lib/ssl.py and compare its three service lookups with the fallback in nettacker/core/lib/socket.py:51-54; then read tests/unit/core/lib/test_ssl.py. Run the SSL unit tests and add regression coverage for unmapped ports in both scan paths, including the unknown fallback. Done when non-standard ports no longer raise and standard-port behavior remains unchanged.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
5.7k
Forks
1.2k
Avg merge
2d 17h
Merged PRs (30d)
12

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OWASP/Nettacker

All issues in OWASP/Nettacker

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.