Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบเครือข่าย >> ความปลอดภัยเครือข่าย

RC4 ใน Network Security: อัลกอริทึม เข้ารหัส Stream Cipher ที่ล้าสมัยและไม่ปลอดภัย

RC4 (Rivest Cipher 4 / ARC4) คืออะไร?

RC4 เป็น Stream Cipher ที่ออกแบบโดย Ron Rivest ในปี 1987 สำหรับ RSA Security ใช้ Key ขนาด 40-256 bits ทำงานแบบ Byte-oriented รวดเร็ว เรียบง่าย กำลังใจเป็นที่นิยมอย่างกว้างขวางในอดีต

การทำงานพื้นฐาน

  1. Key Scheduling Algorithm (KSA): เริ่มต้น State Array (S-box) 256 bytes จาก Key
  2. Pseudo-Random Generation Algorithm (PRGA): สร้าง Keystream Byte ต่อเนื่อง
  3. Encryption: Ciphertext = Plaintext XOR Keystream
  4. Decryption: Plaintext = Ciphertext XOR Keystream (Symmetric)

การใช้งานในอดีต (Legacy Usage)

  • SSL/TLS: HTTPS (จนถึง TLS 1.2 - Deprecated in RFC 7465)
  • WEP (Wired Equivalent Privacy): Wi-Fi Security มาตรฐานแรก (แฮกได้ในนาที)
  • WPA (TKIP): ไม่ใช่ RC4 โดยตรง แต่ใช้ RC4 เป็น Core Cipher
  • Microsoft Office: การเข้ารหัสไฟล์เก่า (RC4 CryptoAPI)
  • BitTorrent, Skype, RDP (เก่า), SQL Server (เก่า), Kerberos (เก่า)

ช่องโหว่ร้ายแรง (Critical Vulnerabilities)

ช่องโหว่คำอธิบายผลกระทบ
Keystream Bias (Fluhrer, Mantin, Shamir - 2001)Byte เริ่มต้นของ Keystream มี Bias (ไม่สุ่ม) โดยเฉพาะ Byte ที่ 1-256WEP Cracking (Aircrack-ng) ใช้ IV เยอะๆ ได้ Key ในนาที
RC4 NOMORE (2015)บีาสใน Keystream ทำให้ Recover Plaintext ได้จาก Ciphertext จำนวนมาก (HTTPS Cookies)Session Hijacking, Cookie Theft ใน TLS/SSL
Bar Mitzvah Attack (2015)Bias ใน Byte แรกๆ ของ Keystream ใช้โจมตี TLSDecrypt HTTPS Traffic
Related Key AttackKey ที่คล้ายกัน สร้าง Keystream ที่เกี่ยวข้องกันKey Recovery
No Authentication/IntegrityStream Cipher ต้องการ MAC แยก (EtM) ไม่มี Built-in AEADBit-flipping, Malleability

สถานะปัจจุบัน: DEPRECATED / PROHIBITED

  • RFC 7465 (2015): Prohibiting RC4 in TLS
  • PCI DSS: ห้ามใช้ RC4
  • NIST SP 800-131A: Disallowed หลัง 2015
  • Browser Vendors: Chrome, Firefox, Edge, Safari ลบ RC4 Support แล้ว
  • TLS 1.3: ไม่รองรับ RC4 (เฉพาะ AEAD: AES-GCM, ChaCha20-Poly1305)

ตัวอย่างโค้ด Python (เพื่อการศึกษาเท่านั้น - ห้ามใช้จริง)

def rc4_ksa(key):
    S = list(range(256))
    j = 0
    for i in range(256):
        j = (j + S[i] + key[i % len(key)]) % 256
        S[i], S[j] = S[j], S[i]
    return S

def rc4_prga(S):
    i = j = 0
    while True:
        i = (i + 1) % 256
        j = (j + S[i]) % 256
        S[i], S[j] = S[j], S[i]
        yield S[(S[i] + S[j]) % 256]

def rc4_encrypt(key, plaintext):
    S = rc4_ksa(key)
    keystream = rc4_prga(S)
    return bytes([c ^ next(keystream) for c in plaintext])

ตัวเลือกแทนที่ (Modern Alternatives)

AlgorithmTypeใช้ใน
AES-GCMAEAD Block CipherTLS 1.2/1.3, IPsec, SSH, WireGuard
ChaCha20-Poly1305AEAD Stream CipherTLS 1.2/1.3, WireGuard, SSH, QUIC
AES-CCMAEAD Block CipherIoT, 802.11i (WPA2), TLS
ASCONLightweight AEADNIST Lightweight Crypto Winner (IoT)

สรุป

RC4 ต้องห้ามใช้ในระบบใหม่ทุกประเภท หากพบใน Legacy System ให้วางแผน Migration ทันที ใช้ AES-GCM หรือ ChaCha20-Poly1305 แทน ซึ่งให้ Confidentiality + Integrity + Authenticity (AEAD) ในอัลกอริทึมเดียว