— 從原理、實作到安全性考量
Steganography(隱寫術) 是一種將資訊隱藏在其他看似正常的媒介中的技術,使第三方無法察覺資料的存在。與加密(Encryption)不同,隱寫術的核心目標不是讓資料難以解讀,而是讓資料「看起來不存在」。
常見的隱藏媒介包括:
例如,一張普通的 PNG 圖片中,可能暗藏:
| 技術 | 目的 | 是否隱藏資料存在 |
|---|---|---|
| Cryptography(加密) | 保護內容 | ❌ 不隱藏 |
| Steganography(隱寫) | 隱藏存在 | ✅ 隱藏 |
| Stego + Crypto | 最高安全 | ✅ 隱藏 + 保護 |
最佳實務通常是:
先加密,再隱寫
Secret Data ↓Encryption ↓Steganography ↓Stego File最經典且最容易實作的隱寫方法是:
在 8-bit 顏色中:
原始像素:R: 10110110G: 11001001B: 11100010最低位元(LSB):
R: 1011011[0]G: 1100100[1]B: 1110001[0]我們可以把:
Secret message: 101寫入:
R: 1011011[1]G: 1100100[0]B: 1110001[1]人眼幾乎無法察覺這種微小變化。
pip install pillowfrom PIL import Imagedef encode_image(image_path, message, output_path): img = Image.open(image_path) pixels = img.load() binary_message = "".join( format(ord(c), "08b") for c in message ) + "1111111111111110" data_index = 0 for y in range(img.height): for x in range(img.width): if data_index >= len(binary_message): img.save(output_path) return r, g, b = pixels[x, y] r = (r & ~1) | int(binary_message[data_index]) data_index += 1 pixels[x, y] = (r, g, b)encode_image( "input.png", "Hidden Secret", "output.png")def decode_image(image_path): img = Image.open(image_path) pixels = img.load() binary_data = "" for y in range(img.height): for x in range(img.width): r, g, b = pixels[x, y] binary_data += str(r & 1) message = "" for i in range(0, len(binary_data), 8): byte = binary_data[i:i+8] if byte == "11111110": break message += chr(int(byte, 2)) return message圖片能藏多少資料?
公式:
Capacity = Width × Height × Channels × Bits例如:
1920 × 1080 × 3 × 1 bit約:
6,220,800 bits≈ 777,600 bytes≈ 759 KB注意:
不是整張圖片都應該用來藏資料否則容易被偵測。
不是直接覆寫 bit,而是:
+1 或 -1優點:
在 JPEG 中,資料不是直接存在像素,而是:
Discrete Cosine Transform (DCT)流程:
Image ↓DCT ↓Modify coefficients ↓JPEG這是:
更實務更隱蔽更抗壓縮類似:
無線通訊把資料:
分散到整個訊號特性:
這是:
偵測是否存在隱寫資料
常見方法:
檢查:
Pixel distributionLSB 會造成:
異常均勻分布用統計方法判斷:
是否存在人工修改現代工具使用:
CNN / Deep Learning例如:
Detect Stego Images準確率:
> 90%AES → Steganography而不是:
Plaintext → Steganography建議:
≤ 10% pixels而不是:
順序寫入JPEG 重壓縮因為:
會破壞 LSB因此:
Steganography 是雙用途技術(Dual-use Technology)steghide embed -cf image.jpg -ef secret.txtzsteg image.pngbinwalk file.jpgSteganography 的核心不是加密,而是:
讓資料看起來不存在最重要三點:
1)不可察覺(Imperceptibility)2)容量(Capacity)3)穩定性(Robustness)如果你是在以下領域,這項技術非常關鍵:
#網絡安全態勢感知 #安全架構 #安全運維 #零信任架構 #自動化網絡運維#智能流量分析#雲原生網絡