Repository navigation
feat: improve service detection with case-insensitive headers and fingerprinting - #6
Conversation
…gerprinting - Fix case-sensitive HTTP header parsing (RFC violation) - now detects 'server: uvicorn' and similar lowercase headers - Add HTTP fingerprinting: Go net/http (Traefik), FastAPI, uWebSockets, Node.js http identified by response patterns - Expand Redis port range to 6379-6399 for Docker remapped instances - Generic probe now falls back to Redis/PostgreSQL when HTTP fails - Extract HTML <title> as version info for unidentified HTTP services
Up to standards ✅🟢 Issues
|
Semgrep Static Analysis
No issues found. |
There was a problem hiding this comment.
Pull Request Overview
Two high-confidence detection correctness issues should be fixed before merging: header matching can produce false positives, and arbitrary responses beginning with - can be classified as Redis. The required parsing, fingerprinting, fallback, and regression scenarios are also currently untested.
About this PR
- Add automated coverage for the new detection paths and verify that existing standard-port detection behavior does not regress.
Test suggestions
- Parse Server and X-Powered-By headers with varied capitalization and whitespace.
- Identify Go net/http from nosniff and the standard 404 body.
- Identify FastAPI from a uvicorn Server header and a detail JSON response.
- Identify uWebSockets and preserve its version.
- Identify Node.js HTTP from Keep-Alive and chunked transfer headers.
- Extract an HTML title for an unidentified HTTP service.
- Classify Redis ports across the full 6379-6399 range and PostgreSQL ports across 5432-5434.
- Detect Redis and PostgreSQL through generic-probe fallback when HTTP probing fails.
- Verify standard port scans continue to detect existing services.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Parse Server and X-Powered-By headers with varied capitalization and whitespace.
2. Identify Go net/http from nosniff and the standard 404 body.
3. Identify FastAPI from a uvicorn Server header and a detail JSON response.
4. Identify uWebSockets and preserve its version.
5. Identify Node.js HTTP from Keep-Alive and chunked transfer headers.
6. Extract an HTML title for an unidentified HTTP service.
7. Classify Redis ports across the full 6379-6399 range and PostgreSQL ports across 5432-5434.
8. Detect Redis and PostgreSQL through generic-probe fallback when HTTP probing fails.
9. Verify standard port scans continue to detect existing services.
Make this review better
TIP Add a ticket key to the branch or title so the reviewer can check the PR against it. Or tell us which ticket tracker you use here.
TIP Add Codacy review.md instructions or an AGENTS.md so the reviewer knows your conventions.
TIP How was this review? Give us feedback
| } else { | ||
| info.setName(server); | ||
| // Response to HTTP wasn't HTTP - check if it looks like Redis error | ||
| if (data[0] == '-') { |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Require a Redis-specific RESP error prefix, such as -ERR or -NOAUTH, or another validated Redis response pattern before returning a Redis result. Checking only the first byte produces false-positive detections on unknown ports.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| const pos = findCaseTag(data, header) orelse return null; | ||
| var start = pos + header.len; | ||
| while (start < data.len and (data[start] == ' ' or data[start] == '\t')) start += 1; | ||
| if (start >= data.len) return null; | ||
| const end = std.mem.indexOfPos(u8, data, start, "\r\n") orelse @min(start + 128, data.len); | ||
| if (start >= end) return null; | ||
| return data[start..end]; | ||
| } |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Restrict header matching to the start of an HTTP header line (offset zero or immediately after \r\n), require an exact case-insensitive field-name match followed by optional whitespace, and preserve the existing value trimming behavior. Otherwise X-Server: or body text can produce incorrect service identification.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
Security Scan Summary
All security checks passed! |
- Require specific Redis RESP prefixes (-ERR, -NOAUTH, -DENIED) instead of matching any response starting with '-' to avoid false positives - Restrict header matching to line boundaries (pos == 0 or after \n) to prevent body text or prefixed headers like X-Server matching as Server
Semgrep Static Analysis
No issues found. |
Security Scan Summary
All security checks passed! |
Summary
server: uvicornwas being missedX-Content-Type-Options: nosniff+404 page not foundbody{"detail":...}response bodyKeep-Alive: timeout=N+Transfer-Encoding: chunked<title>as version info for unidentified HTTP servicesBefore/After (real VPS scan)
Before:
After:
Test plan