- GitHubActionsSource: searches GitHub code search for workflow files with provider keywords (token-gated) - TravisCISource: queries Travis CI v3 API for public build logs (credentialless) - CircleCISource: queries CircleCI v2 pipeline API for build pipelines (token-gated) - JenkinsSource: queries open Jenkins /api/json for job build consoles (credentialless) - GitLabCISource: queries GitLab projects API for CI-enabled projects (token-gated) - RegisterAll extended to 45 sources (40 Phase 10-13 + 5 Phase 14) - Integration test updated with fixtures for all 5 new sources - cmd/recon.go wires CIRCLECI_TOKEN env var
132 lines
3.2 KiB
Go
132 lines
3.2 KiB
Go
package sources
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
"time"
|
|
|
|
"golang.org/x/time/rate"
|
|
|
|
"github.com/salvacybersec/keyhunter/pkg/providers"
|
|
"github.com/salvacybersec/keyhunter/pkg/recon"
|
|
)
|
|
|
|
// 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.
|
|
type TravisCISource struct {
|
|
BaseURL string
|
|
Registry *providers.Registry
|
|
Limiters *recon.LimiterRegistry
|
|
Client *Client
|
|
}
|
|
|
|
var _ recon.ReconSource = (*TravisCISource)(nil)
|
|
|
|
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 }
|
|
|
|
type travisBuildResponse struct {
|
|
Builds []travisBuild `json:"builds"`
|
|
}
|
|
|
|
type travisBuild struct {
|
|
ID int `json:"id"`
|
|
State string `json:"state"`
|
|
Repository travisRepository `json:"repository"`
|
|
}
|
|
|
|
type travisRepository struct {
|
|
Slug string `json:"slug"`
|
|
}
|
|
|
|
func (s *TravisCISource) Sweep(ctx context.Context, _ string, out chan<- recon.Finding) error {
|
|
base := s.BaseURL
|
|
if base == "" {
|
|
base = "https://api.travis-ci.org"
|
|
}
|
|
client := s.Client
|
|
if client == nil {
|
|
client = NewClient()
|
|
}
|
|
|
|
queries := BuildQueries(s.Registry, "travisci")
|
|
kwIndex := travisKeywordIndex(s.Registry)
|
|
|
|
for _, q := range queries {
|
|
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
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
req.Header.Set("Travis-API-Version", "3")
|
|
req.Header.Set("Accept", "application/json")
|
|
|
|
resp, err := client.Do(ctx, req)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
var result travisBuildResponse
|
|
decErr := json.NewDecoder(resp.Body).Decode(&result)
|
|
_ = resp.Body.Close()
|
|
if decErr != nil {
|
|
continue
|
|
}
|
|
|
|
provName := kwIndex[strings.ToLower(q)]
|
|
for _, build := range result.Builds {
|
|
source := fmt.Sprintf("https://app.travis-ci.com/%s/builds/%d",
|
|
url.PathEscape(build.Repository.Slug), build.ID)
|
|
f := recon.Finding{
|
|
ProviderName: provName,
|
|
Confidence: "low",
|
|
Source: source,
|
|
SourceType: "recon:travisci",
|
|
DetectedAt: time.Now(),
|
|
}
|
|
select {
|
|
case out <- f:
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func travisKeywordIndex(reg *providers.Registry) map[string]string {
|
|
m := make(map[string]string)
|
|
if reg == nil {
|
|
return m
|
|
}
|
|
for _, p := range reg.List() {
|
|
for _, k := range p.Keywords {
|
|
kl := strings.ToLower(strings.TrimSpace(k))
|
|
if kl != "" {
|
|
if _, exists := m[kl]; !exists {
|
|
m[kl] = p.Name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return m
|
|
}
|