Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add -specify-ip option to allow for specified CustomIP values #5898

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

p-l-
Copy link
Contributor

@p-l- p-l- commented Dec 10, 2024

Proposed changes

This PR adds a -specify-ip which changes the expected target formet to <IP address>,<URL>.

It makes it easier to scan one host with a given hostname, that could be either non-resolvable / internal, or that could resolve to a reverse-proxy or WAF and we have found the origin.

The format is compatible with zgrab2.

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

  • New Features

    • Introduced a new command-line flag to specify IP addresses for scanning, enhancing target specification flexibility.
    • Updated input handling to allow custom IP alongside URL in specified formats.
  • Bug Fixes

    • Improved error handling and logging for IP and URL parsing.
  • Documentation

    • Enhanced comments and documentation for clarity on the new flag and its usage.

Copy link

coderabbitai bot commented Dec 10, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce a new boolean flag SpecifyIP across multiple files, enhancing the command-line options for specifying an IP address during scanning operations. This flag is integrated into the readConfig function, the ListInputProvider class, and the Options struct, allowing users to provide an IP alongside a URL. The implementation includes updates to methods for handling input and error logging, ensuring that the new functionality is properly managed. Documentation and comments have been updated for clarity, while the overall structure and flow of the application remain unchanged.

Changes

File Path Change Summary
cmd/nuclei/main.go Added SpecifyIP flag to command-line options in readConfig function.
pkg/input/provider/list/hmap.go Updated ipOptions struct to include SpecifyIP. Modified Set and Del methods to handle custom IP logic. Enhanced error handling for URL parsing.
pkg/input/provider/list/utils.go Added SpecifyIP field to ipOptions struct.
pkg/types/types.go Introduced SpecifyIP field in Options struct with updated comments.

Poem

In the meadow where bunnies hop,
A flag for IPs, we now can swap.
With URLs and numbers, we dance with glee,
Scanning the fields, oh so carefree!
Hooray for the changes, let’s celebrate,
With hops and twirls, we can’t be late! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

@p-l-
Copy link
Contributor Author

p-l- commented Dec 11, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Dec 11, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
pkg/input/provider/list/hmap.go (1)

153-153: Improve the comment for clarity.

The current comment could be more descriptive about the fallback behavior.

-    // if no comma, let's process the URL normally
+    // If no comma is found in the input, process the entire string as a URL without custom IP specification
pkg/types/types.go (1)

320-321: Enhance field documentation.

The comment could be more detailed about the expected format and provide an example.

-    // Provide IP address with the URL, as IP,URL
+    // SpecifyIP enables providing a custom IP address with the URL in the format "IP,URL".
+    // Example: "192.168.1.1,example.com" will scan example.com using 192.168.1.1
cmd/nuclei/main.go (1)

239-239: LGTM! Consider enhancing the flag documentation.

The new -specify-ip flag is well-integrated into the input options group. However, the description could be more detailed to help users understand:

  • The specific use cases (e.g., scanning through reverse proxies, WAFs)
  • Examples of valid input formats
  • Interaction with other input methods (list, stdin)

Consider updating the flag description to be more comprehensive:

-flagSet.BoolVarP(&options.SpecifyIP, "specify-ip", "ip", false, "scan the specified IP address (items provided as IP,URL)")
+flagSet.BoolVarP(&options.SpecifyIP, "specify-ip", "ip", false, "scan the specified IP address (format: IP,URL). Useful for scanning through reverse proxies/WAFs or when target resolution is not desired")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c731126 and 38d2869.

📒 Files selected for processing (4)
  • cmd/nuclei/main.go (1 hunks)
  • pkg/input/provider/list/hmap.go (3 hunks)
  • pkg/input/provider/list/utils.go (1 hunks)
  • pkg/types/types.go (1 hunks)
🔇 Additional comments (2)
pkg/input/provider/list/utils.go (1)

4-4: LGTM!

The addition of the SpecifyIP field to the ipOptions struct is clean and well-aligned with the existing boolean fields.

cmd/nuclei/main.go (1)

239-241: Verify interaction with other IP-related flags.

The new -specify-ip flag is added alongside other IP-related flags. Please ensure proper interaction between these flags.

✅ Verification successful

Let me analyze the interactions between these IP-related flags based on the code snippets found.

The search results show clear handling of these flags in the codebase:

  1. In pkg/input/provider/list/hmap.go, the flags are used in a mutually compatible way:

    • SpecifyIP handles custom IP,URL pairs with proper parsing
    • ScanAllIPs performs DNS lookups to get all associated IPs
    • IPVersion is used to filter IPs (4/6) during processing
  2. In internal/runner/options.go, there's proper default handling for IP versions where IPv4 is the default if none specified.

Let me verify one more aspect to ensure there are no conflicting conditions between these flags.


Let me try one more search to specifically look for any validation logic between these flags.


Based on the code analysis, I can now provide a final response:

The IP-related flags are properly implemented with compatible interactions

The codebase shows well-structured handling of these flags:

  • SpecifyIP and ScanAllIPs are processed independently in separate code blocks
  • IPVersion works as a filter on top of either flag's behavior
  • Default IPv4 is properly set when no IP version is specified
  • No conflicting validation rules or mutually exclusive conditions were found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential conflicts or interactions between IP-related flags
# Test: Search for IP-related flag handling logic
rg -A 5 "SpecifyIP|ScanAllIPs|IPVersion" --type go

Length of output: 5023


Script:

#!/bin/bash
# Check for any validation or conflict checks between these flags
ast-grep --pattern 'if $_ && $_.$_ {
  $$$
}'

Length of output: 47


Script:

#!/bin/bash
# Look for validation logic in runner or options initialization
rg -A 5 "func.*[Vv]alidate.*Options|func.*[Cc]heck.*Options" --type go

Length of output: 2307

Comment on lines +388 to +398
if i.ipOptions.SpecifyIP {
valueParsed := strings.SplitN(value, ",", 2)
if len(valueParsed) == 2 {
metaInput := contextargs.NewMetaInput()
metaInput.Input = strings.TrimSpace(valueParsed[1])
metaInput.CustomIP = strings.TrimSpace(valueParsed[0])
i.delItem(metaInput)
return
}
// if no comma, let's process the URL normally
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add IP address validation.

The code should validate that the specified IP address is in a valid format before using it.

Example implementation:

+func isValidIP(ip string) bool {
+    return net.ParseIP(ip) != nil
+}

 if i.ipOptions.SpecifyIP {
     valueParsed := strings.SplitN(value, ",", 2)
     if len(valueParsed) == 2 {
+        ip := strings.TrimSpace(valueParsed[0])
+        if !isValidIP(ip) {
+            gologger.Warning().Msgf("Invalid IP address specified: %s", ip)
+            return
+        }
         metaInput := contextargs.NewMetaInput()
         metaInput.Input = strings.TrimSpace(valueParsed[1])
-        metaInput.CustomIP = strings.TrimSpace(valueParsed[0])
+        metaInput.CustomIP = ip
         i.delItem(metaInput)
         return
     }

Committable suggestion skipped: line range outside the PR's diff.

pkg/input/provider/list/hmap.go Show resolved Hide resolved
@GeorginaReeder
Copy link

Thanks for your contribution @p-l- ! :)

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.

3 participants