//go:build !race12package nuclei_test34import (5"os"6"testing"78"github.com/kitabisa/go-ci"9nuclei "github.com/projectdiscovery/nuclei/v3/lib"10"github.com/remeh/sizedwaitgroup"11)1213// A very simple example on how to use nuclei engine14func ExampleNucleiEngine() {15// create nuclei engine with options16ne, err := nuclei.NewNucleiEngine(17nuclei.WithTemplateFilters(nuclei.TemplateFilters{IDs: []string{"self-signed-ssl"}}), // only run self-signed-ssl template18)19if err != nil {20panic(err)21}22// load targets and optionally probe non http/https targets23ne.LoadTargets([]string{"scanme.sh"}, false)24// when callback is nil it nuclei will print JSON output to stdout25err = ne.ExecuteWithCallback(nil)26if err != nil {27panic(err)28}29defer ne.Close()3031// Output:32// [self-signed-ssl] scanme.sh:44333}3435func ExampleThreadSafeNucleiEngine() {36// create nuclei engine with options37ne, err := nuclei.NewThreadSafeNucleiEngine()38if err != nil {39panic(err)40}41// setup sizedWaitgroup to handle concurrency42// here we are using sizedWaitgroup to limit concurrency to 143// but can be anything in general44sg := sizedwaitgroup.New(1)4546// scan 1 = run dns templates on scanme.sh47sg.Add()48go func() {49defer sg.Done()50err = ne.ExecuteNucleiWithOpts([]string{"scanme.sh"},51nuclei.WithTemplateFilters(nuclei.TemplateFilters{IDs: []string{"nameserver-fingerprint"}}), // only run self-signed-ssl template52)53if err != nil {54panic(err)55}56}()5758// scan 2 = run dns templates on honey.scanme.sh59sg.Add()60go func() {61defer sg.Done()62err = ne.ExecuteNucleiWithOpts([]string{"honey.scanme.sh"}, nuclei.WithTemplateFilters(nuclei.TemplateFilters{ProtocolTypes: "dns"}))63if err != nil {64panic(err)65}66}()6768// wait for all scans to finish69sg.Wait()70defer ne.Close()7172// Output:73// [nameserver-fingerprint] scanme.sh74// [caa-fingerprint] honey.scanme.sh75}7677func TestMain(m *testing.M) {78// this file only contains testtables examples https://go.dev/blog/examples79// and actual functionality test are in sdk_test.go80if ci.IsCI() {81// no need to run this test on github actions82return83}8485os.Exit(m.Run())86}878889