éèŠãªæŽæ° ïŒã³ã¡ã³ãã§ãSamDarkã¯Mcryptã©ã€ãã©ãªãé·ãéãµããŒããããŠããããå€ãã®æ¬ ç¹ããããšè¿°ã¹ããããOpenSSLã䜿çšããããšããå§ãããŸãã æ¢åã®ã³ãŒããæžãçŽãããå Žåã¯ã ãã®èšäºã圹ç«ã¡ãŸãã ããã«ã PHP7ã§Mcryptãåé€ã§ãããšãã蚌æ ããããŸãã
ããã¯ãPHPã§äžè¬çãªå¯Ÿç§°æå·åãšã©ãŒãåé¿ããæ¹æ³ã«é¢ããçãã¬ã€ãã§ãã
ãµãŒããŒåŽã§ããŒã¿ãåŠçãããå ŽåïŒç¹ã«ããµãŒããŒã§æå·åãè¡ããããã¬ãŒã³ããã¹ãããã¹ã¯ãŒããªã©ã®åœ¢åŒã§ã¯ã©ã€ã¢ã³ãããããŒã¿ãåä¿¡ã§ããå ŽåïŒãèæ ®ããŸããããã¯ãPHPã¢ããªã±ãŒã·ã§ã³ã®å žåçãªå Žåã§ãã ã
ãã®ã¬ã€ãã®æ å ±ã䜿çšããŠãããè€éãªèŠä»¶ãæã€æå·åããããããã¯ãŒã¯æ¥ç¶ãäœæããªãã§ãã ããã ãã®ãããªå Žåã¯ã spipedãŸãã¯TLSã䜿çšããå¿ èŠããããŸã ã
åœç¶ãããã§äžããããæšå¥šäºé ã¯ãPHPã§æå·åãæŽçããããã®ãå¯äžã®å¯èœãªæ¹æ³ãã§ã¯ãããŸããã ãã®ã¬ã€ãã®ç®çã¯ããšã©ãŒãè€éã§ææ§ãªæ±ºå®ã®äœå°ãå°ãªãããããšã§ãã
PHPæå·åé¢æ°
McryptãŸãã¯OpenSSLæ¡åŒµæ©èœã䜿çšããŸã ã
æå·åã¢ã«ãŽãªãºã ãšãã®åäœã¢ãŒããã¯ã³ã¿ã€ã ã³ãŒãïŒåæåãã¯ãã«ïŒ
ã©ã³ãã ãª1åéãã®ã³ãŒãïŒ çŽTranslãïŒnonce ïŒã§CTRã¢ãŒãã§AES-256ã䜿çšããŸãã AESã¯æšæºã§ãããããMcryptãŸãã¯OpenSSLã®ä»»æã®æ¡åŒµæ©èœã䜿çšã§ããŸãã
åžžã«æ°ããã¯ã³ã¿ã€ã ã³ãŒããçæããŸãã ãã®éãæå·ã®åŒ·åãªä¹±æ°ãœãŒã¹ã䜿çšããå¿ èŠããããŸãã ä¹±æ°çæã®è©³çŽ°ã«ã€ããŠã¯ã以äžãã芧ãã ããã ã¯ã³ã¿ã€ã ã³ãŒãã¯ç§å¯ã§ã¯ãªããéä¿¡ãšãã®åŸã®åŸ©å·åã®ããã«æå·æãšé£çµã§ããŸãã
ã¯ã³ã¿ã€ã ã³ãŒãã¯ã128ãããïŒ16ãã€ãïŒã®é·ãã§ããšã³ã³ãŒããããŠããªããã€ãã®æååã§ããå¿ èŠããããŸãã
Mcryptæ¡åŒµæ©èœã§ã¯ãAESã¯Rijndael-128ãšããŠç¥ãããŠããŸã ïŒ perevã«æ³šæããŠãã ãããAES-256ã«ã€ããŠè©±ããŠãããšããäºå®ã«ãããããããããã¯ãšã©ãŒã§ã¯ãããŸãããAES-256ïŒ= Rijndael-256 ïŒã OpenSSLã§ã¯ãããããAES-256-CTRã
Mcryptã®äœ¿çšäŸïŒ
<?php // $key length must be exactly 256 bits (32 bytes). // $nonce length must be exactly 128 bits (16 bytes). $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, 'ctr', $nonce); // Mcrypt
OpenSSLã®äœ¿çšäŸïŒ
<?php // $key length must be exactly 256 bits (32 bytes). // $nonce length must be exactly 128 bits (16 bytes). $ciphertext = openssl_encrypt($plaintext, 'AES-256-CTR', $key, true, $nonce); // OpenSSL
ãã¹ããã¯ã¿ãŒã䜿çšããŠæå·åãæ£ããæ©èœããããšã確èªããŸãïŒ AES-256-CTRã«ã€ããŠã¯TranslãïŒçŽ57ããŒãžã®F.5.5é ãåç § ïŒã
CTRã¢ãŒãã®å Žåãæå·åãããããŒã¿ã®åèšéã«ã¯ããã€ãã®å¶éããããŸãã å®éã«ã¯ããã«ééããªããããããŸãããã1ã€ã®é·ãã¡ãã»ãŒãžã§ããããå€ãã®çãã¡ãã»ãŒãžã§ãããã«é¢ä¿ãªãã1ã€ã®ããŒã§2 ^ 64ãã€ããè¶ ããããŒã¿ãæå·åããªãã§ãã ããã
CTRã¢ãŒãã¯ãåãããŒã§åãã¯ã³ã¿ã€ã ã³ãŒãã䜿çšããªãå Žåã«ã®ã¿æç¶ããŸãã ãã®ãããæå·çã«åŒ·åãªã©ã³ãã æ§ã®ãœãŒã¹ã䜿çšããŠã¯ã³ã¿ã€ã ã³ãŒããçæããããšãéèŠã§ãã ããã«ãããã¯ã1ã€ã®ããŒã§2 ^ 64ãè¶ ããã¡ãã»ãŒãžãæå·åããªãããšãæå³ããŸãã ã¯ã³ã¿ã€ã ã³ãŒãã®é·ãã¯128ãããã§ãããããèªçæ¥ã®ãã©ããã¯ã¹ã®ããã«ãã¡ãã»ãŒãžïŒããã³å¯Ÿå¿ããã¯ã³ã¿ã€ã ã³ãŒãïŒ2 ^ 128/2ã®æ°ãå¶éããããšãéèŠã§ãïŒ æ³šïŒ ãã©ããã¯ã¹ã«ã€ããŠã®è©³çŽ° ïŒã
ãŸããæå·åã§ã¯ãéä¿¡ããããŒã¿éãé ãããšã¯ã§ããŸããã 極端ãªå Žåã®äŸãšããŠããã¯ãããŸãã¯ãããããã®ã¿ãå«ãã¡ãã»ãŒãžãæå·åããå Žåãæããã«ãæå·åã¯ãã®æ å ±ãé ããŸããã
ããŒã¿èªèšŒ
ããŒã¿ã®ä¿¡é Œæ§ãšæŽåæ§ãåžžã«ç¢ºèªããŠãã ããã
ãããè¡ãã«ã¯ãæå·ååŸã«MACã䜿çšããŸãã ã€ãŸã æåã«ããŒã¿ãæå·åããã次ã«æå·æèªäœãšã¯ã³ã¿ã€ã ã³ãŒããå«ãHMAC-SHA-256ãåä¿¡ããæå·æããååŸãããŸãã
埩å·åãããšãã¯ãæåã«æéæ»æã«èããæ¯èŒã¢ã«ãŽãªãºã ã䜿çšããŠHMACã確èªããŸãã ==ãŸãã¯===æ¯èŒæŒç®åã䜿çšããŠã$ user_submitted_macãš$ calculated_macãçŽæ¥æ¯èŒããªãã§ãã ããã ã ããã«HMACãã§ã㯠ãã䜿çšããããšã¯ããã«è¯ãããšã§ãã
HMACãã§ãã¯ãæåããå Žåãå®å šã«åŸ©å·åã§ããŸãã HMACãé©åã§ãªãå Žåã¯ãããã«ã·ã£ããããŠã³ããŸãã
æå·åããã³èªèšŒããŒ
çæ³çã«ã¯ãæå·çã«å®å šãªã©ã³ãã æ§ã®ãœãŒã¹ããååŸããããŒã䜿çšããŸãã AES-256ã«ã¯32ãã€ãã®ã©ã³ãã ããŒã¿ãå¿ èŠã§ãïŒçã®æååã¯ãšã³ã³ãŒãã䜿çšããªããããã®ã·ãŒã±ã³ã¹ã§ãïŒã
ããŒã«äŸåããå ŽåïŒ Re .:ãŠãŒã¶ãŒãå ¥åããããŒãããã¹ã¯ãŒãããšåŒã³ãŸã ïŒããŠãŒã¶ãŒãå ¥åããããŸãã¯æ§æã§æå®ããå Žåãæå·åããŒãšããŠäœ¿çšããåã«å€æããå¿ èŠããããŸãã PBKDF2ã䜿çšããŠããã¹ã¯ãŒããæå·åããŒã«å€æããŸãã 詳现http://php.net/hash_pbkdf2
ã¢ããªã±ãŒã·ã§ã³ãPBKDF2ã®çµã¿èŸŒã¿å®è£ ããªã5.5ããåã®PHPããŒãžã§ã³ã§å®è¡ãããŠããå Žåã¯ãPHPã§ç¬èªã®å®è£ ã䜿çšããå¿ èŠããããŸã ããã®äŸã¯https://defuse.ca/php-pbkdf2.htmã«ãããŸã ã ç¬èªã®å®è£ ã«äŸåããŠãããããhash_pbkdf2ïŒïŒçµã¿èŸŒã¿é¢æ°ãè¡ãããã«ãããŒãé©åã«å€æã§ããªãå¯èœæ§ãããããšã«æ³šæããŠãã ããã
æå·åãšèªèšŒã«åãããŒã䜿çšããªãã§ãã ããã äžèšã®ããã«ãæå·åããŒããšã«32ãã€ããšèªèšŒããŒïŒHMACïŒããšã«32ãã€ããå¿ èŠã§ãã PBKDF2ã䜿çšãããšããã¹ã¯ãŒããã64ãã€ããååŸããããšãã°æåã®32ãã€ããæå·åããŒãšããŠäœ¿çšããæ®ãã®32ãã€ããèªèšŒããŒãšããŠäœ¿çšã§ããŸãã
ããšãã°ããã¹ã¯ãŒãã16é²æååãšããŠãã¡ã€ã«ã«ä¿åãããŠããå Žåãæå·åæ©èœãããã£ãŒããããåã«ãã¹ã¯ãŒããåãšã³ã³ãŒãããªãã§ãã ããã 代ããã«ãPBKDF2ã䜿çšããŠãããŒãHEXãšã³ã³ãŒãã£ã³ã°ããçŽæ¥é«å質ã®æå·åããŒãŸãã¯èªèšŒããŒã«å€æããŸãã ãŸãã¯ãè¿œå ã®ãšã³ã³ãŒãïŒ32ãã€ãæååã®ã¿ïŒãªãã§åºåã§SHA-256ã䜿çšããŠããã¹ã¯ãŒããããã·ã¥ããŸãã éåžžã®ãã¹ã¯ãŒãããã·ã¥ã䜿çšãããšãååãªãšã³ããããŒãåŸãããŸãã 詳现ã«ã€ããŠã¯ã次ã®æ®µèœã§èª¬æããŸãã
ããŒæ»rain
ãŸããäœãšã³ããããŒããŒãé¿ããå¿ èŠããããŸãã ããã§ããããšãã°ãŠãŒã¶ãŒãã¹ã¯ãŒãã䜿çšããå¿ èŠãããå Žåã¯ãããŒã®ã»ãã¥ãªãã£ãæ倧éã«é«ããããã«ãééããªãPBKDF2ãå€æ°ã®å埩ã§äœ¿çšããå¿ èŠããããŸãã
PBKDF2ã®ãã©ã¡ãŒã¿ãŒã®1ã€ã¯ãããã·ã¥å埩ã®æ°ã§ãã ãããŠããããé«ããã°é«ãã»ã©ãéµã®ã»ãã¥ãªãã£ã¯ãã倧ããæåŸ ã§ããŸãã ã³ãŒãã64ããããã©ãããã©ãŒã ã§å®è¡ãããå ŽåãPBKDF2ã®ããã·ã¥ã¢ã«ãŽãªãºã ãšããŠSHA-512ã䜿çšããŸãã 32ããããã©ãããã©ãŒã ã®å ŽåãSHA-256ã䜿çšããŸãã
ãã ããDoSæ»æã®ãªã¹ã¯ãããããããªã³ã©ã€ã³ã¢ããªã±ãŒã·ã§ã³ã§æ¯èŒçå€æ°ã®å埩ã䜿çšããããšã¯ã§ããŸããã ãããã£ãŠãããŒã®å質ã¯ãªãã©ã€ã³ã¢ããªã±ãŒã·ã§ã³ã»ã©é«ããªãããã®ãããªãªã¹ã¯ãªãã«å€æ°ã®å埩ãè¡ãããšãã§ããŸãã ååãšããŠããªã³ã©ã€ã³ã¢ããªã±ãŒã·ã§ã³ã®å ŽåãPBKDF2ã100ããªç§ä»¥å ã«æ©èœããããã«ããã®ãããªæ°ã®ããã·ã¥å埩ãéžæãããŸãã
ãšã³ããããŒã®é«ããã¹ã¯ãŒãã䜿çšã§ããå Žåããšã³ããããŒã®äœããã¹ã¯ãŒãã®å Žåã®ããã«ãã¹ãã¬ããã³ã°ããå®è¡ããå¿ èŠã¯ãããŸããã ããšãã°ã/ dev / urandomã䜿çšããŠãæå·åmaster_keyããšãauthentication_ master_keyããäœæããå ŽåãPBKDF2ã¯ãŸã£ããäžèŠã§ãã ãšã³ã³ãŒãã£ã³ã°ã䜿çšããã«ãããŒããããã·ãŒã±ã³ã¹ãšããŠäœ¿çšããŠãã ããã
ããã«ãPBKDF2ã䜿çšãããšã1ã€ã®ãã¹ã¿ãŒãã¹ã¯ãŒãããæå·åãšèªèšŒã®äž¡æ¹ã®ããŒãç°¡åã«ååŸã§ããŸãïŒããããªå埩ãŸãã¯1ã€ã®å埩ã䜿çšããã ãã§ãïŒã ããã¯ãæå·åãšèªèšŒã®äž¡æ¹ã«äœ¿çšãããããã¹ã¿ãŒãã¹ã¯ãŒããã1ã€ãããªãå Žåã«äŸ¿å©ã§ãã
éµã®ä¿ç®¡ãšç®¡ç
æåã®æ¹æ³ã¯ãåå¥ã®å°çšããŒã¹ãã¬ãŒãžããã€ã¹ïŒ HSM ïŒã䜿çšããããšã§ãã
ãããäžå¯èœãªå Žåãæ»æãè€éã«ããããã«ãå¥ã®å ŽæïŒããŒã ãã£ã¬ã¯ããªãŸãã¯ãµã€ãã«ãŒãã®å€éšïŒã«ä¿åãããããŒã䜿çšããŠãããŒãŸãã¯æ§æãã¡ã€ã«ïŒå®éã®æå·å/èªèšŒããŒãä¿åãããŠããïŒã§ãã¡ã€ã«ã®æå·åã䜿çšã§ããŸãã ããšãã°ãhttpd.confã®Apacheç°å¢å€æ°ã䜿çšããŠãå®éã®ããŒã§ãã¡ã€ã«ã埩å·åããããã«å¿ èŠãªããŒãä¿åã§ããŸãã
<VirtualHost *:80> SetEnv keyfile_key crypto_strong_high_entropy_key # You can access this variable in PHP using $_SERVER['keyfile_key'] # Rest of the config </VirtualHost>
çŸåšããµã€ãã®ã«ãŒã以äžã®ãã¡ã€ã«ïŒããŒä»ããã¡ã€ã«ãå«ãïŒã䟵害ãããå ŽåïŒããšãã°ãããã¯ã¢ãããæŒæŽ©ããå ŽåïŒãç°å¢å€æ°ã«ä¿åãããŠããããŒã䟵害ãããŠããªããããæå·åãããããŒã¿ã¯å®å šãªãŸãŸã§ãã httpd.confãã¡ã€ã«ã¯åå¥ã«ããã¯ã¢ããããå¿ èŠããããããšãã°phpinfoïŒïŒã®åºåãä»ããŠkeyfile_keyå€æ°ã䟵害ããªãããšãèŠããŠããããšãéèŠã§ãã
æ§æãã©ã¡ãŒã¿ãŒã®ä»£ããã«ãã¡ã€ã«ã䜿çšããå ŽåãããŒã®ããŒããŒã·ã§ã³ãæŽçããããšãã§ããŸãã ææªã®å Žåãæ»æè ãæå·åããŒãšèªèšŒããŒãååŸãããã®äºå®ã«æ°ä»ããªãã£ãå Žåãäžå®ã®åšæã§ããŒãããŒããŒã·ã§ã³ãããšã¢ã¯ã»ã¹ãå¶éãããå¯èœæ§ããããŸãïŒæ°ããããŒãååŸã§ããªãå ŽåïŒã æµã¯äŸµå®³ãããããŒãç¡æéã«äœ¿çšããããšãã§ããªãããããã®ææ³ã¯æ害ã軜æžããã®ã«åœ¹ç«ã¡ãŸãã
ããŒã¿å§çž®
äžè¬ã«ãæå·åã®åã«ãœãŒã¹ã³ãŒããå§çž®ããªãã§ãã ããã ããã«ãããæ»æè ã¯åæã®ããã®è¿œå ã®ããŒã«ãæäŸã§ããŸãã
ããšãã°ãã»ãã·ã§ã³ããŒã¿ãæå·åãããCookieã«ä¿åãããã®ããŒã¿ã®äžéšã¯ãŠãŒã¶ãŒã«ãã£ãŠæäŸãããäžéšã¯ç§å¯æ å ±ãæäŸããå Žåãæ»æè ã¯éåžžã®ãŠãŒã¶ãŒãšããŠçæãããããŒã¿ãéä¿¡ããåä¿¡ããæå·æã®é·ããã©ã®ããã«å€åãããã枬å®ããããšã§ãç§å¯ã«é¢ããè¿œå æ å ±ãèŠã€ããããšãã§ããŸãã
éè€ããã»ã¯ã·ã§ã³ãããå Žåãããã¹ãã¯ããå¹ççã«å§çž®ãããŸãã ãŠãŒã¶ãŒããŒã¿ãæäœããããšã«ããããŠãŒã¶ãŒãç§å¯ããŒã¿ãšéšåçã«äžèŽããããã«éžæã§ããŸãã äžèŽã倧ããã»ã©ãæå·æã¯å°ãããªããŸãã ãã®ã¿ã€ãã®æ»æã¯CRIMEãšåŒã°ããŸãã
ããŒã¿ãå§çž®ããå¿ èŠãããå Žåãé€ããå§çž®ããªãã§ãã ããã
ãµãŒããŒç°å¢
ååãšããŠãã»ãã¥ãªãã£ã®åœ±é¿ãåããããã¢ããªã±ãŒã·ã§ã³ãå ±æãµãŒããŒã«é 眮ããªãã§ãã ããã ããšãã°ãå ±æãã¹ãã£ã³ã°ã§ã¯ãæ»æè ãããªããšåãç©çãµãŒããŒäžã®ä»®æ³ãã·ã³ã«ã¢ã¯ã»ã¹ã§ããŸãã
å ±æãµãŒããŒããã»ãã¥ãªãã£ãéèŠãªã¢ããªã±ãŒã·ã§ã³ããã¹ãããããã®çãããå Žæã«ããããŸããŸãªçç±ããããŸãã ããšãã°ãä»®æ³ãµãŒããŒéã®æ»æãæè¿å®èšŒãããŠããŸãïŒ eprint.iacr.org/2014/248.pdf ã ããã¯ãæ»æææ³ãäœäžããã®ã§ã¯ãªããæéãšãšãã«æ¹åããæ¹åãããããšãæãåºãããŠãããŸãã ãã®ãããªèœãšãç©Žãåžžã«èæ ®ããå¿ èŠããããŸãã
å°é家ã®çžè«
æåŸã«ãªããŸããããå°é家ã«çžè«ããŠãã»ãã¥ãªãã£ã³ãŒãã確èªããŠããããŸãã
@ rootlabs ã2014幎6æ5æ¥ïŒ
@plo @veorqç§ã¯1997幎ããæå·åã«åãçµãã§ããããããŸã§ã®ãšãããç§ã®æ±ºå®ãšå®è£ ã¯ãã¹ãŠç¬¬äžè ã«ãã£ãŠã¬ãã¥ãŒãããŠããŸãã
æå·çã«åŒ·åãªä¹±æ°
OSãæäŸããä¹±æ°ãœãŒã¹ã䜿çšããŸãã PHPã§ã¯ãããšãã°ãmcrypt_create_ivïŒ$ã«ãŠã³ããMCRYPT_DEV_URANDOMïŒãŸãã¯/ dev / urandomããçŽæ¥èªã¿åããŸãã
ãœãŒã¹ããæ£ãããã€ãæ°ãåä¿¡ãããããšãåžžã«ç¢ºèªããŠãã ããã ããã§ãªãå Žåã¯ãèªåã§äœæããæ¬äŒŒã©ã³ãã ã¢ã«ãŽãªãºã ã䜿çšããŠããã®ãããªééããèªåã§ä¿®æ£ããããšããªãã§ãã ããã