Adding support for udp payload#1051
Conversation
|
Thanks for your contribution @jesusprubio ! We also have a Discord server, which you’re more than welcome to join. It's a great place to connect with fellow contributors and stay updated with the latest developments! |
WalkthroughAdds a new connect payload option and CLI flag, threads it through runner logic, updates Scanner.ConnectPort to accept and write the payload (notably for UDP), and enforces validation that a connect payload is only allowed for connect scans. Tests and README updated accordingly. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant CLI as CLI
participant Runner as Runner
participant Scanner as Scanner
participant Net as Network Socket
CLI->>Runner: Parse args (includes --connect-payload)
Runner->>Runner: store options.ConnectPayload
Runner->>Scanner: ConnectPort(host, payload, port, timeout)
alt UDP connect scan
Scanner->>Net: Dial UDP
Note right of Scanner #D6F5D6: New — write provided payload to socket
Scanner->>Net: Write(payload)
Net-->>Scanner: Response / Timeout
else TCP connect scan
Scanner->>Net: Dial TCP
Note right of Scanner #F0F0F0: No payload write for TCP in diff
end
Scanner-->>Runner: (open, err)
Runner-->>CLI: Report result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🪛 markdownlint-cli2 (0.18.1)README.md44-44: Unordered list indentation (MD007, ul-indent) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
pkg/runner/options.go (1)
76-76: Consider minor comment refinement.The comment "Payload to use with CONNECT scan types" could be slightly clearer. Consider "Payload to send in CONNECT scans" to match the CLI help text.
- ConnectPayload string // Payload to use with CONNECT scan types + ConnectPayload string // Payload to send in CONNECT scanspkg/runner/validate.go (1)
144-146: Consider validation ordering for better UX.The validation correctly enforces that connect payloads require connect scans. However, the current placement means users might see this error even when the code would automatically fall back to connect scan (e.g., due to routing failure at line 148-151).
Consider moving this validation after all automatic scan-type adjustments, or automatically switching to connect scan when a payload is specified (similar to the proxy handling at lines 139-142).
Current flow:
- Line 139-142: Auto-adjust SynScan → ConnectScan if proxy is used
- Line 144-146: Error if ConnectPayload with non-ConnectScan
- Line 148-151: Auto-adjust SynScan → ConnectScan if routing fails
Potential improvement:
// Move after routing check (line 151) if options.ConnectPayload != "" && options.ScanType != ConnectScan { gologger.Warning().Msgf("Connect payload requires connect scan: falling back to connect scan") options.ScanType = ConnectScan }Or move after all adjustments:
// After line 151 if options.ConnectPayload != "" && options.ScanType != ConnectScan { return errors.New("connect payload can only be used with connect scan") }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
pkg/runner/options.go(2 hunks)pkg/runner/runner.go(6 hunks)pkg/runner/validate.go(3 hunks)pkg/runner/validate_test.go(1 hunks)pkg/scan/scan.go(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
pkg/runner/validate.go (1)
pkg/runner/default.go (1)
ConnectScan(16-16)
pkg/scan/scan.go (1)
pkg/port/port.go (1)
Port(10-17)
pkg/runner/validate_test.go (1)
pkg/runner/default.go (1)
SynScan(15-15)
🔇 Additional comments (4)
pkg/scan/scan.go (1)
389-445: LGTM! UDP payload implementation is correct.The signature change and UDP payload write are implemented correctly:
- The payload parameter is properly added to the method signature
- For UDP, the payload is written to the connection, enabling proper service discovery
- TCP connections remain unchanged (line 444), as they succeed on connect without data
- Empty payloads are handled correctly (empty byte slice)
pkg/runner/runner.go (2)
348-348: LGTM! Payload extraction is efficient.Extracting the payload once and reusing it throughout is the right approach.
836-866: LGTM! Payload propagation is consistent.The
handleHostPortsignature update and payload passing toConnectPortare implemented correctly across all code paths.pkg/runner/validate_test.go (1)
20-24: LGTM! Test coverage for payload validation is appropriate.The test correctly verifies that using ConnectPayload with SynScan results in the expected validation error.
|
@coderabbitai update the linked issue, describing the partial implementation with a global udp payload for all ports |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 493 🏁 Script executed: Length of output: 76 @Mzack9999, I've updated issue #462 with a description of the partial implementation. The comment explains:
You can view the comment here: #462 (comment) |
Add protocol-specific probes for UDP port scanning. Previously, naabu sent empty payloads by default (or required users to specificy via `-cp`) which often failed to elicit responses from UDP services. This adds default payloads for common protocols. A custom payload specified via `-cp` takes priority over embedded probes. References: * projectdiscovery#462 * projectdiscovery#1014 * projectdiscovery#1051
Most UDP services do not reply to empty requests. This PR adds a flag to include the data to write to the connection.
Partial solution to this issue: #462
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation