SlideShare uma empresa Scribd logo
1 de 150
密碼學漏洞與他們的產地
zuan@chroot.org
Who am I
- Zuan
- chroot 讀書會成員
- 什麼都略懂一點,但什麼都不精通
- 愛玩資訊跟電子領域的各種事務
- 興趣是騎腳踏車跟買學生證
Content
- 非對稱式演算法
- 對稱式演算法
- 雜湊
- 其他
這邊有人沒有聽過 RSA 的嗎 ?
請舉個手
c ≡ ne
(mod (N))
n ≡ cd
(mod (N))
ed ≡ 1 (mod φ(N))
c -> 密文
n -> 明文
(e,N) -> 公鑰
(d,N) -> 私鑰
一般為了加速計算, e 會取很小
(e=65537 or e=17 or e=3)
如果 ne
< N 且 e = 3
那不是開方根就能解密了?
...
OK ,那如果效能不是問題,我 e 選大一
點總可以吧?
如果要加密 0 或 1
0^e = 0
1^e = 1
...
Encrypt(‘A’) = YCD6WGtUMNDedQ2HjC5KzSVT
Encrypt(‘B’) = REfHH3SCzed6jkRhP6JZwytH
Encrypt(‘C’) = aSWP4Z6cX2VYWMxwA9bGMKRA
Encrypt(‘D’) = sRuHR8t8Vmy3th8Gf2RAVfkz
Encrypt(‘E’) = F4ahebRHXUyzzeNgcBzN4r26
Encrypt(t) = aSWP4Z6cX2VYWMxwA9bGMKRA
t = ?
就說該都猜 C
一個加密演算法不該有那麼多毛
以上這些弱點都可以透過 Padding 來解決
加解密: PKCS #1 v1.5, OAEP
簽章: PKCS #1 v1.5, PSS
Plaintext n
Padded Plaintext n
Ciphertext n
OAEP
RSA
如果自己實作 Signature Padding
應依照標準驗證簽章
Python RSA 出過類似包
CVE-2016-1494
[ 問掛 ] 有沒有 RSA 很慢的八卦?
2048 bit/op * 768.3 op/s ≈ 200 kB/s
2048 bit/op * 26270.6 op/s ≈ 6.7 MB/s
撥接喔?!╯ -____-) ~═╩════╩═╯
加解密 (AES): 75~90 MB/s
簽章 (SHA2): 30~300 MB/s
RSA iPad AES/SHA!
RSA Weak Key
RSA 的 Key 不是找兩個大質數就夠了
CVE-2008-0166
亂數產生器不夠亂,某些質數出現機率高
=> 直接猜那些質數可破密
=> 拿一堆 N 來 GCD 也可以破一發
( shared factor)
N1 = p1*q1
N2 = p2*q2
若 p1 = p2, p1 = GCD(N1,N2)
Weiner’s Attack
不常見,記得 d > ⅓ N¼
就好
Pollard p-1 Factorization
也不常見,建議 (p-1)/2 也要是質數
TL;DR 懶人包 : 生 Key? OpenSSL
[ 問掛 ] 有沒有 RSA 很慢的八卦?
...
你有聽過橢圓曲線嗎?
對稱 RSA ECC
80 1024 160
112 2048 224
128 3072 256
192 7680 384
總時間上,橢圓曲線遠比同級的 RSA 快
ECDSA 256 bit Public Key:
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyN
TYAAABBBCv5hlgEJBGfQfF/4RdBDMv0hiaeNbwqwkyW4n
tYsUUroqqFQMROgYSdHr2bqmX0BCX87l95Hynh2nUPxbO
vWtg=
RSA 2048 bit Public Key:
AAAAB3NzaC1yc2EAAAADAQABAAABAQD4XK2ooKXQZFIrz
Tlu6sIVOTdnLDcKc1Qn/WvrGCBFRx5jTfKlJflCVb0Bdh
PayaYwibMzu87rn6IzfKdc3yEivcRIKJ0Vv/z86jjbK1V
7zlTXyhvp0I2IUgL46HTFQVykn88dcj0CX0vuuITfr+sH
jSLG8icBrZHOoiAXYI8xdbZFZ5BZFp5IbeD5QZ2BNotK1
SkMAt1ls2AZD48toBoX0lMiWf7pufdviQw8GIkQo7Jm52
QDFPj2QPUocVLeqCvzreWgu0SSfaIEDUMScM9alS/OBaj
rorQI9/eT85H57sv3che8ascbwN48EpQngBwwzylUl0Wm
sjYneybGW8xT
Key 小就是爽啦
下次也考慮下 ECC 系列吧
但如果 Public 端為嵌入式,則可考慮
RSA
如果用 ECDSA 一定要記得
不要 Sony
Sony 進行 PS3 的 ECDSA 簽章時每次 k 都
一樣
兩次 k 一樣的簽章 = 洩漏私鑰
RSA 有 Side Channel 問題
想想 Modular Exponentiation
def modexp( base, exp, mod ):
out = base if (exp[0] == 1) else 1
for i in range(1,len(exp)):
out = (out * out) % mod;
if exp[i] == 1:
out = (out * base) % mod
return out
def modexp( base, exp, mod ):
out = base if (exp[0] == 1) else 1
for i in range(1,len(exp)):
out = (out * out) % mod;
if exp[i] == 1:
out = (out * base) % mod
return out
量測 CPU Cache Hit/ 執行時間 / 使用功
率可以看出這步有沒有執行
執行在同一顆 CPU 的其他程式或是對
CPU 有實體權限的攻擊者有機會破密
RSA 要避免類似 Side channel 較麻煩
ECC 也有類似問題 (Double or add)
進幾年 HITCON 有示範過
bit 0 1 2 3 4 ...
0 1 1 1 1 1 ...
1 M^1 M^2 M^4 M^8 M^16 ...
如果有這考量,可以用現成的 Library ,
或是用 Ed25519
玩夠非對稱式的,來聊聊對稱式的吧
用過 Stream Cipher 吧?
RC4, OFB/CTR Mode 的 Block Cipher,
Salsa20, ChaCha20
Stream Cipher 的 IV/Nounce 每次加密一
定要不一樣,否則加密多少,就能解密多
少
Win32/Dircrypt.A
如果有使用某些舊的 Block Cipher,
需要注意 Weak Key
尤其是 Blowfish
AES 沒這煩惱,把把都是好 Key
Block Cipher 跟 RSA 一樣不能單用
要搭配 Cipher Mode of Operation
看維基百科秒懂
那不然要用什麼?
大多人會推薦 CBC
Source: Wikipedia
但是 CBC 有 Padding Oracle 問題
解密時如果 Padding 不對,不能讓對方知
道
if not VerifyPadding( … ):
// ERROR
return
if not VerifyHMAC( … ):
// ERROR
return
除了 CBC 以外,還有什麼可以用?
看看 Google 用什麼吧
[ 問掛 ] 有沒有 GCM 的八卦
GCM 其實很好用
內帶驗證,且效能高
考慮拿 GCM 取代 CBC+HMAC
Hash
還在用 md5 的舉手
md5 跟 sha1 都已經過時
讓他們安息吧
大家密碼都怎麼存?
a)明碼
md5
sha1
sha256/sha512
md5+salt
sha1+salt
sha256/sha512+salt
salt 可以避免 Rainbow Table
不要再猜了,答案是以上階非
Source:
https://gist.github.com/epixoip/973da7352f4cc005746c627527e4d073
hash 的設計都是在安全的狀況下盡量快
所以要用另一類專門的函數 -- KDF
Key Derivation Function
設計就是要慢
Source:
https://gist.github.com/epixoip/973da7352f4cc005746c627527e4d073
考慮使用 PBKDF2, scrypt, bcrypt
內建 Salt, 可調運算強度
純 Hash 不應該拿來做驗證
不少 Hash 有 Length Extension 的
bug feature
給 H(A), 不知道 A, 可以求 H(A+B)
H(secret || msg) 不安全
如果有驗證需求,請用 HMAC
HMAC = H( K1 || H(K2 || M) )
其他
亂數 ?
rand()
當然不是
如果需要少量的亂數 ( 生 Key)
就跟系統拿 Entropy
*nix: /dev/random
Win: RtlGenRandom()
/dev/random 是稀有資源
urandom 沒有快到哪裡去
需要大量亂數 ? 用 entropy 去 seed
PRNG
Hash_DBRG, CTR_DBRG
不要 Dual_EC_DBRG
封包大小有 Side Channel 問題
透過 ssh tunnel 上網
Google 台科大官網
不難看出誰是誰
GFW 就是這樣抓 VPN 的
若要避免,可以用 obfs4/ScrambleSuit
語音也有一樣問題
HTTPS 很好用
但是它其實會洩漏 Server 的 Domain
最後,東西用完記得收
有些勒索軟體可以用刪除復原 / 硬碟救援
工具還原
因為他們檔案用完沒有 Shred
*nix: shred
win: sdelete
記憶體也可能殘留,用完記得複寫再釋放
結論
能用現成整套的,就用
HTTPS/TLS, SSH, GnuPG
如果需要單獨使用密碼學的元素
請用現成 Library
Crypto++, CryptoJS, libsodium… etc
END
謝謝大家
小抄 / 懶人包
1. 非對稱加密相關問題與建議
1a. 非對稱式加密應該搭配對稱式加密使用。
1b. RSA 不能直接用,需要搭配專門的 Padding Scheme 。
1c. RSA 存在 Weak Key 。 (Pollard p-1 Factorization, Shared Factor, Weiner) 。
1d. 可以考慮 ECC 系列演算法,因為安全性下,需要較少運算。
1e. RSA 跟 ECC 都存在 Timing/Power Side Channel ,如果要避免,
可以考慮 Ed25519 。
1f. ECDSA 每次簽章的 k 必須隨機不重複。 (PS3 因此被破解 )
1g. 簽章驗證應該依照標準檢測所有參數。 (ie. CVE-2016-1494)
2. 對稱演算法相關問題與建議
2a. Stream Cipher 必須有 Nounce ,且必須每次不一樣。
2b. 部份 Blocker Cipher 有 Weak Key 。 ( 例如 Blowfish) 。
2c. Block Cipher 應注意 Cipher Mode ,不該單純用 ECB 。
2d. Block Cipher 的 Padding Oracle 問題。
2e. Block Cipher Mode 建議使用 GCM 模式,因為性能較優異且帶有驗證功能。
3. Hash 相關問題與建議
3a. md5/sha1 應淘汰。
3b. 密碼不應該用單純 Hash 存,應該使用 PBKDF 或 scrypt 。
3c. 注意 Length Extension Attack ,因此 HMAC 請照標準 HMAC 格式走。
4. 其他
4a. 亂數應該使用標準的亂數演算法 (NIST 系列, DUAL_EC_DRBG 除外 ) 。
4b. 亂數應確保有足夠的 Entropy 。
4c. 封包的大小與 Timing 有 Side Channel 。
4d. 承 4c ,該漏洞可利用於破解通話加密,以及分析 TLS 裡面瀏覽的網站內容。
4e. TLS 有 SNI 會洩漏你瀏覽哪個網站。
4f. 除非必要,建議使用現成,常用的套件或協定 (ie. OpenSSL+TLS)
4g. 注意殘留,硬碟 / 記憶體需要 Shred ,如果使用現成套件,用完要釋放。

