Skip to content

postgres: raise detection threshold to prevent false positives (#125)#734

Draft
Seanstoppable wants to merge 2 commits into
zmap:masterfrom
Seanstoppable:ssmith/postgres-detection-threshold
Draft

postgres: raise detection threshold to prevent false positives (#125)#734
Seanstoppable wants to merge 2 commits into
zmap:masterfrom
Seanstoppable:ssmith/postgres-detection-threshold

Conversation

@Seanstoppable

Copy link
Copy Markdown
Contributor

The postgres scanner could misidentify non-Postgres services as PostgreSQL when they responded with an 'N' byte (or any non-'E' response) to the version probe. This is the scenario described in issue #125.

Changes:

  • Version probes (0.0 and 255.255) now require the server to return a valid 'E'-type error packet. Any other response type causes the scan to bail with SCAN_PROTOCOL_ERROR.
  • Add isValidPostgresError() to validate that 'E' packets contain the minimum structured fields (severity, code, message) expected from a real PostgreSQL server.
  • Add tests for false-positive scenarios: bare 'N' byte, invalid error fields, immediate close, and valid server responses.

Seanstoppable and others added 2 commits June 8, 2026 22:35
)

The postgres scanner could misidentify non-Postgres services as
PostgreSQL when they responded with an 'N' byte (or any non-'E'
response) to the version probe. This is the scenario described in
issue zmap#125.

Changes:
- Version probes (0.0 and 255.255) now require the server to return
  a valid 'E'-type error packet. Any other response type causes the
  scan to bail with SCAN_PROTOCOL_ERROR.
- Add isValidPostgresError() to validate that 'E' packets contain
  the minimum structured fields (severity, code, message) expected
  from a real PostgreSQL server.
- Add tests for false-positive scenarios: bare 'N' byte, invalid
  error fields, immediate close, and valid server responses.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Older Postgres versions (e.g. 9.3-9.5) respond to bogus version probes
with a raw \n\0-terminated error string rather than a structured 'E'
packet with tagged fields. These have Length=0 in the parsed
ServerPacket.

Only apply isValidPostgresError validation to structured error packets
(Length > 0). Pre-startup errors (Length == 0) are still accepted as
valid Postgres detections since the 'E' type byte combined with the
\n\0 termination is sufficient evidence.

Add TestPreStartupError_OlderPostgres to cover this case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant