Skip to content

fix(network): record decoded bytes for debug dump - #7478

Merged
dwisiswant0 merged 1 commit into
projectdiscovery:devfrom
snicket2100:network-debug-hex-dump
Jun 21, 2026
Merged

fix(network): record decoded bytes for debug dump#7478
dwisiswant0 merged 1 commit into
projectdiscovery:devfrom
snicket2100:network-debug-hex-dump

Conversation

@snicket2100

@snicket2100 snicket2100 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #7477.

Proposed changes

Move the reqBuilder.Write(dataInBytes) call after the hex decode so the logged bytes match what is actually written to the connection.

Proof

Using the "Steps to reproduce" from #7477:

Before:


                     __     _
   ____  __  _______/ /__  (_)
  / __ \/ / / / ___/ / _ \/ /
 / / / / /_/ / /__/ /  __/ /
/_/ /_/\__,_/\___/_/\___/_/   v3.8.0

		projectdiscovery.io

[INF] Current nuclei version: v3.8.0 (outdated)
[INF] Current nuclei-templates version: v10.4.4 (latest)
[WRN] Scan results upload to cloud is disabled.
[INF] New templates added in latest release: 179
[INF] Templates loaded for current scan: 1
[INF] Executing 1 signed templates from projectdiscovery/nuclei-templates
[INF] Targets loaded for current scan: 1
[INF] [mikrotik-routeros-api] Dumped Network request for 127.0.0.1:1234
00000000  33 61 30 30 30 30 30 30  32 66 30 30 30 30 30 30  |3a0000002f000000|
00000010  30 32 30 30 30 30 34 30  30 32 30 66 30 30 30 31  |02000040020f0001|
00000020  30 30 33 64 30 35 30 30  30 30 30 30 30 30 30 30  |003d050000000000|
00000030  30 30 30 30 30 30 30 30  30 30 30 30 30 30 32 66  |000000000000002f|
00000040  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
00000050  30 30 34 30 31 66 30 30  30 30 30 30 30 30 30 30  |00401f0000000000|
00000060  30 30 30 30 30 30 30 30  30 30 30 30 30 30 30 30  |0000000000000000|
00000070  30 30 30 30 30 30 30 30                           |00000000| address=127.0.0.1:1234

With this fix in place:


                     __     _
   ____  __  _______/ /__  (_)
  / __ \/ / / / ___/ / _ \/ /
 / / / / /_/ / /__/ /  __/ /
/_/ /_/\__,_/\___/_/\___/_/   v3.9.0

		projectdiscovery.io

[INF] Current nuclei version: v3.9.0 (latest)
[INF] Current nuclei-templates version: v10.4.4 (latest)
[WRN] Scan results upload to cloud is disabled.
[INF] New templates added in latest release: 179
[INF] Templates loaded for current scan: 1
[INF] Executing 1 signed templates from projectdiscovery/nuclei-templates
[INF] Targets loaded for current scan: 1
[INF] [mikrotik-routeros-api] Dumped Network request for 127.0.0.1:1234
00000000  3a 00 00 00 2f 00 00 00  02 00 00 40 02 0f 00 01  |:.../......@....|
00000010  00 3d 05 00 00 00 00 00  00 00 00 00 00 00 00 2f  |.=............./|
00000020  00 00 00 00 00 00 00 00  00 40 1f 00 00 00 00 00  |.........@......|
00000030  00 00 00 00 00 00 00 00  00 00 00 00              |............| address=127.0.0.1:1234

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Bug Fixes
    • Fixed incorrect representation of hex-encoded network requests in output logging to accurately reflect the actual bytes sent over TCP connections.

Move the `reqBuilder.Write(dataInBytes)` call after the hex decode so
the logged bytes match what is actually written to the connection.
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

In executeRequestWithPayloads, the reqBuilder.Write call is moved from before the unresolved-variable check and optional hex decoding to after the hex-decode step, so reqBuilder now holds the decoded bytes actually written to the TCP connection rather than the raw hex string bytes.

Changes

Fix hex-type debug request output

Layer / File(s) Summary
Move reqBuilder write to post-hex-decode position
pkg/protocols/network/request.go
Removes the early reqBuilder.Write before unresolved-variable checking, then adds reqBuilder.Write(dataInBytes) after the hex-decode path so the DSL event request field contains the actual decoded bytes sent over the connection for type: hex inputs.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 A hex string sneaked into the debug log,
Pretending to be bytes — what a fog!
I hopped the write past the decode gate,
Now the real bytes arrive — no longer late.
The wire speaks truth, no more ASCII charade! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The code change relocates the reqBuilder.Write() call to after hex decoding, ensuring debug output displays actual decoded bytes instead of ASCII hex representation, directly addressing issue #7477.
Out of Scope Changes check ✅ Passed The changes are limited to reordering code in executeRequestWithPayloads to fix the specific debug output bug; no extraneous modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title directly relates to the main change: moving the request payload append operation after hex-decoding to ensure debug output records the actual decoded bytes sent over the network connection.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@daviediao-code

Copy link
Copy Markdown

Reviewed this PR.

Assessment: Implementation looks solid and follows project conventions. Clean code quality.

Approved ✅

@dwisiswant0 dwisiswant0 changed the title fix: record decoded bytes for debug dump fix(network): record decoded bytes for debug dump Jun 20, 2026
@dwisiswant0
dwisiswant0 merged commit a86c4fa into projectdiscovery:dev Jun 21, 2026
29 of 30 checks passed
@snicket2100
snicket2100 deleted the network-debug-hex-dump branch June 21, 2026 17:17
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.

[BUG] for inputs type: hex the -debug flag does not print correct request bytes

3 participants