Mais conteúdo relacionado

Mais procurados

EDR, ETDR, Next Gen AV is all the rage, so why am I ENRAGED?
EDR, ETDR, Next Gen AV is all the rage, so why am I ENRAGED?EDR, ETDR, Next Gen AV is all the rage, so why am I ENRAGED?
EDR, ETDR, Next Gen AV is all the rage, so why am I ENRAGED?Michael Gough
 
台科大網路鑑識課程 封包分析及中繼站追蹤
台科大網路鑑識課程 封包分析及中繼站追蹤台科大網路鑑識課程 封包分析及中繼站追蹤
台科大網路鑑識課程 封包分析及中繼站追蹤jack51706
 
Overview on Cryptography and Network Security
Overview on Cryptography and Network SecurityOverview on Cryptography and Network Security
Overview on Cryptography and Network SecurityDr. Rupa Ch
 
Become A Security Master
Become A Security MasterBecome A Security Master
Become A Security MasterChong-Kuan Chen
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelPeter Hlavaty
 
Windows環境でのgitまとめ(2016.8)
Windows環境でのgitまとめ(2016.8)Windows環境でのgitまとめ(2016.8)
Windows環境でのgitまとめ(2016.8)Tadahiro Ishisaka
 
BLS署名の実装とその応用
BLS署名の実装とその応用BLS署名の実装とその応用
BLS署名の実装とその応用MITSUNARI Shigeo
 
