|
| 1 | +package nigerianfintech |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "regexp" |
| 6 | + |
| 7 | + "github.com/trufflesecurity/trufflehog/v3/pkg/common" |
| 8 | + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" |
| 9 | + "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" |
| 10 | +) |
| 11 | + |
| 12 | +type scanner struct{} |
| 13 | + |
| 14 | +// Ensure the detector satisfies the interface at compile time. |
| 15 | +var _ detectors.Detector = (*scanner)(nil) |
| 16 | + |
| 17 | +func (s scanner) ID() int { return 987 } |
| 18 | + |
| 19 | +func (s scanner) Type() detectorspb.DetectorType { |
| 20 | + return detectorspb.DetectorType_CustomRegex |
| 21 | +} |
| 22 | + |
| 23 | +func (s scanner) Description() string { |
| 24 | + return "Detects exposed Nigerian fintech & betting credentials (Paystack, Flutterwave, Remita, Interswitch, SportyBet/BetKing)" |
| 25 | +} |
| 26 | + |
| 27 | +// Keywords are used for pre-filtering. |
| 28 | +func (s scanner) Keywords() []string { |
| 29 | + return []string{ |
| 30 | + "paystack", "flutterwave", "remita", "interswitch", "sportybet", "betking", |
| 31 | + "sk_live", "sk_test", "FLWSECK", "macKey", |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +// FromData will be called when keywords are matched. |
| 36 | +func (s scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) { |
| 37 | + dataStr := string(data) |
| 38 | + |
| 39 | + patterns := map[string]string{ |
| 40 | + "Paystack Secret Key": `sk_(live|test)_[0-9a-zA-Z]{50,}`, |
| 41 | + "Flutterwave Secret Key": `FLWSECK[_-]?[a-zA-Z0-9]{30,}`, |
| 42 | + "Flutterwave Test Key": `FLWSECK_TEST-[a-z0-9]{30,}`, |
| 43 | + "Remita Merchant+Hash": `[0-9]{10,15}\|?[0-9a-zA-Z]{40,}`, |
| 44 | + "Interswitch MAC Key": `macKey["']?\s*[:=]\s*["']?[0-9A-Fa-f]{64}`, |
| 45 | + "Betting Admin Token": `eyJ[A-Za-z0-9-_]{100,}|Bearer [A-Za-z0-9-_]{50,}\.[A-Za-z0-9-_]{50,}\.[A-Za-z0-9-_]{50,}`, |
| 46 | + } |
| 47 | + |
| 48 | + for name, regexStr := range patterns { |
| 49 | + rx := regexp.MustCompile(regexStr) |
| 50 | + matches := rx.FindAllString(dataStr, -1) |
| 51 | + |
| 52 | + for _, match := range matches { |
| 53 | + result := detectors.Result{ |
| 54 | + DetectorType: detectorspb.DetectorType_CustomRegex, |
| 55 | + Verified: false, // we can't verify without API call |
| 56 | + ExtraData: map[string]string{ |
| 57 | + "service": name, |
| 58 | + }, |
| 59 | + } |
| 60 | + result.Raw = []byte(match) |
| 61 | + |
| 62 | + if verify { |
| 63 | + // Skip verification for now (too many services) |
| 64 | + result.Verified = false |
| 65 | + } |
| 66 | + results = append(results, result) |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + return results, nil |
| 71 | +} |
| 72 | + |
| 73 | +// New returns a new detector instance. |
| 74 | +func New() detectors.Detector { |
| 75 | + return &scanner{} |
| 76 | +} |
0 commit comments