Skip to content

Fix SAPDIAG probe: extract SID, hostname and kernel from DIAG port#6

Open
kloris wants to merge 1 commit into
gelim:masterfrom
kloris:fix-sapdiag-sid-extraction
Open

Fix SAPDIAG probe: extract SID, hostname and kernel from DIAG port#6
kloris wants to merge 1 commit into
gelim:masterfrom
kloris:fix-sapdiag-sid-extraction

Conversation

@kloris
Copy link
Copy Markdown

@kloris kloris commented Mar 30, 2026

Summary

  • Fix broken softmatch regex on the SAPDIAG probe — the header anchor pattern \x00\x00\x11 does not appear in actual SAP Dispatcher responses (actual: \x00\x00 NI header), so SID/hostname/kernel were never extracted
  • Promote to match (definitive service identification) and rename "DB name" → "SID" for clarity
  • Add fallback match rules for login screens without kernel version, and for DIAG error responses that leak SID in the error text

Problem

The existing SAPDIAG probe successfully sends a TERM_INI packet and receives the full login screen (~4KB) containing ST_R3INFO items with SID, hostname, and kernel version. However, the softmatch regex never fires because it expects \x00\x00\x11 at byte offset 4, while the actual response has \x00\x00\x00 (plain NI header with no DP header in the response).

As a result, nmap falls through to the SAPDISP probe which only reports:

3201/tcp open  sapdisp  SAP ABAP Dispatcher

...with no SID, hostname, or version information.

After this fix

3201/tcp open  sapdiag  SAP ABAP Dispatcher kernel 7930, patch level 100, database release 758 (SID S4D)
Service Info: Host: srv03s4d1

Match rules added

# When Extracts
1 Full login screen with kernel version SID, hostname, kernel, patch level, DB release
2 Login screen without \x10\x06\x29 item SID, hostname
3 DIAG error response ("location <host>_<SID>_<NR>") SID, instance number, hostname

Test plan

  • Tested with nmap 7.91 against SAP S/4HANA (kernel 793) on port 3201
  • Verified regex matches against real response data (4230 bytes login screen)
  • Verified error response match against simulated error data
  • Verified SAPDISP fallback probe still works for basic detection

🤖 Generated with Claude Code

…2XX)

The existing SAPDIAG softmatch regex never matched because the header
anchor pattern (\x00\x00\x11) does not appear in actual SAP Dispatcher
responses. The response starts with a plain NI header (\x00\x00..),
followed directly by DIAG items — no \x11 byte at offset 4.

This was confirmed against SAP S/4HANA (kernel 793) where the probe
successfully returns the full login screen (~4KB), but the softmatch
silently fails and nmap falls through to the SAPDISP probe which only
reports "SAP ABAP Dispatcher" without SID, hostname, or version info.

Changes:
- Fix header anchor to match actual NI response format (^\x00\x00.{2})
- Promote softmatch to match (this is a definitive service identification)
- Rename "DB name" to "SID" in the info string for clarity
- Add fallback match for login screens without kernel version item
- Add match for DIAG error responses that leak SID in the error text
  ("invalid gui connect data (location <host>_<SID>_<inst>-<wp>)")
- Add comments documenting the probe and ST_R3INFO item structure

Tested with nmap 7.91 against SAP S/4HANA kernel 793 on port 3201:
  3201/tcp open sapdiag SAP ABAP Dispatcher kernel 7930, patch level 100,
                       database release 758 (SID S4D)
  Service Info: Host: srv03s4d1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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