Got Your PW - 一場入門資安的微旅行
Got Your PW - 一場入門資安的微旅行Got Your PW - 一場入門資安的微旅行
Got Your PW - 一場入門資安的微旅行Allen Chou
 
Testing in Production, Deploy on Fridays
Testing in Production, Deploy on FridaysTesting in Production, Deploy on Fridays
Testing in Production, Deploy on FridaysYi-Feng Tzeng
 
前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧Chu-Siang Lai
 
ELC21: VM-to-VM Communication Mechanisms for Embedded
ELC21: VM-to-VM Communication Mechanisms for EmbeddedELC21: VM-to-VM Communication Mechanisms for Embedded
ELC21: VM-to-VM Communication Mechanisms for EmbeddedStefano Stabellini
 
あるmmapの話
あるmmapの話あるmmapの話
あるmmapの話nullnilaki
 
TDOH Conf-APP檢測之經驗分享
TDOH Conf-APP檢測之經驗分享TDOH Conf-APP檢測之經驗分享
TDOH Conf-APP檢測之經驗分享Tzu-Ting(Fei) Lin
 
Rules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynoteRules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynoteMarkDowd13
 
Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Ahmed El-Arabawy
 
Windows Privilege Escalation
Windows Privilege EscalationWindows Privilege Escalation
Windows Privilege EscalationRiyaz Walikar
 
