nuclei/v2/pkg/templates/compile.go

40 lines
742 B
Go
Raw Normal View History

2020-04-04 02:50:32 +05:30
package templates
import (
"fmt"
2020-04-04 02:50:32 +05:30
"os"
"gopkg.in/yaml.v2"
)
2020-06-29 17:43:08 +05:30
// Parse parses a yaml request template file
func Parse(file string) (*Template, error) {
2020-04-04 02:50:32 +05:30
template := &Template{}
f, err := os.Open(file)
if err != nil {
return nil, err
}
err = yaml.NewDecoder(f).Decode(template)
if err != nil {
return nil, err
}
2020-06-26 14:37:55 +02:00
defer f.Close()
2020-07-31 17:13:51 +02:00
template.path = file
2020-06-29 17:43:08 +05:30
// If no requests, and it is also not a workflow, return error.
2020-07-18 21:42:23 +02:00
if len(template.BulkRequestsHTTP)+len(template.RequestsDNS) <= 0 {
return nil, fmt.Errorf("no requests defined for %s", template.ID)
2020-06-26 14:37:55 +02:00
}
2020-04-04 02:50:32 +05:30
2020-04-22 22:45:02 +02:00
// Compile the matchers and the extractors for http requests
2020-07-18 21:42:23 +02:00
for _, request := range template.BulkRequestsHTTP {
2020-07-24 18:12:16 +02:00
request.InitGenerator()
2020-04-04 02:50:32 +05:30
}
2020-04-22 22:45:02 +02:00
2020-04-04 02:50:32 +05:30
return template, nil
}