標準的偽隨機數生成器不能抵擋各種加密攻擊。
在對安全性要求較高的環境中,使用能產生可預測數值的函數作為隨機數據源,會產生 Insecure Randomness 錯誤。
電腦是一種具有確定性的機器,因此不可能產生真正的隨機性。偽隨機數生成器 (PRNG) 近似于隨機算法,始于一個能計算后續數值的種子。
PRNG 包括兩種類型:統計學的 PRNG 和密碼學的 PRNG。統計學的 PRNG 可提供有用的統計資料,但其輸出結果很容易預測,因此數據流容易復制。若安全性取決于生成數值的不可預測性,則此類型不適用。密碼學的 PRNG 通過可產生較難預測的輸出結果來應對這一問題。為了使加密數值更為安全,必須使攻擊者根本無法、或極不可能將它與真實的隨機數加以區分。通常情況下,如果一個 PRNG 算法沒有被指出曾經經過加密保護,那么它就很可能是一個統計學的 PRNG,而且不應該在對安全性要求較高的環境中使用。
示例: 下面的代碼可利用統計學的 PRNG 為購買產品后仍在有效期內的收據創建一個 URL。
char* CreateReceiptURL() {
int num;
time_t t1;
char *URL = (char*) malloc(MAX_URL);
if (URL) {
(void) time(&t1);
srand48((long) t1); /* use time to set seed */
sprintf(URL, "%s%d%s",
"http://test.com/",lrand48(),".html");
}
return URL;
}
lrand48() 函數來為它所生成的收據頁面生成獨特的標識符。因為 lrand48() 是一個統計學 PRNG,攻擊者很容易就能猜到由它生成的字符串。盡管收據系統的底層設計也存在錯誤,但如果使用了一個不生成可預測收據標識符的隨機數生成器,會更安全一些。
[1] .NET System.Security.Cryptography:Random Number Generation Microsoft
[2] Standards Mapping - OWASP Top 10 2010 - (OWASP 2010) A7 Insecure Cryptographic Storage
[3] Standards Mapping - OWASP Top 10 2007 - (OWASP 2007) A8 Insecure Cryptographic Storage
[4] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A8 Insecure Storage
[5] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3150.2 CAT II
[6] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3150.2 CAT II
[7] BeeCrypt
[8] J. Viega, G. McGraw Building Secure Software Addison-Wesley
[9] Crypt++
[10] CryptLib
[11] CryptoAPI:CryptGenRandom() Microsoft
[12] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 330
[13] Standards Mapping - Web Application Security Consortium 24 + 2 - (WASC 24 + 2) Information Leakage
[14] Standards Mapping - FIPS200 - (FISMA) MP
[15] OpenSSL
[16] Standards Mapping - SANS Top 25 2009 - (SANS 2009) Porous Defenses - CWE ID 330
[17] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.3.1.3, Requirement 6.5.8
[18] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.3
[19] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.8
[20] RtlGenRandom() Microsoft
[21] B. Schneier Yarrow:A secure pseudorandom number generator