-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e313d0
commit 1585fbd
Showing
6 changed files
with
132 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,77 @@ | ||
package pcidata | ||
|
||
import ( | ||
"strings" | ||
"unicode" | ||
) | ||
|
||
// List of card prefixes and their corresponding lengths | ||
var cardPrefixes = map[string][]int{ | ||
"34": {15}, // AMEX | ||
"37": {15}, // AMEX | ||
"300": {15}, // Diners | ||
"301": {15}, // Diners | ||
"302": {15}, // Diners | ||
"303": {15}, // Diners | ||
"36": {15}, // Diners | ||
"38": {15}, // Diners | ||
"6011": {16}, // Discover | ||
"2014": {16}, // Enroute | ||
"2149": {16}, // Enroute | ||
"2100": {16}, // JCB 15 | ||
"1800": {16}, // JCB 15 | ||
"3088": {16}, // JCB 16 | ||
"3096": {16}, // JCB 16 | ||
"3112": {16}, // JCB 16 | ||
"3158": {16}, // JCB 16 | ||
"3337": {16}, // JCB 16 | ||
"3528": {16}, // JCB 16 | ||
"51": {16}, // MasterCard | ||
"52": {16}, // MasterCard | ||
"53": {16}, // MasterCard | ||
"54": {16}, // MasterCard | ||
"55": {16}, // MasterCard | ||
"4": {13, 16}, // Visa | ||
"4539": {16}, // Visa | ||
"4556": {16}, // Visa | ||
"4916": {16}, // Visa | ||
"4532": {16}, // Visa | ||
"4929": {16}, // Visa | ||
"40240071": {16}, // Visa | ||
"4485": {16}, // Visa | ||
"4716": {16}, // Visa | ||
"8699": {13, 16}, // Voyager | ||
} | ||
|
||
// Matches the following card formats: | ||
// 4111111111111111 | ||
// 4111 1111 1111 1111 | ||
// 4111-1111-1111-1111 | ||
// 4111.1111.1111.1111 | ||
// **** **** **** 1111 | ||
const cardRegex = `(?:(\d|\*)[ -\.]*?){13,19}` | ||
|
||
// Normalize card number by removing non-digit characters (if separated by spaces, dots, or dashes) | ||
func normalizeCardNumber(card string) string { | ||
var normalized string | ||
for _, char := range card { | ||
if unicode.IsDigit(char) { | ||
normalized += string(char) | ||
} | ||
} | ||
return normalized | ||
} | ||
|
||
// Check if the card number is valid based on prefixes and length | ||
func isValidCardNumber(card string) bool { | ||
for prefix, lengths := range cardPrefixes { | ||
if strings.HasPrefix(card, prefix) { | ||
for _, length := range lengths { | ||
if len(card) == length { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
return false | ||
} |
This file contains 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 |
---|---|---|
@@ -1,31 +1,25 @@ | ||
package pcidata | ||
|
||
import ( | ||
"github.com/otterize/iamlive/iamlivecore" | ||
"github.com/otterize/intents-operator/src/shared/errors" | ||
ebpftypes "github.com/otterize/network-mapper/src/node-agent/pkg/ebpf/types" | ||
"io" | ||
"net/http" | ||
"regexp" | ||
) | ||
|
||
const AWSHost = "amazonaws.com" | ||
func ContainsPaymentInformation(ctx ebpftypes.EventContext, data string) error { | ||
// Regular expression for possible credit card patterns (13-19 digits, allowing spaces, dashes, or dots as separators) | ||
re := regexp.MustCompile(cardRegex) | ||
|
||
func HandleAwsRequest(ctx ebpftypes.EventContext, req *http.Request) error { | ||
body, err := io.ReadAll(req.Body) | ||
if err != nil { | ||
return errors.Wrap(err) | ||
} | ||
|
||
// Check if the event is an AWS request - called to host "amazonaws.com" | ||
if req.Host != AWSHost { | ||
return nil | ||
} | ||
// Find all matches | ||
matches := re.FindAllString(data, -1) | ||
|
||
// Check if the event is an egress event | ||
if ebpftypes.Direction(ctx.Event.Meta.Direction) != ebpftypes.DirectionEgress { | ||
return nil | ||
// Filter matches based on valid credit card prefix and length | ||
for _, match := range matches { | ||
normalized := normalizeCardNumber(match) | ||
if isValidCardNumber(normalized) { | ||
// Set PCI tag | ||
ctx.Metadata.Tags[ebpftypes.EventTagPCI] = true | ||
} | ||
} | ||
|
||
iamlivecore.HandleAWSRequest(req, body, 200) | ||
return nil | ||
} |
This file contains 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