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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/nuclei/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ on extensive configurability, massive extensibility and ease of use.`)
flagSet.StringVarP(&options.TargetsFilePath, "list", "l", "", "path to file containing a list of target URLs/hosts to scan (one per line)"),
flagSet.StringSliceVarP(&options.ExcludeTargets, "exclude-hosts", "eh", nil, "hosts to exclude to scan from the input list (ip, cidr, hostname)", goflags.FileCommaSeparatedStringSliceOptions),
flagSet.StringVar(&options.Resume, "resume", "", "resume scan using resume.cfg (clustering will be disabled)"),
flagSet.BoolVarP(&options.SpecifyIP, "specify-ip", "ip", false, "scan the specified IP address (items provided as IP,URL)"),
flagSet.BoolVarP(&options.ScanAllIPs, "scan-all-ips", "sa", false, "scan all the IP's associated with dns record"),
flagSet.StringSliceVarP(&options.IPVersion, "ip-version", "iv", nil, "IP version to scan of hostname (4,6) - (default 4)", goflags.CommaSeparatedStringSliceOptions),
)
Expand Down
25 changes: 25 additions & 0 deletions pkg/input/provider/list/hmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func New(opts *Options) (*ListInputProvider, error) {
input := &ListInputProvider{
hostMap: hm,
ipOptions: &ipOptions{
SpecifyIP: options.SpecifyIP,
ScanAllIPs: options.ScanAllIPs,
IPV4: sliceutil.Contains(options.IPVersion, "4"),
IPV6: sliceutil.Contains(options.IPVersion, "6"),
Expand Down Expand Up @@ -140,6 +141,18 @@ func (i *ListInputProvider) Iterate(callback func(value *contextargs.MetaInput)

// Set normalizes and stores passed input values
func (i *ListInputProvider) Set(value string) {
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.setItem(metaInput)
return
}
// if no comma, let's process the URL normally
}
p-l- marked this conversation as resolved.
Show resolved Hide resolved

URL := strings.TrimSpace(value)
if URL == "" {
return
Expand Down Expand Up @@ -372,6 +385,18 @@ func (i *ListInputProvider) isExcluded(URL string) bool {
}

func (i *ListInputProvider) Del(value string) {
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
}
Comment on lines +388 to +398
Copy link
Contributor

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.


URL := strings.TrimSpace(value)
if URL == "" {
return
Expand Down
1 change: 1 addition & 0 deletions pkg/input/provider/list/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package list

type ipOptions struct {
SpecifyIP bool
ScanAllIPs bool
IPV4 bool
IPV6 bool
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ type Options struct {
UncoverLimit int
// Uncover search delay
UncoverRateLimit int
// Provide IP address with the URL, as IP,URL
SpecifyIP bool
// ScanAllIPs associated to a dns record
ScanAllIPs bool
// IPVersion to scan (4,6)
Expand Down
Loading