Skip to content

feat: improve service detection with case-insensitive headers and fingerprinting - #6

Merged
Bulletdev merged 2 commits into
mainfrom
feat/service-detection
Nov 10, 2026
Merged

Bulletdev merged 2 commits into
mainfrom
feat/service-detection

Conversation

@Bulletdev

Copy link
Copy Markdown
Member

Summary

  • Fix case-sensitive HTTP header parsing (RFC violation) - server: uvicorn was being missed
  • Add HTTP response fingerprinting beyond Server header:
    • Go net/http identified by X-Content-Type-Options: nosniff + 404 page not found body
    • FastAPI identified when uvicorn server + {"detail":...} response body
    • uWebSockets identified by its custom header
    • Node.js http identified by Keep-Alive: timeout=N + Transfer-Encoding: chunked
  • Expand Redis port classification from 6379-6380 to 6379-6399 (Docker remapped instances)
  • Generic probe now falls back to Redis/PostgreSQL probes when HTTP detection fails
  • Extract HTML <title> as version info for unidentified HTTP services

Before/After (real VPS scan)

Before:

6382/tcp  open    unknown
8001/tcp  open    HTTP
8002/tcp  open    HTTP
6001/tcp  open    HTTP
80/tcp    open    http

After:

6382/tcp  open    Redis          7.4.8
8001/tcp  open    uvicorn
8002/tcp  open    uvicorn
6001/tcp  open    uWebSockets    20
80/tcp    open    Go net/http

Test plan

  • Scan VPS with 9 known open ports - all correctly identified
  • Redis on non-standard port 6382 detected with version
  • Case-insensitive header parsing works (uvicorn via lowercase server header)
  • HTTP fingerprinting identifies Go net/http and uWebSockets
  • Verify no regression on standard port scans

…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
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@github-actions

Copy link
Copy Markdown

Semgrep Static Analysis

Severity Count
Errors 0
Critical (HIGH confidence) 0
Warnings 0

No issues found.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

⚠️ Resolve issues before merging

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

Comment thread src/banner.zig Outdated
} else {
info.setName(server);
// Response to HTTP wasn't HTTP - check if it looks like Redis error
if (data[0] == '-') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread src/banner.zig Outdated
Comment on lines +703 to +710
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];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@github-actions

Copy link
Copy Markdown

Security Scan Summary

Check Status
Semgrep success
Secret Detection success

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
@Bulletdev Bulletdev self-assigned this Nov 10, 2026
@github-actions

Copy link
Copy Markdown

Semgrep Static Analysis

Severity Count
Errors 0
Critical (HIGH confidence) 0
Warnings 0

No issues found.

@github-actions

Copy link
Copy Markdown

Security Scan Summary

Check Status
Semgrep success
Secret Detection success

All security checks passed!

@Bulletdev
Bulletdev merged commit 759632b into main Nov 10, 2026
10 checks passed
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