mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 20:15:27 +00:00
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
|
|
package installer
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bufio"
|
||
|
|
"bytes"
|
||
|
|
"fmt"
|
||
|
|
"io"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"github.com/Masterminds/semver/v3"
|
||
|
|
"github.com/projectdiscovery/gologger"
|
||
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
|
||
|
|
errorutil "github.com/projectdiscovery/utils/errors"
|
||
|
|
)
|
||
|
|
|
||
|
|
// GetNewTemplatesInVersions returns templates path of all newly added templates
|
||
|
|
// in these versions
|
||
|
|
func GetNewTemplatesInVersions(versions ...string) []string {
|
||
|
|
allTemplates := []string{}
|
||
|
|
for _, v := range versions {
|
||
|
|
if v == config.DefaultConfig.TemplateVersion {
|
||
|
|
allTemplates = append(allTemplates, config.DefaultConfig.GetNewAdditions()...)
|
||
|
|
}
|
||
|
|
_, err := semver.NewVersion(v)
|
||
|
|
if err != nil {
|
||
|
|
gologger.Error().Msgf("%v is not a valid semver version. skipping", v)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
if config.IsOutdatedVersion(v, "v8.8.4") {
|
||
|
|
// .new-additions was added in v8.8.4 any version before that is not supported
|
||
|
|
gologger.Error().Msgf(".new-additions support was added in v8.8.4 older versions are not supported")
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
|
||
|
|
arr, err := getNewAdditionsFileFromGithub(v)
|
||
|
|
if err != nil {
|
||
|
|
gologger.Error().Msgf("failed to fetch new additions for %v got: %v", v, err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
allTemplates = append(allTemplates, arr...)
|
||
|
|
}
|
||
|
|
return allTemplates
|
||
|
|
}
|
||
|
|
|
||
|
|
func getNewAdditionsFileFromGithub(version string) ([]string, error) {
|
||
|
|
resp, err := retryableHttpClient.Get(fmt.Sprintf("https://raw.githubusercontent.com/projectdiscovery/nuclei-templates/%s/.new-additions", version))
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if resp.StatusCode != http.StatusOK {
|
||
|
|
return nil, errorutil.New("version not found")
|
||
|
|
}
|
||
|
|
data, err := io.ReadAll(resp.Body)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
templatesList := []string{}
|
||
|
|
scanner := bufio.NewScanner(bytes.NewReader(data))
|
||
|
|
for scanner.Scan() {
|
||
|
|
text := scanner.Text()
|
||
|
|
if text == "" {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
if config.IsTemplate(text) {
|
||
|
|
templatesList = append(templatesList, text)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return templatesList, nil
|
||
|
|
}
|