[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)
174 lines · 5.2 KB
| 1 | package evasion |
| 2 | |
| 3 | import ( |
| 4 | "encoding/binary" |
| 5 | "errors" |
| 6 | "fmt" |
| 7 | "math" |
| 8 | "math/rand" |
| 9 | ) |
| 10 | |
| 11 | // GenerateProceduralWAV generates a valid 16-bit stereo PCM WAV audio file with realistic tone + noise. |
| 12 | func GenerateProceduralWAV(durationSeconds int, sampleRate int, seed int64) []byte { |
| 13 | if sampleRate <= 0 { |
| 14 | sampleRate = 44100 |
| 15 | } |
| 16 | if durationSeconds <= 0 { |
| 17 | durationSeconds = 2 |
| 18 | } |
| 19 | |
| 20 | numChannels := 2 |
| 21 | bitsPerSample := 16 |
| 22 | bytesPerSample := bitsPerSample / 8 |
| 23 | blockAlign := numChannels * bytesPerSample |
| 24 | byteRate := sampleRate * blockAlign |
| 25 | totalSamples := durationSeconds * sampleRate |
| 26 | dataSize := totalSamples * blockAlign |
| 27 | fileSize := 36 + dataSize |
| 28 | |
| 29 | buf := make([]byte, 44+dataSize) |
| 30 | |
| 31 | // RIFF header |
| 32 | copy(buf[0:4], "RIFF") |
| 33 | binary.LittleEndian.PutUint32(buf[4:8], uint32(fileSize)) |
| 34 | copy(buf[8:12], "WAVE") |
| 35 | |
| 36 | // fmt subchunk |
| 37 | copy(buf[12:16], "fmt ") |
| 38 | binary.LittleEndian.PutUint32(buf[16:20], 16) // PCM format size |
| 39 | binary.LittleEndian.PutUint16(buf[20:22], 1) // audio format 1 = PCM |
| 40 | binary.LittleEndian.PutUint16(buf[22:24], uint16(numChannels)) |
| 41 | binary.LittleEndian.PutUint32(buf[24:28], uint32(sampleRate)) |
| 42 | binary.LittleEndian.PutUint32(buf[28:32], uint32(byteRate)) |
| 43 | binary.LittleEndian.PutUint16(buf[32:34], uint16(blockAlign)) |
| 44 | binary.LittleEndian.PutUint16(buf[34:36], uint16(bitsPerSample)) |
| 45 | |
| 46 | // data subchunk |
| 47 | copy(buf[36:40], "data") |
| 48 | binary.LittleEndian.PutUint32(buf[40:44], uint32(dataSize)) |
| 49 | |
| 50 | // Synthesize gentle ambient harmonic tone (e.g. 440 Hz + 880 Hz) with dither |
| 51 | rng := rand.New(rand.NewSource(seed)) |
| 52 | freq1 := 440.0 |
| 53 | freq2 := 880.0 |
| 54 | |
| 55 | for i := 0; i < totalSamples; i++ { |
| 56 | t := float64(i) / float64(sampleRate) |
| 57 | v1 := math.Sin(2.0*math.Pi*freq1*t) * 6000.0 |
| 58 | v2 := math.Sin(2.0*math.Pi*freq2*t) * 2000.0 |
| 59 | noise := (rng.Float64() - 0.5) * 200.0 |
| 60 | sampleVal := int16(v1 + v2 + noise) |
| 61 | |
| 62 | // Left channel |
| 63 | offset := 44 + i*blockAlign |
| 64 | binary.LittleEndian.PutUint16(buf[offset:offset+2], uint16(sampleVal)) |
| 65 | // Right channel (slight stereo pan) |
| 66 | binary.LittleEndian.PutUint16(buf[offset+2:offset+4], uint16(sampleVal+int16(noise))) |
| 67 | } |
| 68 | |
| 69 | return buf |
| 70 | } |
| 71 | |
| 72 | // EmbedWAV embeds payload into 16-bit PCM WAV samples using 1-bit LSB. |
| 73 | func EmbedWAV(wavData []byte, payload []byte) ([]byte, error) { |
| 74 | if len(wavData) < 44 || string(wavData[0:4]) != "RIFF" || string(wavData[8:12]) != "WAVE" { |
| 75 | return nil, errors.New("invalid WAV file header") |
| 76 | } |
| 77 | |
| 78 | // Find data chunk |
| 79 | offset := 12 |
| 80 | dataOffset := -1 |
| 81 | dataSize := 0 |
| 82 | for offset+8 <= len(wavData) { |
| 83 | subID := string(wavData[offset : offset+4]) |
| 84 | subSize := int(binary.LittleEndian.Uint32(wavData[offset+4 : offset+8])) |
| 85 | if subID == "data" { |
| 86 | dataOffset = offset + 8 |
| 87 | dataSize = subSize |
| 88 | break |
| 89 | } |
| 90 | offset += 8 + subSize |
| 91 | } |
| 92 | |
| 93 | if dataOffset == -1 || dataOffset+dataSize > len(wavData) { |
| 94 | return nil, errors.New("data subchunk not found in WAV") |
| 95 | } |
| 96 | |
| 97 | total16BitSamples := dataSize / 2 |
| 98 | maxCapacity := (total16BitSamples / 8) - 4 |
| 99 | if len(payload) > maxCapacity { |
| 100 | return nil, fmt.Errorf("payload size (%d bytes) exceeds WAV capacity (%d bytes)", len(payload), maxCapacity) |
| 101 | } |
| 102 | |
| 103 | framed := make([]byte, 4+len(payload)) |
| 104 | binary.BigEndian.PutUint32(framed[0:4], uint32(len(payload))) |
| 105 | copy(framed[4:], payload) |
| 106 | |
| 107 | out := make([]byte, len(wavData)) |
| 108 | copy(out, wavData) |
| 109 | |
| 110 | totalBits := len(framed) * 8 |
| 111 | for bitIdx := 0; bitIdx < totalBits; bitIdx++ { |
| 112 | sampleByteOffset := dataOffset + bitIdx*2 |
| 113 | sample := int16(binary.LittleEndian.Uint16(out[sampleByteOffset : sampleByteOffset+2])) |
| 114 | |
| 115 | payloadBit := (framed[bitIdx/8] >> (7 - (bitIdx % 8))) & 0x01 |
| 116 | sample = (sample &^ 1) | int16(payloadBit) |
| 117 | binary.LittleEndian.PutUint16(out[sampleByteOffset:sampleByteOffset+2], uint16(sample)) |
| 118 | } |
| 119 | |
| 120 | return out, nil |
| 121 | } |
| 122 | |
| 123 | // ExtractWAV extracts payload embedded via EmbedWAV. |
| 124 | func ExtractWAV(wavData []byte) ([]byte, error) { |
| 125 | if len(wavData) < 44 || string(wavData[0:4]) != "RIFF" || string(wavData[8:12]) != "WAVE" { |
| 126 | return nil, errors.New("invalid WAV file header") |
| 127 | } |
| 128 | |
| 129 | offset := 12 |
| 130 | dataOffset := -1 |
| 131 | dataSize := 0 |
| 132 | for offset+8 <= len(wavData) { |
| 133 | subID := string(wavData[offset : offset+4]) |
| 134 | subSize := int(binary.LittleEndian.Uint32(wavData[offset+4 : offset+8])) |
| 135 | if subID == "data" { |
| 136 | dataOffset = offset + 8 |
| 137 | dataSize = subSize |
| 138 | break |
| 139 | } |
| 140 | offset += 8 + subSize |
| 141 | } |
| 142 | |
| 143 | if dataOffset == -1 { |
| 144 | return nil, errors.New("data subchunk not found in WAV") |
| 145 | } |
| 146 | |
| 147 | // Extract 32 bits (4 bytes) length header |
| 148 | var lengthBuf [4]byte |
| 149 | for bitIdx := 0; bitIdx < 32; bitIdx++ { |
| 150 | sampleByteOffset := dataOffset + bitIdx*2 |
| 151 | sample := binary.LittleEndian.Uint16(wavData[sampleByteOffset : sampleByteOffset+2]) |
| 152 | bit := sample & 0x01 |
| 153 | lengthBuf[bitIdx/8] |= byte(bit << (7 - (bitIdx % 8))) |
| 154 | } |
| 155 | |
| 156 | payloadLen := int(binary.BigEndian.Uint32(lengthBuf[:])) |
| 157 | total16BitSamples := dataSize / 2 |
| 158 | maxCapacity := (total16BitSamples / 8) - 4 |
| 159 | if payloadLen <= 0 || payloadLen > maxCapacity { |
| 160 | return nil, fmt.Errorf("invalid extracted WAV payload length %d (capacity: %d)", payloadLen, maxCapacity) |
| 161 | } |
| 162 | |
| 163 | payload := make([]byte, payloadLen) |
| 164 | totalBits := (4 + payloadLen) * 8 |
| 165 | for currBit := 32; currBit < totalBits; currBit++ { |
| 166 | sampleByteOffset := dataOffset + currBit*2 |
| 167 | sample := binary.LittleEndian.Uint16(wavData[sampleByteOffset : sampleByteOffset+2]) |
| 168 | bit := sample & 0x01 |
| 169 | targetBit := currBit - 32 |
| 170 | payload[targetBit/8] |= byte(bit << (7 - (targetBit % 8))) |
| 171 | } |
| 172 | |
| 173 | return payload, nil |
| 174 | } |