This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Gophlare is a Go SDK and CLI wrapper for the flare.io API, used for threat intelligence — searching breach credentials, stealer logs, and cookies. It also integrates with Bloodhound-CE for Active Directory breach data correlation. The tool is designed for authorized security testing and penetration testing engagements.
# Build
go build -v -trimpath -ldflags="-s -w" .
# Run tests (local, uses tparse for formatting)
make test
# Run a single test
go test -v -run TestFunctionName ./package/...
# Lint
make lint
# or directly:
golangci-lint run -c .golangci-lint.yml -v ./... --timeout 10m
# Format check
make fmt
# Full pipeline
make all # fmt + lint + build + test + releasePre-commit hooks run TruffleHog (secret scanning), golangci-lint, and tests on commit/push. These run via make lint and make test.
main.go— Entry point, initializes~/.config/gophlare/and runs the root command.cmd/root.go— Root cobra command. Config loaded via viper from--configflag or~/.config/gophlare/config.yaml. Env vars prefixed withGOFLARE_.cmd/search/command.go—gophlare searchsubcommand. Delegates tophlare.Optionsfor flag loading, creates aScope, then dispatches to stealer log, credential, or email search functions.cmd/bloodhound/command.go—gophlare bloodhoundsubcommand for correlating breach data with Bloodhound-CE.cmd/docs/command.go— Generates CLI documentation.
phlare/options.go—Optionsstruct andConfigureCommand()to register all cobra flags.LoadFromCommand()parses flags usingutils.ConfigureFlagOpts(). Several fields (Domains,Emails,Severity, etc.) areinterface{}because they can be a string,[]string, or file path.phlare/scope.go—Scopestruct normalizesOptionsinterface{} fields into typed[]stringslices, with out-of-scope domain filtering.phlare/flareClient.go—FlareClienthandles API auth (JWT token via Basic auth), auto-refresh on expiry, and all Flare API calls (global events search, credentials search, cookies search, stealer log downloads). Pagination uses aNextcursor field.phlare/types.go— All Flare API request/response structs.FlareTimeis a customtime.Timewrapper that handles multiple timestamp formats from the API.phlare/time.go—FlareTimeJSON unmarshalling (tries multiple formats),Scan/Valuefor GORM database serialization.phlare/http.go— Generic HTTPClientwithDoReq()method. Response decoding dispatches to JSON or XML based on Content-Type. Whentargetis a string, it writes the body to that file path.phlare/db.go— SQLite database (via GORM +glebarez/sqlite) for persisting breach data. Stored at~/.config/gophlare/database/. Batch inserts for stealer log activities and credentials with upsert on UID conflict.phlare/dbModels.go— GORM model definitions for all database tables.
bloodhound/api.go— Bloodhound-CE API client (user enumeration).bloodhound/neo4j.go— Neo4j queries for correlating breach data with AD data.bloodhound/postgres.go— Alternative Postgres-based Bloodhound queries.bloodhound/ingest.go— Data ingestion and correlation logic.
utils/flags.go—ConfigureFlagOpts()is the central flag resolution function. Priority: CLI flag > env var (via GOFLARE_ prefix) > viper config value > default. Handles type coercion, file-to-slice reading, and comma-separated string splitting.utils/string.go— String utilities includingIsUserIDFormatMatch()which dynamically generates regex patterns from sample user ID formats (e.g.,a12345becomes^[A-Za-z]\d{5}$).utils/file.go— File helpers (path resolution, existence checks, gzip compression, JSON/CSV/XLSX writing).utils/log.go— Logging wrappers aroundgologgerwith colored output and file-based error logging.utils/slice.go— Slice utilities (dedup, contains, filtering).
config/config.go—GoPhlareConfigstruct withAPI_KEYS.FLARE_APIandAPI_KEYS.FLARE_TENANT_IDloaded via viper.config/config.yaml— Example config file (contains real API keys — do not commit changes to this file).
- Flag resolution chain: CLI flag →
GOFLARE_*env var → viper config (YAML) → default value. All handled inutils.ConfigureFlagOpts(). - Interface{} for multi-type inputs:
Optionsfields likeDomains,Emails,Severityuseinterface{}to accept string,[]string, or file paths.Scopenormalizes these viaresolveToSlice(). - FlareTime: Custom time type that handles multiple Flare API timestamp formats. Used throughout API response structs and GORM models. When adding new time fields, use
FlareTimenottime.Time. - API pagination: Flare API uses cursor-based pagination via
Next *stringfield. Pagination loops use labeledbreak flarePaginatepattern. - Version: Hardcoded in both
cmd/root.go(versionvar) andphlare/flareClient.go(gophlareClientVersionconst). Both must be updated together for releases.
- Sister project:
goreconasoutsiderat~/projects/goreconasoutsidershares the sameutils/flags.goConfigureFlagOpts pattern. Features may be ported between them (e.g.,ReadFileLineswas ported from goreconasoutsider to gophlare).
Uses golangci-lint v2 config (.golangci-lint.yml). Key enabled linters: bodyclose, dupl, errorlint, gocognit, goconst, gocritic, gosec, govet, staticcheck, unused. The gocognit nolint directive is used on complex LoadFromCommand methods.