-
Notifications
You must be signed in to change notification settings - Fork 3.4k
draft: Version ranges #7306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
charles1024
wants to merge
6
commits into
projectdiscovery:dev
Choose a base branch
from
charles1024:version-ranges
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
draft: Version ranges #7306
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d5ed7d
add Apache detection to nuclei core logic
42341b0
modified core
536b30e
adding new nuclei logic
1ab872d
attemptd to add Debug Messages for Nuclei
72f5ce5
added debugging and a tech-stack check inside of executeTemplateOnInput
charles1024 a2d6960
template filtering successful
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package hosttechcache | ||
|
|
||
| import ( | ||
| "strings" | ||
| "sync" | ||
| "github.com/projectdiscovery/gologger" | ||
| ) | ||
|
|
||
| // TechHint represents a detected technology on a host that can be used | ||
| // to filter templates before execution. | ||
| type TechHint struct { | ||
| // Tags is the set of template tags that are REQUIRED for this host. | ||
| // A template is skipped unless it contains at least one of these tags, | ||
| // or the set is empty (meaning: no filtering). | ||
| Tags map[string]struct{} | ||
| } | ||
|
|
||
| // HostTechCache stores per-host technology hints derived from early HTTP | ||
| // responses (e.g. the Server: header). It is safe for concurrent use. | ||
| type HostTechCache struct { | ||
| mu sync.RWMutex | ||
| hints map[string]*TechHint // keyed by normalised host (scheme+host) | ||
| } | ||
|
|
||
| // NewHostTechCache returns an initialised HostTechCache. | ||
| func NewHostTechCache() *HostTechCache { | ||
| return &HostTechCache{hints: make(map[string]*TechHint)} | ||
| } | ||
|
|
||
| // RecordServerHeader inspects a raw Server header value and, if it contains | ||
| // a known technology keyword, records a tag requirement for that host. | ||
| // | ||
| // Currently understood keywords → required tag: | ||
| // | ||
| // "apache" → "apache" | ||
| // | ||
| // The mapping is intentionally simple and lowercase-compared so that | ||
| // "Apache/2.4.51 (Unix)" and "apache" both resolve to the same hint. | ||
| func (c *HostTechCache) RecordServerHeader(host, serverHeader string) { | ||
| lower := strings.ToLower(serverHeader) | ||
|
|
||
| var requiredTags []string | ||
| if strings.Contains(lower, "apache") { | ||
| requiredTags = append(requiredTags, "apache") | ||
| } | ||
|
|
||
| c.mu.Lock() | ||
| defer c.mu.Unlock() | ||
|
|
||
| if len(requiredTags) == 0 { | ||
| if _, exists := c.hints[host]; exists { | ||
| gologger.Debug().Msgf("[tech-filter] CLEARED hint for host '%s' (unrecognised Server header: '%s')", | ||
| host, serverHeader) | ||
| } | ||
| delete(c.hints, host) | ||
| return | ||
| } | ||
|
|
||
| gologger.Debug().Msgf("[tech-filter] RECORDED hint for host '%s' — Server: '%s' → required tags: %v", | ||
| host, serverHeader, requiredTags) | ||
|
|
||
| hint := &TechHint{Tags: make(map[string]struct{}, len(requiredTags))} | ||
| for _, t := range requiredTags { | ||
| hint.Tags[t] = struct{}{} | ||
| } | ||
| c.hints[host] = hint | ||
| } | ||
|
|
||
| // ShouldSkipTemplate returns true when the cache has a hint for the given host | ||
| // AND the template's tags contain none of the required tags. | ||
| // | ||
| // If there is no hint for the host the function always returns false (no skip). | ||
| func (c *HostTechCache) ShouldSkipTemplate(host string, templateTags []string) bool { | ||
| c.mu.RLock() | ||
| hint, ok := c.hints[host] | ||
| c.mu.RUnlock() | ||
|
|
||
| if !ok || len(hint.Tags) == 0 { | ||
| return false // no information → don't skip | ||
| } | ||
|
|
||
| for _, tag := range templateTags { | ||
| if _, required := hint.Tags[strings.ToLower(tag)]; required { | ||
| return false // template has at least one matching tag → keep it | ||
| } | ||
| } | ||
| return true // no matching tag found → skip | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 22286
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 783
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 891
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 2050
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 525
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 1467
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 127
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 40798
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 49
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 2668
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 49
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 149
🏁 Script executed:
# Check the input package files ls -la pkg/input/Repository: projectdiscovery/nuclei
Length of output: 544
🏁 Script executed:
# Read the transform.go file to see Helper and Transform implementation cat -n pkg/input/transform.goRepository: projectdiscovery/nuclei
Length of output: 4978
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 4607
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 49
🏁 Script executed:
Repository: projectdiscovery/nuclei
Length of output: 498
Normalize host key consistently between cache recording and lookups to prevent cache misses.
The
ShouldSkipTemplatecheck at template execution time usesctx.Input.MetaInput.Inputin its original form, butRecordServerHeaderis called after the HTTP protocol executor has processed the input throughInputHelper.Transform(). For HTTP protocol requests, this transforms raw inputs (like"example.com") into full URLs (like"https://example.com"), causing a key format mismatch.Scenario where this fails:
"example.com"ShouldSkipTemplate()checks cache with key"example.com"→ miss (cache empty)"https://example.com"viaInputHelper.Transform()RecordServerHeader()records hint with key"https://example.com""example.com"looks up"example.com"again → still a miss, despite hint existingApply the suggested normalization approach to extract a consistent key (host+port only) in both
RecordServerHeaderandShouldSkipTemplatemethods:🔧 Suggested normalization
🤖 Prompt for AI Agents