Skip to content

fix(scan): resolve hanging when provides source-ip with SYN scan#1421

Merged
Mzack9999 merged 1 commit intodevfrom
dwisiswant0/fix/scan/resolve-hanging-when-provides-source-ip-with-SYN-scan
Mar 31, 2025
Merged

fix(scan): resolve hanging when provides source-ip with SYN scan#1421
Mzack9999 merged 1 commit intodevfrom
dwisiswant0/fix/scan/resolve-hanging-when-provides-source-ip-with-SYN-scan

Conversation

@dwisiswant0
Copy link
Copy Markdown
Member

@dwisiswant0 dwisiswant0 commented Mar 13, 2025

The SYN scan in combination with a specified
source IP would cause to hang indefinitely. This
issue occurred when attempting to create an
ethernet frame w/o proper validation of available
HW addresses.

fixes #1408

Summary by CodeRabbit

  • Bug Fixes
    • Improved TCP packet transmission by refining how network source details are verified, which enhances overall connection stability and error handling in varying network configurations.

with SYN scan

The SYN scan in combination with a specified
source IP would cause to hang indefinitely. This
issue occurred when attempting to create an
ethernet frame w/o proper validation of available
HW addresses.

Signed-off-by: Dwi Siswanto <git@dw1.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 13, 2025

Walkthrough

The update revises the sendAsyncTCP4 function in the UNIX scan package. It introduces stricter checks for determining how to send TCP packets based on the availability of a source IP and a hardware (MAC) address. The function now distinguishes between cases when both are available, only the source IP is available, or neither is present, applying appropriate fallback mechanisms and ensuring valid interface usage for Ethernet framing.

Changes

File Change Summary
pkg/scan/scan_unix.go Updated sendAsyncTCP4: now checks that both source IP and hardware address are provided for Ethernet framing; if only IP is available, it sets the IP explicitly; falls back to routing when neither is available, and validates the network interface before sending.

Sequence Diagram(s)

sequenceDiagram
    participant Function as sendAsyncTCP4
    participant Handler as listenHandler
    participant Router as Routing Module
    participant Interface as Network Interface

    Function->>Handler: Check if hasSourceIp and SourceHW exist
    alt Both Source IP & HW available
        Function->>Function: Prepare Ethernet framing
        Function->>Interface: Validate interface (iface not nil)
        Function->>Interface: Send packet with Ethernet framing
    else Only Source IP available
        Function->>Handler: Set source IP to SourceIp4 for raw socket
        Function->>Interface: Send packet using raw socket
    else Neither available
        Function->>Router: Route destination IP to determine source IP
        Router-->>Function: Return valid source IP or error
        Function->>Interface: Send packet using raw socket (if valid)
    end
Loading

Poem

I'm a hopping rabbit with joyful glee,
Watching packets dance so gracefully.
With IP and MAC in a perfect embrace,
My code leaps forward at a rapid pace.
Each byte and frame sings a cheerful tune,
Under the stars and the bright code moon.
🐇✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8838e2 and f112144.

📒 Files selected for processing (1)
  • pkg/scan/scan_unix.go (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: build-windows
  • GitHub Check: release-test-windows
  • GitHub Check: build-mac
  • GitHub Check: build-linux
  • GitHub Check: release-test-mac
  • GitHub Check: Functional Test (ubuntu-latest)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
pkg/scan/scan_unix.go (3)

185-188: Enhanced condition check for ethernet framing

The fix properly requires both source IP and hardware address to be present before attempting to use ethernet framing. This prevents the scan from hanging when only a source IP is provided without a valid hardware address.


207-221: Improved fallback mechanism for handling partial networking information

The code now correctly handles three distinct cases:

  1. When both source IP and hardware address are available (uses ethernet framing)
  2. When only source IP is available (uses raw socket)
  3. When neither is available (routes the destination IP to find a valid source IP)

This is a robust approach that ensures the scan continues in all scenarios rather than hanging.


249-249: Fixed the final condition check for sending packets

The condition now properly verifies that all three requirements are met before attempting to send with an ethernet handler: source IP is present, hardware address is available, and the interface is valid.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dwisiswant0 dwisiswant0 changed the title fix(scan): resolve hanging when provides source-ip fix(scan): resolve hanging when provides source-ip with SYN scan Mar 13, 2025
@dogancanbakir dogancanbakir requested a review from Mzack9999 March 28, 2025 13:55
@Mzack9999 Mzack9999 merged commit 121b5a4 into dev Mar 31, 2025
12 checks passed
@Mzack9999 Mzack9999 deleted the dwisiswant0/fix/scan/resolve-hanging-when-provides-source-ip-with-SYN-scan branch March 31, 2025 18:43
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.

Naabu does not scan when both -scan-type and -source-ip flag is present

3 participants