以開源軟體打造新創公司基礎資訊建設 [2020/08/01] @COSCUP2020
以開源軟體打造新創公司基礎資訊建設 [2020/08/01] @COSCUP2020以開源軟體打造新創公司基礎資訊建設 [2020/08/01] @COSCUP2020
以開源軟體打造新創公司基礎資訊建設 [2020/08/01] @COSCUP2020Jason Cheng
 
Python2.x の input 関数に RCE 脆弱性がある話
Python2.x の input 関数にRCE 脆弱性がある話Python2.x の input 関数にRCE 脆弱性がある話
Python2.x の input 関数に RCE 脆弱性がある話xryuseix
 

Mais procurados (20)

EDR, ETDR, Next Gen AV is all the rage, so why am I ENRAGED?
EDR, ETDR, Next Gen AV is all the rage, so why am I ENRAGED?EDR, ETDR, Next Gen AV is all the rage, so why am I ENRAGED?
EDR, ETDR, Next Gen AV is all the rage, so why am I ENRAGED?
 
台科大網路鑑識課程 封包分析及中繼站追蹤
台科大網路鑑識課程 封包分析及中繼站追蹤台科大網路鑑識課程 封包分析及中繼站追蹤
台科大網路鑑識課程 封包分析及中繼站追蹤
 
SQLite の暗号化
SQLite の暗号化SQLite の暗号化
SQLite の暗号化
 
Overview on Cryptography and Network Security
Overview on Cryptography and Network SecurityOverview on Cryptography and Network Security
Overview on Cryptography and Network Security
 
Become A Security Master
Become A Security MasterBecome A Security Master
Become A Security Master
 
Metasploitable
MetasploitableMetasploitable
Metasploitable
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows Kernel
 
Windows環境でのgitまとめ(2016.8)
Windows環境でのgitまとめ(2016.8)Windows環境でのgitまとめ(2016.8)
Windows環境でのgitまとめ(2016.8)
 
BLS署名の実装とその応用
BLS署名の実装とその応用BLS署名の実装とその応用
BLS署名の実装とその応用
 
Got Your PW - 一場入門資安的微旅行
Got Your PW - 一場入門資安的微旅行Got Your PW - 一場入門資安的微旅行
Got Your PW - 一場入門資安的微旅行
 
Testing in Production, Deploy on Fridays
Testing in Production, Deploy on FridaysTesting in Production, Deploy on Fridays
Testing in Production, Deploy on Fridays
 
前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧
 
ELC21: VM-to-VM Communication Mechanisms for Embedded
ELC21: VM-to-VM Communication Mechanisms for EmbeddedELC21: VM-to-VM Communication Mechanisms for Embedded
ELC21: VM-to-VM Communication Mechanisms for Embedded
 
あるmmapの話
あるmmapの話あるmmapの話
あるmmapの話
 
TDOH Conf-APP檢測之經驗分享
TDOH Conf-APP檢測之經驗分享TDOH Conf-APP檢測之經驗分享
TDOH Conf-APP檢測之經驗分享
 
Rules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynoteRules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynote
 
Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities
 
Windows Privilege Escalation
Windows Privilege EscalationWindows Privilege Escalation
Windows Privilege Escalation
 
以開源軟體打造新創公司基礎資訊建設 [2020/08/01] @COSCUP2020
以開源軟體打造新創公司基礎資訊建設 [2020/08/01] @COSCUP2020以開源軟體打造新創公司基礎資訊建設 [2020/08/01] @COSCUP2020
以開源軟體打造新創公司基礎資訊建設 [2020/08/01] @COSCUP2020
 
