2020-06-26 10:23:54 +02:00
|
|
|
package workflows
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/d5/tengo/v2"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/pkg/executor"
|
|
|
|
|
)
|
|
|
|
|
|
2020-06-26 15:10:42 +02:00
|
|
|
// NucleiVar within the scripting engine
|
2020-06-26 10:23:54 +02:00
|
|
|
type NucleiVar struct {
|
|
|
|
|
tengo.ObjectImpl
|
2020-06-26 15:10:42 +02:00
|
|
|
HTTPOptions *executor.HTTPOptions
|
|
|
|
|
DNSOptions *executor.DNSOptions
|
|
|
|
|
URL string
|
2020-06-26 10:23:54 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-26 15:10:42 +02:00
|
|
|
// TypeName of the variable
|
2020-06-26 10:23:54 +02:00
|
|
|
func (n *NucleiVar) TypeName() string {
|
|
|
|
|
return "nuclei-var"
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 15:10:42 +02:00
|
|
|
// CanCall can be called from within the scripting engine
|
2020-06-26 10:23:54 +02:00
|
|
|
func (n *NucleiVar) CanCall() bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 15:10:42 +02:00
|
|
|
// Call logic - actually it doesn't require arguments
|
2020-06-26 10:23:54 +02:00
|
|
|
func (n *NucleiVar) Call(args ...tengo.Object) (ret tengo.Object, err error) {
|
2020-06-26 15:10:42 +02:00
|
|
|
for _, request := range n.HTTPOptions.Template.RequestsHTTP {
|
|
|
|
|
n.HTTPOptions.HTTPRequest = request
|
|
|
|
|
httpExecutor, err := executor.NewHTTPExecutor(n.HTTPOptions)
|
2020-06-26 10:23:54 +02:00
|
|
|
if err != nil {
|
2020-06-26 15:10:42 +02:00
|
|
|
return nil, err
|
2020-06-26 10:23:54 +02:00
|
|
|
}
|
|
|
|
|
err = httpExecutor.ExecuteHTTP(n.URL)
|
|
|
|
|
if err != nil {
|
2020-06-26 15:10:42 +02:00
|
|
|
return nil, err
|
2020-06-26 10:23:54 +02:00
|
|
|
}
|
|
|
|
|
if httpExecutor.GotResults() {
|
|
|
|
|
return tengo.TrueValue, nil
|
|
|
|
|
}
|
|
|
|
|
return tengo.FalseValue, nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 15:10:42 +02:00
|
|
|
for _, request := range n.DNSOptions.Template.RequestsDNS {
|
|
|
|
|
n.DNSOptions.DNSRequest = request
|
|
|
|
|
dnsExecutor := executor.NewDNSExecutor(n.DNSOptions)
|
|
|
|
|
err = dnsExecutor.ExecuteDNS(n.URL)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if dnsExecutor.GotResults() {
|
|
|
|
|
return tengo.TrueValue, nil
|
|
|
|
|
}
|
|
|
|
|
return tengo.FalseValue, nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 10:23:54 +02:00
|
|
|
return nil, nil
|
|
|
|
|
}
|