● Notice //GitHub (@shehzade) is temporarily suspended pending an automated false-positive review. All tools are hosted on this Code Mirror and available on request (contact); GitHub links will return once reinstated.
PUBLIC MIRRORGo v1.0

Multi-protocol network egress assessment and DLP verification framework featuring automated L4 sweeps, corporate proxy traversal, and covert protocol smuggling across 20+ channels.

$ git clone https://shehzade.io/repos/contraband.git Copy
Source ZIP (1.93 MB)
Code 174 Commits 1
contraband / pkg / client / dlp / procedural.go
← Back to directory
140 lines · 5.2 KB
Raw
1package dlp
2
3import (
4 "encoding/base64"
5 "encoding/hex"
6 "encoding/json"
7 "fmt"
8 "math/rand"
9 "strings"
10 "time"
11)
12
13// GenerateCarrierRecord produces a serialized record embedding synthetic DLP data in the specified carrier format.
14func GenerateCarrierRecord(carrier string, dlpType string, r *rand.Rand, domain string) []byte {
15 if domain == "" {
16 domain = "acme-corp.internal"
17 }
18
19 switch strings.ToLower(carrier) {
20 case "csv":
21 return generateCSVRecord(dlpType, r, domain)
22 case "json":
23 return generateJSONRecord(dlpType, r, domain)
24 case "sql":
25 return generateSQLRecord(dlpType, r, domain)
26 case "email":
27 return generateEmailRecord(dlpType, r, domain)
28 case "syslog":
29 return generateSyslogRecord(dlpType, r, domain)
30 case "noise":
31 return generateNoiseRecord(dlpType, r, domain)
32 default:
33 return generateRawRecord(dlpType, r, domain)
34 }
35}
36
37func generateCSVRecord(dlpType string, r *rand.Rand, domain string) []byte {
38 emp := GenerateEmployeeProfile(r, domain)
39 cc, _ := GenerateCreditCard(BrandVisa, r, FormatHyphenated)
40 // Return a single CSV row
41 line := fmt.Sprintf("%s,\"%s %s\",%s,%s,%02d/%02d,%s,%s,%d\n",
42 emp.ID, emp.FirstName, emp.LastName, emp.SSN, cc.Formatted, cc.ExpMonth, cc.ExpYear, emp.Department, emp.Email, emp.Salary)
43 return []byte(line)
44}
45
46func generateJSONRecord(dlpType string, r *rand.Rand, domain string) []byte {
47 emp := GenerateEmployeeProfile(r, domain)
48 cc, _ := GenerateCreditCard(BrandMasterCard, r, FormatHyphenated)
49 t := time.Unix(1772841600+r.Int63n(86400*30), int64(r.Intn(1000000000))).UTC()
50 data := map[string]any{
51 "event_id": fmt.Sprintf("evt_%08x", r.Uint32()),
52 "timestamp": t.Format(time.RFC3339Nano),
53 "employee": emp,
54 "billing_pan": cc.Formatted,
55 "card_exp": fmt.Sprintf("%02d/%02d", cc.ExpMonth, cc.ExpYear),
56 "cvv": cc.CVV,
57 }
58 b, _ := json.Marshal(data)
59 return append(b, '\n')
60}
61
62func generateSQLRecord(dlpType string, r *rand.Rand, domain string) []byte {
63 emp := GenerateEmployeeProfile(r, domain)
64 cc, _ := GenerateCreditCard(BrandAmex, r, FormatRaw)
65 line := fmt.Sprintf("INSERT INTO corporate_records (emp_id, first_name, last_name, email, ssn, pan, salary) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %d);\n",
66 emp.ID, emp.FirstName, emp.LastName, emp.Email, emp.SSN, cc.Number, emp.Salary)
67 return []byte(line)
68}
69
70func generateEmailRecord(dlpType string, r *rand.Rand, domain string) []byte {
71 emp := GenerateEmployeeProfile(r, domain)
72 cc, _ := GenerateCreditCard(BrandVisa, r, FormatSpaceDelimited)
73 ak, sk := GenerateAWSCredentials(r)
74 t := time.Unix(1772841600+r.Int63n(86400*30), 0).UTC()
75
76 email := fmt.Sprintf("From: %s\r\nTo: compliance-audit@%s\r\nSubject: Quarterly Verification - %s\r\nDate: %s\r\nMessage-ID: <%08x@%s>\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nHi Team,\r\n\r\nPlease review the attached employee billing record for %s %s (SSN: %s).\r\nCorporate Card on file: %s (Exp: %02d/%02d).\r\nStaging AWS Access: %s (Secret: %s)\r\n\r\nRegards,\r\n%s %s\r\n%s Department\r\n---\r\n\r\n",
77 emp.Email, domain, emp.ID, t.Format(time.RFC1123Z), r.Uint32(), domain,
78 emp.FirstName, emp.LastName, emp.SSN, cc.Formatted, cc.ExpMonth, cc.ExpYear,
79 ak, sk, emp.FirstName, emp.LastName, emp.Department)
80 return []byte(email)
81}
82
83func generateSyslogRecord(dlpType string, r *rand.Rand, domain string) []byte {
84 emp := GenerateEmployeeProfile(r, domain)
85 t := time.Unix(1772841600+r.Int63n(86400*30), int64(r.Intn(1000000000))).UTC()
86 timestamp := t.Format(time.RFC3339Nano)
87 line := fmt.Sprintf("<134>1 %s auth-server.internal app - [authEvent@41113 ssn=\"%s\" user=\"%s\" dept=\"%s\"] Authentication granted for %s\n",
88 timestamp, emp.SSN, emp.Email, emp.Department, emp.ID)
89 return []byte(line)
90}
91
92func generateNoiseRecord(dlpType string, r *rand.Rand, domain string) []byte {
93 rawDLP := strings.TrimRight(string(generateRawRecord(dlpType, r, domain)), "\r\n")
94
95 preLen := 16 + r.Intn(32)
96 postLen := 16 + r.Intn(32)
97
98 preBytes := make([]byte, preLen)
99 r.Read(preBytes)
100 postBytes := make([]byte, postLen)
101 r.Read(postBytes)
102
103 var prefix, suffix string
104 if r.Intn(2) == 0 {
105 prefix = hex.EncodeToString(preBytes)
106 } else {
107 prefix = base64.StdEncoding.EncodeToString(preBytes)
108 }
109
110 if r.Intn(2) == 0 {
111 suffix = hex.EncodeToString(postBytes)
112 } else {
113 suffix = base64.StdEncoding.EncodeToString(postBytes)
114 }
115
116 return []byte(fmt.Sprintf("%s %s %s\n", prefix, rawDLP, suffix))
117}
118
119func generateRawRecord(dlpType string, r *rand.Rand, domain string) []byte {
120 switch dlpType {
121 case "pci":
122 cc, _ := GenerateCreditCard(BrandVisa, r, FormatHyphenated)
123 return []byte(fmt.Sprintf("%s %02d/%02d %s %s\n", cc.Formatted, cc.ExpMonth, cc.ExpYear, cc.CVV, cc.CardholderName))
124 case "ssn":
125 return []byte(GenerateSSN(r, true) + "\n")
126 case "keys":
127 ak, sk := GenerateAWSCredentials(r)
128 ghp := GenerateGitHubPAT(r, false)
129 aiza := GenerateGoogleAIzaKey(r)
130 azure := GenerateAzureKey(r)
131 slack := GenerateSlackToken(r, true)
132 return []byte(fmt.Sprintf("AWS_KEY=%s AWS_SECRET=%s GHP=%s AIZA=%s AZURE=%s SLACK=%s\n", ak, sk, ghp, aiza, azure, slack))
133 case "hipaa":
134 med := GenerateMedicalRecord(r)
135 return []byte(FormatHL7v2(med))
136 default:
137 emp := GenerateEmployeeProfile(r, domain)
138 return []byte(fmt.Sprintf("%s|%s %s|%s|%s\n", emp.ID, emp.FirstName, emp.LastName, emp.Email, emp.SSN))
139 }
140}