merge: phase 14-04 register wiring
This commit is contained in:
@@ -4,9 +4,15 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
<<<<<<< HEAD
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
=======
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
@@ -15,9 +21,16 @@ import (
|
||||
"github.com/salvacybersec/keyhunter/pkg/recon"
|
||||
)
|
||||
|
||||
<<<<<<< HEAD
|
||||
// TravisCISource searches public Travis CI build logs for leaked API keys.
|
||||
// It queries the Travis CI API v3 /builds endpoint for builds matching
|
||||
// provider keywords. No authentication required for public repositories.
|
||||
=======
|
||||
// TravisCISource scrapes public Travis CI build logs for leaked API keys.
|
||||
// Travis CI exposes build logs publicly by default for open-source projects.
|
||||
// Developers frequently print environment variables or use secrets insecurely
|
||||
// in CI scripts, causing API keys to appear in build output.
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
type TravisCISource struct {
|
||||
BaseURL string
|
||||
Registry *providers.Registry
|
||||
@@ -27,17 +40,28 @@ type TravisCISource struct {
|
||||
|
||||
var _ recon.ReconSource = (*TravisCISource)(nil)
|
||||
|
||||
<<<<<<< HEAD
|
||||
func (s *TravisCISource) Name() string { return "travisci" }
|
||||
func (s *TravisCISource) RateLimit() rate.Limit { return rate.Every(3 * time.Second) }
|
||||
func (s *TravisCISource) Burst() int { return 1 }
|
||||
func (s *TravisCISource) RespectsRobots() bool { return true }
|
||||
func (s *TravisCISource) Enabled(_ recon.Config) bool { return true }
|
||||
|
||||
=======
|
||||
func (s *TravisCISource) Name() string { return "travisci" }
|
||||
func (s *TravisCISource) RateLimit() rate.Limit { return rate.Every(3 * time.Second) }
|
||||
func (s *TravisCISource) Burst() int { return 2 }
|
||||
func (s *TravisCISource) RespectsRobots() bool { return false }
|
||||
func (s *TravisCISource) Enabled(_ recon.Config) bool { return true }
|
||||
|
||||
// travisBuildResponse represents the Travis CI API builds response.
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
type travisBuildResponse struct {
|
||||
Builds []travisBuild `json:"builds"`
|
||||
}
|
||||
|
||||
type travisBuild struct {
|
||||
<<<<<<< HEAD
|
||||
ID int `json:"id"`
|
||||
State string `json:"state"`
|
||||
Repository travisRepository `json:"repository"`
|
||||
@@ -46,6 +70,14 @@ type travisBuild struct {
|
||||
type travisRepository struct {
|
||||
Slug string `json:"slug"`
|
||||
}
|
||||
=======
|
||||
ID int `json:"id"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
// ciLogKeyPattern matches API key patterns commonly leaked in CI logs.
|
||||
var ciLogKeyPattern = regexp.MustCompile(`(?i)(api[_-]?key|secret[_-]?key|token|password|credential|auth[_-]?token)['":\s]*[=:]\s*['"]?([a-zA-Z0-9_\-]{16,})['"]?`)
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
|
||||
func (s *TravisCISource) Sweep(ctx context.Context, _ string, out chan<- recon.Finding) error {
|
||||
base := s.BaseURL
|
||||
@@ -58,23 +90,41 @@ func (s *TravisCISource) Sweep(ctx context.Context, _ string, out chan<- recon.F
|
||||
}
|
||||
|
||||
queries := BuildQueries(s.Registry, "travisci")
|
||||
<<<<<<< HEAD
|
||||
kwIndex := travisKeywordIndex(s.Registry)
|
||||
=======
|
||||
if len(queries) == 0 {
|
||||
return nil
|
||||
}
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
|
||||
for _, q := range queries {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
if s.Limiters != nil {
|
||||
if err := s.Limiters.Wait(ctx, s.Name(), s.RateLimit(), s.Burst(), false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
endpoint := fmt.Sprintf("%s/builds?limit=20&sort_by=finished_at:desc&state=passed&event_type=push",
|
||||
base)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("travisci: build request: %w", err)
|
||||
=======
|
||||
// Search for builds related to the query keyword.
|
||||
searchURL := fmt.Sprintf("%s/builds?search=%s&limit=5", base, q)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, searchURL, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
}
|
||||
req.Header.Set("Travis-API-Version", "3")
|
||||
req.Header.Set("Accept", "application/json")
|
||||
@@ -84,6 +134,7 @@ func (s *TravisCISource) Sweep(ctx context.Context, _ string, out chan<- recon.F
|
||||
continue
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
var result travisBuildResponse
|
||||
decErr := json.NewDecoder(resp.Body).Decode(&result)
|
||||
_ = resp.Body.Close()
|
||||
@@ -106,11 +157,60 @@ func (s *TravisCISource) Sweep(ctx context.Context, _ string, out chan<- recon.F
|
||||
case out <- f:
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
=======
|
||||
var builds travisBuildResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&builds); err != nil {
|
||||
_ = resp.Body.Close()
|
||||
continue
|
||||
}
|
||||
_ = resp.Body.Close()
|
||||
|
||||
for _, b := range builds.Builds {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s.Limiters != nil {
|
||||
if err := s.Limiters.Wait(ctx, s.Name(), s.RateLimit(), s.Burst(), false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch the build log.
|
||||
logURL := fmt.Sprintf("%s/builds/%d/log", base, b.ID)
|
||||
logReq, err := http.NewRequestWithContext(ctx, http.MethodGet, logURL, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
logReq.Header.Set("Travis-API-Version", "3")
|
||||
logReq.Header.Set("Accept", "text/plain")
|
||||
|
||||
logResp, err := client.Do(ctx, logReq)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(io.LimitReader(logResp.Body, 256*1024))
|
||||
_ = logResp.Body.Close()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if ciLogKeyPattern.Match(body) {
|
||||
out <- recon.Finding{
|
||||
ProviderName: q,
|
||||
Source: logURL,
|
||||
SourceType: "recon:travisci",
|
||||
Confidence: "medium",
|
||||
DetectedAt: time.Now(),
|
||||
}
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
func travisKeywordIndex(reg *providers.Registry) map[string]string {
|
||||
m := make(map[string]string)
|
||||
@@ -129,3 +229,5 @@ func travisKeywordIndex(reg *providers.Registry) map[string]string {
|
||||
}
|
||||
return m
|
||||
}
|
||||
=======
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
|
||||
Reference in New Issue
Block a user