Skip to content

Commit

Permalink
Merge pull request #884 from TheSecEng/impl/targets/targets_to_target…
Browse files Browse the repository at this point in the history
…file

implement `TargetsFile` and change logic of `Targets`
  • Loading branch information
forgedhallpass committed Aug 4, 2021
2 parents f516136 + 68ab370 commit ef7591d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Usage:

Flags:
TARGET:
-u, -target string target URL/host to scan
-u, -target string[] target URLs/hosts to scan
-l, -list string path to file containing a list of target URLs/hosts to scan (one per line)

TEMPLATES:
Expand Down
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ nuclei -h
|burp-collaborator-biid|使用burp-collaborator插件|nuclei -burp-collaborator-biid XXXX|
|c|并行的最大模板数量(默认10)|nuclei -c 10|
|l|对URL列表进行测试|nuclei -l urls.txt|
|target|对目标进行测试|nuclei -target hxxps://example.com|
|target|对目标进行测试|nuclei -target hxxps://example.com -target hxxps://example2.com|
|t|要检测的模板种类|nuclei -t git-core.yaml -t cves/|
|no-color|输出不显示颜色|nuclei -no-color|
|no-meta|不显示匹配的元数据|nuclei -no-meta|
Expand Down Expand Up @@ -250,4 +250,4 @@ nano ~/nuclei-templates/.nuclei-ignore

--------

Nuclei是由[projectdiscovery](https://projectdiscovery.io)团队用🖤制作的,当然社区也贡献了很多,通过 **[Thanks.md](https://github.com/projectdiscovery/nuclei/blob/master/THANKS.md)**文件以获取更多详细信息。
Nuclei是由[projectdiscovery](https://projectdiscovery.io)团队用🖤制作的,当然社区也贡献了很多,通过 **[Thanks.md](https://github.com/projectdiscovery/nuclei/blob/master/THANKS.md)**文件以获取更多详细信息。
4 changes: 2 additions & 2 deletions v2/cmd/nuclei/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func readConfig() {
on extensive configurability, massive extensibility and ease of use.`)

createGroup(flagSet, "input", "Target",
flagSet.StringVarP(&options.Target, "target", "u", "", "target URL/host to scan"),
flagSet.StringVarP(&options.Targets, "list", "l", "", "path to file containing a list of target URLs/hosts to scan (one per line)"),
flagSet.StringSliceVarP(&options.Targets, "target", "u", []string{}, "target URLs/hosts to scan"),
flagSet.StringVarP(&options.TargetsFilePath, "list", "l", "", "path to file containing a list of target URLs/hosts to scan (one per line)"),
)

createGroup(flagSet, "templates", "Templates",
Expand Down
32 changes: 23 additions & 9 deletions v2/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func New(options *types.Options) (*Runner, error) {
os.Exit(0)
}

if (len(options.Templates) == 0 || !options.NewTemplates || (options.Targets == "" && !options.Stdin && options.Target == "")) && options.UpdateTemplates {
if (len(options.Templates) == 0 || !options.NewTemplates || (options.TargetsFilePath == "" && !options.Stdin && len(options.Targets) == 0)) && options.UpdateTemplates {
os.Exit(0)
}
hm, err := hybrid.New(hybrid.DefaultDiskOptions)
Expand All @@ -137,11 +137,23 @@ func New(options *types.Options) (*Runner, error) {
runner.inputCount = 0
dupeCount := 0

// Handle single target
if options.Target != "" {
runner.inputCount++
// nolint:errcheck // ignoring error
runner.hostMap.Set(options.Target, nil)
// Handle multiple target
if len(options.Targets) != 0 {
for _, target := range options.Targets {
url := strings.TrimSpace(target)
if url == "" {
continue
}

if _, ok := runner.hostMap.Get(url); ok {
dupeCount++
continue
}

runner.inputCount++
// nolint:errcheck // ignoring error
runner.hostMap.Set(url, nil)
}
}

// Handle stdin
Expand All @@ -152,19 +164,21 @@ func New(options *types.Options) (*Runner, error) {
if url == "" {
continue
}

if _, ok := runner.hostMap.Get(url); ok {
dupeCount++
continue
}

runner.inputCount++
// nolint:errcheck // ignoring error
runner.hostMap.Set(url, nil)
}
}

// Handle taget file
if options.Targets != "" {
input, inputErr := os.Open(options.Targets)
// Handle target file
if options.TargetsFilePath != "" {
input, inputErr := os.Open(options.TargetsFilePath)
if inputErr != nil {
return nil, errors.Wrap(inputErr, "could not open targets file")
}
Expand Down
4 changes: 2 additions & 2 deletions v2/internal/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ var DefaultOptions = &types.Options{
RateLimit: 150,
ProjectPath: "",
Severity: []string{},
Target: "",
Targets: "",
Targets: []string{},
TargetsFilePath: "",
Output: "",
ProxyURL: "",
ProxySocksURL: "",
Expand Down
8 changes: 4 additions & 4 deletions v2/pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ type Options struct {
ProjectPath string
// InteractshURL is the URL for the interactsh server.
InteractshURL string
// Target is a single URL/Domain to scan using a template
Target string
// Targets specifies the targets to scan using templates.
Targets string
// Target URLs/Domains to scan using a template
Targets goflags.StringSlice
// TargetsFilePath specifies the targets from a file to scan using templates.
TargetsFilePath string
// Output is the file to write found results to.
Output string
// ProxyURL is the URL for the proxy server
Expand Down

0 comments on commit ef7591d

Please sign in to comment.