-
Notifications
You must be signed in to change notification settings - Fork 257
Add search Engine _ GreyNoise #697
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
Merged
dogancanbakir
merged 12 commits into
projectdiscovery:dev
from
deehyeon:feat/696-greynoise-provider
Nov 25, 2025
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
74df3a4
feat: Add GreyNoise Agent Core Implementation
deehyeon 9363af6
feat: Integrate GreyNoise API Key Management
deehyeon ca3a227
feat: Add GreyNoise CLI Option
deehyeon 9464979
test: Add GreyNoise Integration Tests
deehyeon 5ace138
feat: Update session to support GreyNoise provider
deehyeon c6ffccd
chore: Add GreyNoise example.json for reference
deehyeon e79a5e2
fix: remove unsupported 'quick' param from GreyNoise GNQL (review fee…
deehyeon 90f3b7b
fix: correct LastSeenTS type to string
deehyeon f0178b2
fix: remove sensitive GreyNoise API key from logs (#696)
deehyeon e3da069
fix: apply review feedback and schema corrections
deehyeon 2d92409
fix:switch to /v3/gnql/metadata endpoint when ExcludeRaw is true
deehyeon 0ef1ee2
feat: Add support for Greynoise
deehyeon 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
Empty file.
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,188 @@ | ||
| package greynoise | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "net/url" | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/projectdiscovery/uncover/sources" | ||
| ) | ||
|
|
||
| const ( | ||
| URL = "https://api.greynoise.io/v3/gnql" | ||
| ) | ||
|
|
||
| type Agent struct{} | ||
|
|
||
| func (agent *Agent) Name() string { return "greynoise" } | ||
|
|
||
| func (agent *Agent) Query(session *sources.Session, query *sources.Query) (chan sources.Result, error) { | ||
| if session.Keys.GreyNoiseKey == "" { | ||
| return nil, errors.New("empty GreyNoise API key") | ||
| } | ||
|
|
||
| results := make(chan sources.Result) | ||
|
|
||
| go func() { | ||
| defer close(results) | ||
|
|
||
| scrollToken := "" | ||
| total := 0 | ||
| done := false | ||
|
|
||
| pageSize := 1000 | ||
| if query.Limit > 0 && query.Limit < pageSize { | ||
| pageSize = query.Limit | ||
| } | ||
|
|
||
| for !done { | ||
| req := &Request{ | ||
| Query: query.Query, | ||
| Size: pageSize, | ||
| Scroll: scrollToken, | ||
| Quick: false, | ||
| ExcludeRaw: true, | ||
| } | ||
|
|
||
| apiResponse, err := agent.query(session, req) | ||
| if err != nil { | ||
| results <- sources.Result{Source: agent.Name(), Error: err} | ||
| return | ||
| } | ||
| if apiResponse == nil || len(apiResponse.Data) == 0 { | ||
| return | ||
| } | ||
|
|
||
| for _, item := range apiResponse.Data { | ||
| host := firstNonEmpty( | ||
| item.InternetScannerIntelligence.Metadata.Domain, | ||
| item.InternetScannerIntelligence.Metadata.RDNS, | ||
| ) | ||
|
|
||
deehyeon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| r := sources.Result{ | ||
| Source: agent.Name(), | ||
| IP: item.IP, | ||
| Host: host, | ||
| } | ||
| if raw, err := json.Marshal(item); err == nil { | ||
| r.Raw = raw | ||
| } | ||
| results <- r | ||
|
|
||
| total++ | ||
| if query.Limit > 0 && total >= query.Limit { | ||
| done = true | ||
| break | ||
| } | ||
| } | ||
|
|
||
| done = done || apiResponse.RequestMetadata.Complete | ||
| scrollToken = apiResponse.RequestMetadata.Scroll | ||
| if strings.TrimSpace(scrollToken) == "" { | ||
| done = true | ||
| } | ||
|
|
||
| if query.Limit > 0 && !done { | ||
| remain := query.Limit - total | ||
| if remain < pageSize { | ||
| pageSize = remain | ||
| } | ||
| } | ||
| } | ||
| }() | ||
|
|
||
| return results, nil | ||
| } | ||
|
|
||
| func (agent *Agent) query(session *sources.Session, request *Request) (*Response, error) { | ||
| params := url.Values{} | ||
| params.Set("query", request.Query) | ||
|
|
||
| if request.Size > 0 { | ||
| if request.Size > 10000 { | ||
| request.Size = 10000 | ||
| } | ||
| params.Set("size", strconv.Itoa(request.Size)) | ||
| } | ||
| if request.Scroll != "" { | ||
| params.Set("scroll", request.Scroll) | ||
| } | ||
| if request.Quick { | ||
| params.Set("quick", "true") | ||
| } | ||
| if request.ExcludeRaw { | ||
| params.Set("exclude_raw", "true") | ||
| } | ||
|
|
||
| fullURL := URL | ||
| if enc := params.Encode(); enc != "" { | ||
| fullURL = fullURL + "?" + enc | ||
| } | ||
|
|
||
| req, err := sources.NewHTTPRequest(http.MethodGet, fullURL, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| req.Header.Set("Accept", "application/json") | ||
| req.Header.Set("key", session.Keys.GreyNoiseKey) | ||
|
|
||
deehyeon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| resp, err := session.Do(req, agent.Name()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| if resp.StatusCode < 200 || resp.StatusCode > 299 { | ||
| b, _ := io.ReadAll(resp.Body) | ||
| msg := strings.TrimSpace(string(b)) | ||
|
|
||
| if resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusNotFound { | ||
| return nil, fmt.Errorf( | ||
| "GreyNoise GNQL request failed: status=%d. Your API key may not include GNQL access (Enterprise key required). body=%s", | ||
| resp.StatusCode, msg, | ||
| ) | ||
| } | ||
deehyeon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return nil, fmt.Errorf("greynoise GNQL request failed: status=%d body=%s", resp.StatusCode, msg) | ||
| } | ||
|
|
||
| var apiResponse Response | ||
| if err := json.NewDecoder(resp.Body).Decode(&apiResponse); err != nil { | ||
| fmt.Fprintf(os.Stderr, "DEBUG: GreyNoise decode error status=%d: %v\n", resp.StatusCode, err) | ||
| return nil, err | ||
| } | ||
|
|
||
| fmt.Fprintf(os.Stderr, | ||
| "DEBUG: GNQL count=%d complete=%v scroll=%s data=%d msg=%s\n", | ||
| apiResponse.RequestMetadata.Count, | ||
| apiResponse.RequestMetadata.Complete, | ||
| short(apiResponse.RequestMetadata.Scroll, 12), | ||
| len(apiResponse.Data), | ||
| short(apiResponse.RequestMetadata.Message, 120), | ||
| ) | ||
deehyeon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return &apiResponse, nil | ||
| } | ||
|
|
||
| func firstNonEmpty(vs ...string) string { | ||
| for _, v := range vs { | ||
| if strings.TrimSpace(v) != "" { | ||
| return v | ||
| } | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| func short(s string, max int) string { | ||
| if len(s) <= max { | ||
| return s | ||
| } | ||
| return s[:max] + "…" | ||
| } | ||
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,9 @@ | ||
| package greynoise | ||
|
|
||
| type Request struct { | ||
| Query string // GNQL query string (required) | ||
| Size int // Number of results per page (1-10000, defaults to 10000) | ||
| Scroll string // Scroll token for pagination | ||
| Quick bool // Quick=true returns only IP and classification/trust level | ||
| ExcludeRaw bool // Optional: request without heavy raw_data | ||
| } | ||
deehyeon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.