//go:build !race1// +build !race23package nuclei_test45import (6"os"7"testing"89"github.com/kitabisa/go-ci"10nuclei "github.com/projectdiscovery/nuclei/v3/lib"11"github.com/remeh/sizedwaitgroup"12)1314// A very simple example on how to use nuclei engine15func ExampleNucleiEngine() {16// create nuclei engine with options17ne, err := nuclei.NewNucleiEngine(18nuclei.WithTemplateFilters(nuclei.TemplateFilters{IDs: []string{"self-signed-ssl"}}), // only run self-signed-ssl template19)20if err != nil {21panic(err)22}23// load targets and optionally probe non http/https targets24ne.LoadTargets([]string{"scanme.sh"}, false)25// when callback is nil it nuclei will print JSON output to stdout26err = ne.ExecuteWithCallback(nil)27if err != nil {28panic(err)29}30defer ne.Close()3132// Output:33// [self-signed-ssl] scanme.sh:44334}3536func ExampleThreadSafeNucleiEngine() {37// create nuclei engine with options38ne, err := nuclei.NewThreadSafeNucleiEngine()39if err != nil {40panic(err)41}42// setup sizedWaitgroup to handle concurrency43// here we are using sizedWaitgroup to limit concurrency to 144// but can be anything in general45sg := sizedwaitgroup.New(1)4647// scan 1 = run dns templates on scanme.sh48sg.Add()49go func() {50defer sg.Done()51err = ne.ExecuteNucleiWithOpts([]string{"scanme.sh"},52nuclei.WithTemplateFilters(nuclei.TemplateFilters{IDs: []string{"nameserver-fingerprint"}}), // only run self-signed-ssl template53)54if err != nil {55panic(err)56}57}()5859// scan 2 = run dns templates on honey.scanme.sh60sg.Add()61go func() {62defer sg.Done()63err = ne.ExecuteNucleiWithOpts([]string{"honey.scanme.sh"}, nuclei.WithTemplateFilters(nuclei.TemplateFilters{ProtocolTypes: "dns"}))64if err != nil {65panic(err)66}67}()6869// wait for all scans to finish70sg.Wait()71defer ne.Close()7273// Output:74// [nameserver-fingerprint] scanme.sh75// [caa-fingerprint] honey.scanme.sh76}7778func TestMain(m *testing.M) {79// this file only contains testtables examples https://go.dev/blog/examples80// and actual functionality test are in sdk_test.go81if ci.IsCI() {82// no need to run this test on github actions83return84}8586os.Exit(m.Run())87}888990