Python2.x の input 関数に RCE 脆弱性がある話
Python2.x の input 関数にRCE 脆弱性がある話Python2.x の input 関数にRCE 脆弱性がある話
Python2.x の input 関数に RCE 脆弱性がある話
 

Semelhante a 密碼學漏洞與他們的產地 Crypto fail and where to find them

HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享Chong-Kuan Chen
 
Introduction of Reverse Engineering
Introduction of Reverse EngineeringIntroduction of Reverse Engineering
Introduction of Reverse EngineeringYC Ling
 
Python学习笔记
Python学习笔记Python学习笔记
Python学习笔记Lingfei Kong
 
introduce RSA
introduce RSAintroduce RSA
introduce RSASoL ymx
 
Talking about exploit writing
Talking about exploit writingTalking about exploit writing
Talking about exploit writingsbha0909
 
R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探Sean Yu
 
Arduino L2
Arduino L2Arduino L2
Arduino L2mmiwwcom
 
從技術面簡介線上遊戲外掛
從技術面簡介線上遊戲外掛從技術面簡介線上遊戲外掛
從技術面簡介線上遊戲外掛John L Chen
 
人机对弈编程概述
人机对弈编程概述人机对弈编程概述
人机对弈编程概述勇浩 赖
 
JCConf 2023 - 深入淺出 Java 21 功能
JCConf 2023 - 深入淺出 Java 21 功能JCConf 2023 - 深入淺出 Java 21 功能
JCConf 2023 - 深入淺出 Java 21 功能Joseph Kuo
 
密码学 & DRM & sgx
密码学 & DRM & sgx密码学 & DRM & sgx
密码学 & DRM & sgxpluschen
 
signed distance function
signed distance functionsigned distance function
signed distance functionEnigmatisms
 
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)Kris Mok
 
應用密碼學入門 - HITCON CMT 2018
應用密碼學入門 - HITCON CMT 2018應用密碼學入門 - HITCON CMT 2018
應用密碼學入門 - HITCON CMT 2018Allen Chou
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)wang hongjiang
 
Hello DNN
Hello DNNHello DNN
Hello DNNevan li
 
Python速成指南
Python速成指南Python速成指南
Python速成指南March Liu
 

Semelhante a 密碼學漏洞與他們的產地 Crypto fail and where to find them (20)

HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享HITCON CTF 2014 BambooFox 解題心得分享
HITCON CTF 2014 BambooFox 解題心得分享
 
Introduction of Reverse Engineering
Introduction of Reverse EngineeringIntroduction of Reverse Engineering
Introduction of Reverse Engineering
 
Python学习笔记
Python学习笔记Python学习笔记
Python学习笔记
 
introduce RSA
introduce RSAintroduce RSA
introduce RSA
 
Talking about exploit writing
Talking about exploit writingTalking about exploit writing
Talking about exploit writing
 
R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探R 語言教學: 探索性資料分析與文字探勘初探
R 語言教學: 探索性資料分析與文字探勘初探
 
Arduino L2
Arduino L2Arduino L2
Arduino L2
 
從技術面簡介線上遊戲外掛
從技術面簡介線上遊戲外掛從技術面簡介線上遊戲外掛
從技術面簡介線上遊戲外掛
 
人机对弈编程概述
人机对弈编程概述人机对弈编程概述
人机对弈编程概述
 
JCConf 2023 - 深入淺出 Java 21 功能
JCConf 2023 - 深入淺出 Java 21 功能JCConf 2023 - 深入淺出 Java 21 功能
JCConf 2023 - 深入淺出 Java 21 功能
 
密码学 & DRM & sgx
密码学 & DRM & sgx密码学 & DRM & sgx
密码学 & DRM & sgx
 
Rootkit 101
Rootkit 101Rootkit 101
Rootkit 101
 
signed distance function
signed distance functionsigned distance function
signed distance function
 
Hi Haskell
Hi HaskellHi Haskell
Hi Haskell
 
Tcfsh bootcamp day2
 Tcfsh bootcamp day2 Tcfsh bootcamp day2
Tcfsh bootcamp day2
 
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)
 
應用密碼學入門 - HITCON CMT 2018
應用密碼學入門 - HITCON CMT 2018應用密碼學入門 - HITCON CMT 2018
應用密碼學入門 - HITCON CMT 2018
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)
 
Hello DNN
Hello DNNHello DNN
Hello DNN
 
Python速成指南
Python速成指南Python速成指南
Python速成指南
 

密碼學漏洞與他們的產地 Crypto fail and where to find them