Skip to content

Commit

Permalink
add LoadTargetsFromList
Browse files Browse the repository at this point in the history
  • Loading branch information
Bio B committed Jul 6, 2024
1 parent 74e305e commit 28a878f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Explorer1092/nuclei/v3/pkg/catalog/loader"
"github.com/Explorer1092/nuclei/v3/pkg/core"
"github.com/Explorer1092/nuclei/v3/pkg/input/provider"
"github.com/Explorer1092/nuclei/v3/pkg/input/provider/list"
providerTypes "github.com/Explorer1092/nuclei/v3/pkg/input/types"
"github.com/Explorer1092/nuclei/v3/pkg/loader/workflow"
"github.com/Explorer1092/nuclei/v3/pkg/output"
Expand Down Expand Up @@ -111,7 +112,7 @@ func (e *NucleiEngine) GetTemplates() []*templates.Template {
return e.store.Templates()
}

// LoadTargets(urls/domains/ips only) adds targets to the nuclei engine
// LoadTargets LoadTargets(urls/domains/ips only) adds targets to the nuclei engine
func (e *NucleiEngine) LoadTargets(targets []string, probeNonHttp bool) {
for _, target := range targets {
if probeNonHttp {
Expand All @@ -122,6 +123,30 @@ func (e *NucleiEngine) LoadTargets(targets []string, probeNonHttp bool) {
}
}

// LoadTargetsFromList LoadTargetsFromList(urls/domains/ips only) adds targets to the nuclei engine
func (e *NucleiEngine) LoadTargetsFromList(targets []string, probeNonHttp bool) {
e.opts.InputFileMode = "list"
listProvider, _ := list.New(&list.Options{
Options: e.opts,
NotFoundCallback: nil,
})
e.inputProvider = listProvider
//if err != nil {
// e.opts.TargetsFilePath = ""
// e.opts.InputFileMode = ""
// return err
//}
//e.inputProvider = httpProvider
for _, target := range targets {
if probeNonHttp {
_ = e.inputProvider.SetWithProbe(target, e.httpxClient)
} else {

e.inputProvider.Set(target)
}
}
}

// LoadTargetsFromReader adds targets(urls/domains/ips only) from reader to the nuclei engine
func (e *NucleiEngine) LoadTargetsFromReader(reader io.Reader, probeNonHttp bool) {
buff := bufio.NewScanner(reader)
Expand Down
9 changes: 9 additions & 0 deletions pkg/input/provider/list/hmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ func (i *ListInputProvider) Del(value string) {
if URL == "" {
return
}

if stringsutil.ContainsAny(value, ",") {
idxComma := strings.Index(value, ",")
metaInput := &contextargs.MetaInput{Input: value[idxComma+1:], CustomIP: value[:idxComma]}
i.delItem(metaInput)
return
}

// parse hostname if url is given
urlx, err := urlutil.Parse(URL)
if err != nil || (urlx != nil && urlx.Host == "") {
Expand Down Expand Up @@ -477,6 +485,7 @@ func (i *ListInputProvider) setItem(metaInput *contextargs.MetaInput) {
// setItem in the kv store
func (i *ListInputProvider) delItem(metaInput *contextargs.MetaInput) {
targetUrl, err := urlutil.ParseURL(metaInput.Input, true)

if err != nil {
gologger.Warning().Msgf("%s\n", err)
return
Expand Down

0 comments on commit 28a878f

Please sign in to comment.