[SHEHZADE//ABDULLAH ANSARI]
Red Team Consultant @ Google | MS in Cybersecurity @ NYU
● 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)
164 lines · 5.2 KB
| 1 | package dlp |
| 2 | |
| 3 | import ( |
| 4 | "encoding/base64" |
| 5 | "encoding/json" |
| 6 | "fmt" |
| 7 | mrand "math/rand" |
| 8 | "strings" |
| 9 | ) |
| 10 | |
| 11 | // GenerateAWSCredentials generates an Access Key ID and Secret Key. |
| 12 | func GenerateAWSCredentials(r *mrand.Rand) (string, string) { |
| 13 | const idCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" |
| 14 | var id [16]byte |
| 15 | for i := 0; i < 16; i++ { |
| 16 | id[i] = idCharset[r.Intn(len(idCharset))] |
| 17 | } |
| 18 | accessKey := "AKIA" + string(id[:]) |
| 19 | |
| 20 | const secretCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/+" |
| 21 | var secret [40]byte |
| 22 | for i := 0; i < 40; i++ { |
| 23 | secret[i] = secretCharset[r.Intn(len(secretCharset))] |
| 24 | } |
| 25 | return accessKey, string(secret[:]) |
| 26 | } |
| 27 | |
| 28 | // GenerateGitHubPAT generates classic or fine-grained GitHub tokens. |
| 29 | func GenerateGitHubPAT(r *mrand.Rand, fineGrained bool) string { |
| 30 | const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
| 31 | if !fineGrained { |
| 32 | var b [36]byte |
| 33 | for i := 0; i < 36; i++ { |
| 34 | b[i] = charset[r.Intn(len(charset))] |
| 35 | } |
| 36 | return "ghp_" + string(b[:]) |
| 37 | } |
| 38 | var b [82]byte |
| 39 | for i := 0; i < 82; i++ { |
| 40 | b[i] = charset[r.Intn(len(charset))] |
| 41 | } |
| 42 | return "github_pat_" + string(b[:]) |
| 43 | } |
| 44 | |
| 45 | // GenerateSlackToken generates xoxb bot token or xoxp user token. |
| 46 | func GenerateSlackToken(r *mrand.Rand, isBot bool) string { |
| 47 | const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
| 48 | d1 := 100000000000 + r.Int63n(899999999999) |
| 49 | d2 := 1000000000000 + r.Int63n(8999999999999) |
| 50 | if isBot { |
| 51 | var b [24]byte |
| 52 | for i := 0; i < 24; i++ { |
| 53 | b[i] = charset[r.Intn(len(charset))] |
| 54 | } |
| 55 | return fmt.Sprintf("xoxb-%d-%d-%s", d1, d2, string(b[:])) |
| 56 | } |
| 57 | d3 := 1000000000000 + r.Int63n(8999999999999) |
| 58 | var b [30]byte |
| 59 | for i := 0; i < 30; i++ { |
| 60 | b[i] = charset[r.Intn(len(charset))] |
| 61 | } |
| 62 | return fmt.Sprintf("xoxp-%d-%d-%d-%s", d1, d2, d3, string(b[:])) |
| 63 | } |
| 64 | |
| 65 | // GenerateRSAPrivateKeyBlock creates an authentic formatted PEM block. |
| 66 | func GenerateRSAPrivateKeyBlock(r *mrand.Rand) string { |
| 67 | raw := make([]byte, 1192) // typical DER size for 2048-bit RSA key |
| 68 | for i := range raw { |
| 69 | raw[i] = byte(r.Intn(256)) |
| 70 | } |
| 71 | // Set valid ASN.1 sequence headers |
| 72 | raw[0] = 0x30 |
| 73 | raw[1] = 0x82 |
| 74 | b64 := base64.StdEncoding.EncodeToString(raw) |
| 75 | |
| 76 | var sb strings.Builder |
| 77 | sb.WriteString("-----BEGIN RSA PRIVATE KEY-----\n") |
| 78 | for i := 0; i < len(b64); i += 64 { |
| 79 | end := i + 64 |
| 80 | if end > len(b64) { |
| 81 | end = len(b64) |
| 82 | } |
| 83 | sb.WriteString(b64[i:end] + "\n") |
| 84 | } |
| 85 | sb.WriteString("-----END RSA PRIVATE KEY-----\n") |
| 86 | return sb.String() |
| 87 | } |
| 88 | |
| 89 | // GenerateGoogleAIzaKey generates a valid 39-character Google API key. |
| 90 | func GenerateGoogleAIzaKey(r *mrand.Rand) string { |
| 91 | const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-" |
| 92 | var b [35]byte |
| 93 | for i := 0; i < 35; i++ { |
| 94 | b[i] = charset[r.Intn(len(charset))] |
| 95 | } |
| 96 | return "AIza" + string(b[:]) |
| 97 | } |
| 98 | |
| 99 | // GenerateAzureKey generates an authentic 88-character Azure Base64 Storage Key (64 random bytes). |
| 100 | func GenerateAzureKey(r *mrand.Rand) string { |
| 101 | raw := make([]byte, 64) |
| 102 | for i := range raw { |
| 103 | raw[i] = byte(r.Intn(256)) |
| 104 | } |
| 105 | return base64.StdEncoding.EncodeToString(raw) |
| 106 | } |
| 107 | |
| 108 | // GenerateAzureConnectionString generates an authentic Azure Storage Connection String. |
| 109 | func GenerateAzureConnectionString(r *mrand.Rand, accountName string) string { |
| 110 | if accountName == "" { |
| 111 | accountName = fmt.Sprintf("storage%06d", r.Intn(1000000)) |
| 112 | } |
| 113 | key := GenerateAzureKey(r) |
| 114 | return fmt.Sprintf("DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;EndpointSuffix=core.windows.net", accountName, key) |
| 115 | } |
| 116 | |
| 117 | // GenerateOpenAIToken generates an OpenAI project key. |
| 118 | func GenerateOpenAIToken(r *mrand.Rand) string { |
| 119 | const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-" |
| 120 | var b [48]byte |
| 121 | for i := 0; i < 48; i++ { |
| 122 | b[i] = charset[r.Intn(len(charset))] |
| 123 | } |
| 124 | return "sk-proj-" + string(b[:]) |
| 125 | } |
| 126 | |
| 127 | // GenerateAnthropicToken generates an Anthropic API key. |
| 128 | func GenerateAnthropicToken(r *mrand.Rand) string { |
| 129 | const charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-" |
| 130 | var b [88]byte |
| 131 | for i := 0; i < 88; i++ { |
| 132 | b[i] = charset[r.Intn(len(charset))] |
| 133 | } |
| 134 | return "sk-ant-api03-" + string(b[:]) |
| 135 | } |
| 136 | |
| 137 | // GenerateGCPServiceAccountKey generates an authentic GCP Service Account JSON keyfile. |
| 138 | func GenerateGCPServiceAccountKey(r *mrand.Rand, projectID string) (string, error) { |
| 139 | if projectID == "" { |
| 140 | projectID = fmt.Sprintf("corp-prod-%05d", r.Intn(100000)) |
| 141 | } |
| 142 | keyID := fmt.Sprintf("%040x", r.Uint64()) |
| 143 | pemKey := GenerateRSAPrivateKeyBlock(r) |
| 144 | clientEmail := fmt.Sprintf("sa-contraband@%s.iam.gserviceaccount.com", projectID) |
| 145 | clientID := fmt.Sprintf("1%020d", r.Int63n(899999999999999999)) |
| 146 | |
| 147 | keyMap := map[string]string{ |
| 148 | "type": "service_account", |
| 149 | "project_id": projectID, |
| 150 | "private_key_id": keyID, |
| 151 | "private_key": pemKey, |
| 152 | "client_email": clientEmail, |
| 153 | "client_id": clientID, |
| 154 | "auth_uri": "https://accounts.google.com/o/oauth2/auth", |
| 155 | "token_uri": "https://oauth2.googleapis.com/token", |
| 156 | "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", |
| 157 | "client_x509_cert_url": fmt.Sprintf("https://www.googleapis.com/robot/v1/metadata/x509/%s", clientEmail), |
| 158 | } |
| 159 | b, err := json.MarshalIndent(keyMap, "", " ") |
| 160 | if err != nil { |
| 161 | return "", err |
| 162 | } |
| 163 | return string(b), nil |
| 164 | } |