CrazyAsian1ã«ããããã°ãã¡ã€ãããŒã3
ããã«ã¡ã¯ ç§ã®ååã¯ãµãŒã·ã£ã»ãã©ã³ãã¯ã§ãã Mail.Ru Groupã§ã¯ã15人ã®WebéçºéšéãçããŠããŸãã ç§ãã¡ã¯äœåäžäººãã®ãŠãŒã¶ãŒã®ããã«ãŠã§ããµã€ããäœæããæ¹æ³ãåŠã³ãæ¯æ¥æ°çŸäžã®ãªãŒãã£ãšã³ã¹ãå·éã«æ±ã£ãŠããŸãã ç§èªèº«ã¯çŽ20幎éWebéçºã«æºãã£ãŠãããéå»15幎éã¯äž»ã«PHPã§ããã°ã©ãã³ã°ããå¿ èŠããããŸãã ãã®éãèšèªãšéçºã¢ãããŒãã®æ©èœã¯å€§ããå€åããŸããããäž»èŠãªè匱æ§ãç解ãããããããèªåèªèº«ãä¿è·ããèœåã¯ãã©ã®éçºè ã«ãšã£ãŠãéèŠãªã¹ãã«ã§ãã
ã€ã³ã¿ãŒãããã«ã¯å€ãã®èšäºãšã»ãã¥ãªãã£ã¬ã€ãããããŸãã ãã®æ¬ã¯ãç§ã«ã¯éåžžã«è©³çŽ°ã«èŠããŸããããç°¡æœã§ç解ãããããã®ã§ããã æ°ããããšãåŠã³ããµã€ãã®ä¿¡é Œæ§ãšå®å šæ§ãé«ããã®ã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãã
PSæ¬ã¯é·ãã®ã§ã翻蚳ã¯ããã€ãã®èšäºã«ãŸãšããããŸãã ããã§ã¯ãå§ããŸããã...
PHPã®å¥ã®ã»ãã¥ãªãã£ããã¯ã§ããïŒ
PHPã§ã»ãã¥ãªãã£ããã¯ãéå§ããã«ã¯å€ãã®æ¹æ³ããããŸãã æ®å¿µãªãããç§ã¯ãããã®ããããèªãã§ããŸããããã®ãããå·çããã»ã¹ã§ããã«å¯ŸåŠããå¿ èŠããããŸãã ããããæãåºæ¬çãªãã®ããå§ããŠããã¹ãŠãããŸãããããšãé¡ã£ãŠããŸãã
X瀟ããªã³ã©ã€ã³ã§èµ·åããæœè±¡Webã¢ããªã±ãŒã·ã§ã³ãæ€èšããå Žåããããã¯ã©ãã¯ããããšé倧ãªæ害ãåŒãèµ·ããå¯èœæ§ã®ããå€ãã®ã³ã³ããŒãã³ããå«ãŸããŠãããšæ³å®ã§ããŸãã ããšãã°ãã©ãã§ããïŒ
- ãŠãŒã¶ãŒãžã®å®³ïŒé»åã¡ãŒã«ããã¹ã¯ãŒããå人ããŒã¿ãéè¡ã«ãŒãã®è©³çŽ°ãããžãã¹ã·ãŒã¯ã¬ãããé£çµ¡å ãªã¹ããååŒå±¥æŽãããã³é«åºŠã«ä¿è·ãããã·ãŒã¯ã¬ããïŒèª°ãã圌ã®ç¬SparkyãšåŒãã ãã®ãªã©ïŒãžã®ã¢ã¯ã»ã¹ãååŸããŸãã ãã®ããŒã¿ã®æŒæŽ©ã¯ããŠãŒã¶ãŒïŒå人ããã³äŒæ¥ïŒã«æ害ãäžããŸãã ãã®ãããªããŒã¿ãæªçšããWebã¢ããªã±ãŒã·ã§ã³ãããŠãŒã¶ãŒã®ä¿¡é Œãå©çšãããµã€ããæ害ãªå ŽåããããŸãã
- äŒç€ŸXèªäœãžã®æ害ïŒãŠãŒã¶ãŒãžã®æ害ãè©å€ã®æªåãå ±é ¬ã®æ¯æããéèŠãªããžãã¹æ å ±ã®æ倱ãè¿œå è²»çšã®çºç-ã€ã³ãã©ã¹ãã©ã¯ãã£ãã»ãã¥ãªãã£ã®æ¹åãçµæã®æž ç®ãæ³çè²»çšã解éãããããããããŒãžã£ãŒãžã®å€§ããªã¡ãªãããªã©
Webã¢ããªã±ãŒã·ã§ã³ã®ã»ãã¥ãªãã£ã·ã¹ãã ãé²æ¢ããªããã°ãªããªããã©ãã«ã®ã»ãšãã©ãå«ãŸããŠãããããããã2ã€ã®ã«ããŽãªã«çŠç¹ãåœãŠãŸãã æ·±å»ãªã»ãã¥ãªãã£äŸµå®³ã«çŽé¢ãããã¹ãŠã®äŒæ¥ã¯ããã¬ã¹ãªãªãŒã¹ããŠã§ããµã€ãã«åœŒããã©ã®ããã«æããŠããããããã«æžããŸãã ã§ããããå®éã«ãã®åé¡ã«åºãããåã«ããã®åé¡ã®éèŠæ§ãæããããšãå¿ãããå§ãããŸãã
æ®å¿µãªãããã»ãã¥ãªãã£ã®åé¡ã¯ãã°ãã°é¡åçã«å¯ŸåŠãããŸãã æãéèŠãªããšã¯ã蚱容ã§ããäºç®ãšæéã§ããŠãŒã¶ãŒã®ããŒãºãæºããå®çšçãªã¢ããªã±ãŒã·ã§ã³ãäœæããããšã§ãããšèããããŠããŸãã ããã¯å®å šã«ç解ã§ããäžé£ã®åªå äºé ã§ãããã»ãã¥ãªãã£ãæ°žä¹ ã«ç¡èŠããããšã¯ã§ããŸããã å€æŽã®ã³ã¹ãããŸã äœãéçºäžã«ç¹å®ã®æ±ºå®ãå°å ¥ããããšãåžžã«å¿µé ã«çœ®ããŠããæ¹ãã¯ããã«åªããŠããŸãã
å®å šæ§ã®äºæ¬¡çèŠå ã¯ãäž»ã«ããã°ã©ãã³ã°æåã®çµæã§ãã äžéšã®ããã°ã©ããŒã¯ãè匱æ§ãèãããšå·éã«ãªããŸãããä»ã®ããã°ã©ããŒã¯ãè匱æ§ã§ã¯ãªãããšã蚌æã§ãããŸã§è匱æ§ã®ååšã«ç°è°ãå±ãããããããŸããã ãããã®äž¡æ¥µç«¯ã®éã«ã¯ã圌ãããŸã ééã£ãŠããªãã®ã§ãè©ãããããå€ãã®ããã°ã©ããŒãããŸãã 圌ãããã®å¥åŠãªäžçãç解ããã®ã¯é£ããã§ãã
Webã¢ããªã±ãŒã·ã§ã³ã®ã»ãã¥ãªãã£ã·ã¹ãã ã¯ãã¢ããªã±ãŒã·ã§ã³ã®ãµãŒãã¹ãä¿¡é ŒãããŠãŒã¶ãŒãä¿è·ããå¿ èŠãããããã質åãžã®åçãç¥ãå¿ èŠããããŸãã
- 誰ãç§ãã¡ãæ»æãããã§ããïŒ
- 圌ãã¯ã©ã®ããã«ç§ãã¡ãæ»æã§ããŸããïŒ
- ã©ãããã°ããããæ¢ããããšãã§ããŸããïŒ
誰ãç§ãã¡ãæ»æãããã§ããïŒ
æåã®è³ªåãžã®çãã¯éåžžã«ç°¡åã§ãïŒããã ãã§ãã ã¯ããå®å®å šäœãããªãã«ã¬ãã¹ã³ãæããããšæã£ãŠããŸãã Kali Linuxãå®è¡ããŠãããªãŒããŒã¯ããã¯ãããã³ã³ãã¥ãŒã¿ãŒã®åäŸã§ããïŒ åœŒã¯ãããããã§ã«ããªããæ»æããŸããã è»èŒªã«æ£ãå ¥ããã®ã奜ããªäžå¯©ãªç·ïŒ 圌ã¯ããããããªããæ»æããããã«èª°ãããã§ã«éã£ãŠããŸãã 1æéããšã«ããŒã¿ãåãåãä¿¡é Œã§ããREST API ãããã圌ã¯ãææããããŒã¿ãããªãã«æããããããã«1ãæåã«ãããã³ã°ãããŸããã ç§ãããªããæ»æã§ããŸãïŒ ãããã£ãŠããã®æ¬ãç²ç®çã«ä¿¡ããªãã§ãã ããã ç§ãåãã€ããŠãããšèããŠãã ããã ãããŠãããããªæ°Žã«é£ããŠè¡ã£ãŠç§ã®æªãã¢ããã€ã¹ãå ¬éããŠãããããã°ã©ããèŠã€ããŠãã ããã äžæ¹ãå€å圌ãããªããããã¯ããã§ããã...
ãã®ãã©ãã€ã¢ã®ãã€ã³ãã¯ãWebã¢ããªã±ãŒã·ã§ã³ãšå¯Ÿè©±ãããã¹ãŠã®ãã®ïŒããŠãŒã¶ãŒãããããã«ãŒãããããŒã¿ããŒã¹ãããä¿¡é Œã§ããªãå ¥åããããããŒãžã£ãŒãããREST APIãïŒã粟ç¥çã«ç°¡åã«åé¡ã§ããããã«ããããšã§ãã次ã«åã«ããŽãªã«ä¿¡é Œæ§ææšãå²ãåœãŠãŸãã æããã«ãããã«ãŒãä¿¡é Œããããšã¯ã§ããŸããããããŒã¿ããŒã¹ã«ã€ããŠã¯ã©ãã§ããïŒ ãä¿¡é Œæ§ã®äœãå ¥åããšããååã«ã¯çç±ããããŸãããååã®ä¿¡é Œã§ããAtomãã£ãŒãããåãåã£ãããã°æçš¿ãæ¬åœã«ãã£ã«ã¿ãªã³ã°ããŸããïŒ
Webã¢ããªã±ãŒã·ã§ã³ã®ãããã³ã°ã«çå£ã«åãçµãã§ãã人ã ã¯ããã®èãæ¹ãå©çšããããšãåŠã³ãè匱ãªããŒã¿ãœãŒã¹ã§ã¯ãªããåªããã»ãã¥ãªãã£ã·ã¹ãã ãæã€å¯èœæ§ãäœãä¿¡é Œã§ããããŒã¿ãœãŒã¹ãæ»æããããšããããããŸãã ããã¯å¶ç¶ã®æ±ºå®ã§ã¯ãããŸãããå®ç掻ã§ã¯ãä¿¡é Œææ°ãé«ã被éšè ã»ã©çããå°ãªãã§ãã ã¢ããªã±ãŒã·ã§ã³ãåæãããšãã«äž»ã«æ³šæãæãã®ã¯ããã®ãããªããŒã¿ãœãŒã¹ã§ãã
ããŒã¿ããŒã¹ã«æ»ããŸãã ããã«ãŒãããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ã§ãããšä»®å®ããå ŽåïŒãããŠãç§ãã¡ã¯åŠæ³ããåžžã«ãããä»®å®ããŸãïŒãããªãã¯åœŒå¥³ãä¿¡é Œããããšã¯ã§ããŸããã ã»ãšãã©ã®ã¢ããªã±ãŒã·ã§ã³ã¯ã質åãªãã§ããŒã¿ããŒã¹ãä¿¡é ŒããŸãã å€ã§ã¯ãWebã¢ããªã±ãŒã·ã§ã³ã¯å šäœã®ããã«èŠããŸãããå éšã§ã¯ããŒã¿ã亀æããå¥åã®ã³ã³ããŒãã³ãã®ã·ã¹ãã ã§ãã ããããã¹ãŠã®ã³ã³ããŒãã³ããä¿¡é Œã§ãããšèŠãªãããŠããå Žåããã®ãã¡ã®1ã€ããããã³ã°ããããšãä»ã®ãã¹ãŠã®ã³ã³ããŒãã³ããããã«äŸµå®³ãããŸãã ãã®ãããªå£æ» çãªã»ãã¥ãªãã£åé¡ã¯ããåºå°ããããã³ã°ãããå Žåãç§ãã¡ã¯ãŸã è² ããŠããŸãããšãããã¬ãŒãºã§ã¯è§£æ±ºã§ããŸããã ããªãã¯ããèšãããšãã§ããŸãããæåã«åºå°ãä¿¡é Œããããã«å¿ããŠè¡åããªããã°ããããããªããã°ãªããªããšããããšã¯ãŸã£ãããããŸããïŒ
圌ãã¯ã©ã®ããã«ç§ãã¡ãæ»æã§ããŸããïŒ
2çªç®ã®è³ªåã«å¯Ÿããçãã¯ãããªãåºç¯ãªãªã¹ãã§ãã Webã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãŠã®ã³ã³ããŒãã³ããŸãã¯ã¬ã€ã€ãŒãããŒã¿ãåä¿¡ããå Žæã§ããã°ã©ãããã§ãæ»æãåããå¯èœæ§ããããŸãã åºæ¬çã«ãWebã¢ããªã±ãŒã·ã§ã³ã¯ããŒã¿ãåŠçããå Žæããå Žæãžè»¢éããã ãã§ãã ãŠãŒã¶ãŒãªã¯ãšã¹ããããŒã¿ããŒã¹ãAPIãããã°ãã£ãŒãããã©ãŒã ãCookieããªããžããªãPHPç°å¢å€æ°ãæ§æãã¡ã€ã«ãå床æ§æãã¡ã€ã«ãå®è¡ããPHPãã¡ã€ã«-ãããã¯ãã¹ãŠãããŒã¿ã«ææããŠã»ãã¥ãªãã£ã·ã¹ãã ãçªç Žããæ害ãåŒãèµ·ããå¯èœæ§ããããŸãã å®éãæªæã®ããããŒã¿ããªã¯ãšã¹ãã«äœ¿çšãããPHPã³ãŒãã«æ瀺çã«ååšããªãå Žåãããããããã€ããŒãããšããŠéä¿¡ãããŸãã aïŒãœãŒã¹PHPã³ãŒããäœæããbïŒæ£ããã¬ãã¥ãŒãããcïŒç¯çœªçµç¹ã®ä»£è¡šè ãããªãã«æ¯æããããªãã£ããšä»®å®ããŸãã
ããŒã¿ãå®å šã«å®å šã§äœ¿çšã«é©ããŠããããšã確èªããã«ããŒã¿ãœãŒã¹ã䜿çšãããšãæ»æãåããå¯èœæ§ããããŸãã ãŸããåä¿¡ããããŒã¿ãéä¿¡ããããŒã¿ãšäžèŽããããšã確èªããå¿ èŠããããŸãã ããŒã¿ãåºåã«å¯ŸããŠå®å šã«å®å šã«ãããŠããªãå Žåãæ·±å»ãªåé¡ãçºçããŸãã ãããã¯ãã¹ãŠãPHPã®ãå ¥åããã§ãã¯ããŠãã ããã ç»é¢åºåãã
ãããã¯ãäœããã®æ¹æ³ã§å¶åŸ¡ããå¿ èŠãããæãããªããŒã¿ãœãŒã¹ã§ãã ãœãŒã¹ã«ã¯ãã¯ã©ã€ã¢ã³ãåŽã®ãªããžããªãå«ãŸããå ŽåããããŸãã ããšãã°ãã»ãšãã©ã®ã¢ããªã±ãŒã·ã§ã³ã¯ãCookieã«ä¿åã§ããäžæã®ã»ãã·ã§ã³IDãå²ãåœãŠãããšã§ãŠãŒã¶ãŒãèªèããŸãã æ»æè ãCookieããå€ãååŸãããšãå¥ã®ãŠãŒã¶ãŒã«ãªãããŸãããšãã§ããŸãã ãŸãããŠãŒã¶ãŒããŒã¿ã®ååãŸãã¯æ¹ããã«é¢é£ãããªã¹ã¯ã®äžéšã¯è»œæžã§ããŸããããŠãŒã¶ãŒã®ã³ã³ãã¥ãŒã¿ãŒã®ç©ççãªã»ãã¥ãªãã£ãä¿èšŒããããšã¯ã§ããŸããã ãŠãŒã¶ãŒãã123456ãããpasswordãã«ç¶ãæãæããªãã¹ã¯ãŒããšèŠãªãããšããä¿èšŒã§ããŸããã ä»æ¥ã§ã¯ããŠãŒã¶ãŒåŽã®ã¹ãã¬ãŒãžã®çš®é¡ãCookieã ãã§ã¯ãªããšããäºå®ã«ãã£ãŠãè¿œå ã®æµ·è³è¡çºãè¡ãããŠããŸãã
èŠèœãšãããããšãå€ãå¥ã®ãªã¹ã¯ã¯ããœãŒã¹ã³ãŒãã®æŽåæ§ã§ãã PHPã§ã¯ãäºãã«åŒ±ãæ¥ç¶ãããŠãããã¬ãŒã ã¯ãŒã¯ã®å€æ°ã®ã©ã€ãã©ãªãã¢ãžã¥ãŒã«ãããã³ããã±ãŒãžã«åºã¥ãã¢ããªã±ãŒã·ã§ã³éçºããŸããŸãäžè¬çã«ãªã£ãŠããŸãã ãããã®å€ãã¯Githubãªã©ã®å ¬éãªããžããªããããŠã³ããŒããããComposerããã®Webã³ã³ãããªã³ã§ããPackagist.orgãªã©ã®ããã±ãŒãžã€ã³ã¹ããŒã©ãŒã䜿çšããŠã€ã³ã¹ããŒã«ãããŸãã ãããã£ãŠããœãŒã¹ã³ãŒãã®ã»ãã¥ãªãã£ã¯ãããããã¹ãŠã®ãµãŒãããŒãã£ã®ãµãŒãã¹ãšã³ã³ããŒãã³ãã®ã»ãã¥ãªãã£ã«å®å šã«äŸåããŠããŸãã Githubã䟵害ãããå Žåãæªæã®ããã³ãŒããé åžããããã«Githubã䜿çšãããå¯èœæ§ãæãé«ããªããŸãã Packagist.orgã®å Žå-æ»æè ã¯ãã±ããèŠæ±ãèªåã®æªæã®ããããã±ãŒãžã«ãªãã€ã¬ã¯ãã§ããŸãã
ãããŸã§ãComposerãšPackagist.orgã«ã¯äŸåé¢ä¿ã®å€å¥ãšããã±ãŒãžã®é åžã«é¢ããæ¢ç¥ã®è匱æ§ãååšãããããåžžã«äœæ¥ç°å¢ã®ãã¹ãŠãå確èªããPackagist.orgãããã¹ãŠã®ããã±ãŒãžã®ãœãŒã¹ã確èªããŠãã ããã
ã©ãããã°ããããæ¢ããããšãã§ããŸããïŒ
Webã¢ããªã±ãŒã·ã§ã³ã®ã»ãã¥ãªãã£ã·ã¹ãã ãçªç Žããããšã¯ãã°ãã°ãããããšããéåžžã«æéã®ãããäœæ¥ã§ããããŸãã ãã¹ãŠã®Webã¢ããªã±ãŒã·ã§ã³ã®ã©ããã«è匱æ§ããããšä»®å®ããã®ã¯å ¬å¹³ã§ãã ãã®çç±ã¯ç°¡åã§ãããã¹ãŠã®ã¢ããªã±ãŒã·ã§ã³ã¯äººã«ãã£ãŠäœæããã人ã¯ééããç¯ããã¡ã§ãã å®ç§ãªã»ãã¥ãªãã£ã¯å€¢ã®ãããªãã®ã§ãã ãã¹ãŠã®ã¢ããªã±ãŒã·ã§ã³ã«ã¯è匱æ§ãå«ãŸããŠããå¯èœæ§ããããããã°ã©ãã®ä»äºã¯ãªã¹ã¯ãæå°éã«æããããšã§ãã
Webã¢ããªã±ãŒã·ã§ã³ãžã®æ»æã«ããæ害ã®å¯èœæ§ãæžããããã«ãæ éã«èããå¿ èŠããããŸãã ç©èªã®éçšã§ãå¯èœãªæ»ææ¹æ³ã«ã€ããŠã話ããŸãã ãããã®ããã€ãã¯æããã§ãããä»ã¯ããã§ã¯ãããŸããã ãããããããã«ãããåé¡ã解決ããã«ã¯ãããã€ãã®åºæ¬çãªå®å šååãèæ ®ããå¿ èŠããããŸãã
ã»ãã¥ãªãã£ã®åºç€
ä¿è·è£ 眮ãéçºããå Žåããã®æå¹æ§ã¯æ¬¡ã®èæ ®äºé ã䜿çšããŠè©äŸ¡ã§ããŸãã ãã§ã«äžèšã§åŒçšãããã®ããããŸãã
- 誰ãäœãä¿¡ããªãã§ãã ããã
- åžžã«ææªã®ã·ããªãªãæ³å®ããŠãã ããã
- ãã«ãã¬ãã«ã®ä¿è·ãé©çšããŸãïŒå€å±€é²åŸ¡ïŒã
- ãã·ã³ãã«ãªæ¹ãè¯ãããšããååãå®ããŸãïŒKISS It Simple StupidãKISSïŒã
- ãæå°ç¹æš©ãã®ååãé å®ããŠãã ããã
- æ»æè ã¯ãããŸãããæããŸãã
- ããã¥ã¡ã³ãïŒRTFMïŒãèªã¿ãŸããã決ããŠä¿¡çšããªãã§ãã ããã
- ããããã¹ããããŠããªãå Žåãããã¯æ©èœããŸããã
- ããã¯åžžã«ããªãã®ééãã§ãïŒ
ãã¹ãŠã®ãã€ã³ããç°¡åã«èŠãŠãããŸãããã
1.誰ãäœãä¿¡ããªã
äžèšã®ããã«ãæ£ããäœçœ®ã¯ãWebã¢ããªã±ãŒã·ã§ã³ãšããåããããã¹ãŠã®ãã®ããã¹ãŠãããã³ã°ããããšæ³å®ããããšã§ãã ãªã¯ãšã¹ããåŠçããããã«å¿ èŠãªä»ã®ã³ã³ããŒãã³ããŸãã¯ã¢ããªã±ãŒã·ã§ã³å±€ãå«ã¿ãŸãã ããã ãã§ãã äŸå€ãªãã
2.åžžã«ææªã®ã·ããªãªãæ³å®ããŸãã
å€ãã®ã»ãã¥ãªãã£ã·ã¹ãã ã«ã¯å ±éã®ç¹æ§ããããŸããã©ãã»ã©ããŸãäœãããŠããŠãããããããå£ããå¯èœæ§ããããŸãã ãããèæ ®ãããšã2çªç®ã®ãã€ã³ãã®å©ç¹ãããã«ç解ã§ããŸãã ææªã®ã·ããªãªãã¿ãŒã²ããã«ãããšãæ»æã®ç¯å²ãšé倧床ãè©äŸ¡ããã®ã«åœ¹ç«ã¡ãŸãã ãããŠããããæ¬åœã«èµ·ãã£ãå Žåãè¿œå ã®ã»ãã¥ãªãã£æ©èœãšã¢ãŒããã¯ãã£ã®å€æŽã«ããäžå¿«ãªçµæãæžããããšãã§ããã§ãããã ãããããããªãã䜿çšããŠããåŸæ¥ã®ãœãªã¥ãŒã·ã§ã³ã¯ããã§ã«ããè¯ããã®ã«çœ®ãæããããŠããŸããïŒ
3.è€æ°ã¬ãã«ã®ä¿è·ãé©çšããïŒå€å±€é²åŸ¡ïŒ
人ã ãé·ãéãæµã®åŒŸäžžãåããéèŠãªèåšãä¿è·ããå€ãã®å£ãåå¢ãè£ åãé²å ·ããã©ã¹ã³ãã»ãã¥ãªãã£ãžã®æ£ããã¢ãããŒãã§ããããšãèªèããŠããããããã«ãã¬ãã«ã®ä¿è·ã¯è»äºç§åŠããåçšãããŠããŸãã äžèšã®ã©ããä¿è·ãããªãã®ã決ããŠããããŸããããŸããããã€ãã®ä¿è·ã¬ãã«ã§ã¯ããã£ãŒã«ãã®åŒ·åãæŠéã®åœ¢æ以äžã®ãã®ã«äŸåã§ããããã«ããå¿ èŠããããŸãã ãã¡ãããåäžã®é害ã ãã§ã¯ãããŸããã é段ã®äžã«ãã巚倧ãªäžäžã®å£ã«ç»ãããã®åŸãã«å¥ã®å£ããããããããç¢å°ãã·ã£ã¯ãŒã济ã³ãŠããã®ãèŠã€ããæ»æè ãæ³åããŠãã ããã ããã«ãŒãåãããã«æããã§ãããã
4.ãã·ã³ãã«ãªæ¹ãè¯ãããšããååãå®ãïŒKISS It Simple StupidãKISSïŒ
æé«ã®æ²»çæ³ã¯åžžã«ã·ã³ãã«ã§ãã éçºãå®è£ ãç解ã䜿çšããã¹ããç°¡åã§ãã ã·ã³ãã«ãã«ããããšã©ãŒã®æ°ãæžããã¢ããªã±ãŒã·ã§ã³ã®æ£ããåäœãä¿é²ãããæãè€éã§äœ¿ãã«ããç°å¢ã§ãå®è£ ã容æã«ãªããŸãã
5.ãæå°ç¹æš©ãã®ååãé å®ãã
æ å ±äº€æã®ååå è ïŒãŠãŒã¶ãŒãããã»ã¹ãããã°ã©ã ïŒã«ã¯ãèªåã®æ©èœãå®è¡ããããã«å¿ èŠãªã¢ã¯ã»ã¹æš©ã®ã¿ãå¿ èŠã§ãã
6.æ»æè ã¯äžæçããæãã
ã ãããŸããã«ããã»ãã¥ãªã㣠ãã¯ãé²åŸ¡Aã䜿çšãããããã©ã®ããã«æ©èœããã®ãããŸãååšããã®ãã誰ã«ãèšããªãå Žåãæ»æè ãè¿·åã«ãªãããéæ³ã®ããã«åœ¹ç«ã€ãšããä»®å®ã«åºã¥ããŠããŸãã å®éãããã¯ããããªå©ç¹ããäžããŸããã å€ãã®å Žåãçµéšè±å¯ãªæ»æè ã¯ããªããåã£ã察çãèšç®ã§ãããããæ瀺çãªé²åŸ¡ã䜿çšããå¿ èŠããããŸãã ãããŸããªä¿è·ãæ¬åœã®ä¿è·ã®å¿ èŠæ§ãåãæ¶ããšé床ã«ç¢ºä¿¡ããŠãã人ã¯ãå¹»æ³ãåãé€ãããã«ç¹ã«çœ°ããããã¹ãã§ãã
7.ããã¥ã¡ã³ãïŒRTFMïŒãèªããã決ããŠä¿¡çšããªã
PHPããã¥ã¢ã«ã¯èæžã§ãã ãã¡ããã Flying Pasta Monsterã«ãã£ãŠæžããããã®ã§ã¯ãªããããæ£åŒã«ã¯ãŸã æ°ä»ããŠããªãããŸãã¯ä¿®æ£ãããŠããªããããçšåºŠã®ååã®çå®ãæ¬ é¥ã誀解ããŸãã¯èª€ããå«ãå¯èœæ§ããããŸãã ã¹ã¿ãã¯ãªãŒããŒãããŒã«ã€ããŠãåãããšãèšããŸãã
äžè¬ã«ãã»ãã¥ãªãã£ã®åéã«ãããå°éç¥èïŒPHPã®ã¿ã察象ãšããã®ã§ã¯ãªãïŒã¯ããã詳现ãªç¥èãæäŸããŸãã PHPã®ã»ãã¥ãªãã£èæžã«æãè¿ããã®ã¯ãèšäºãã¬ã€ããããã³ãã³ããæ²èŒãããOWASPãµã€ãã§ãã OWASPã§ã®å®è¡ãæšå¥šãããŠããªãå Žåã¯ã絶察ã«å®è¡ããªãã§ãã ããïŒ
8.ãã¹ããããŠããªãå Žåãæ©èœããŸããã
ã»ãã¥ãªãã£æ©èœãå®è£ ããå Žåãæ€èšŒã«å¿ èŠãªãã¹ãŠã®åäœãã¹ããäœæããå¿ èŠããããŸãã ããªããååæã§æ³£ãããã«ãŒã§ãããµããå«ãã ããã¯å€§ãããªããã«æãããããããŸããããWebã¢ããªã±ãŒã·ã§ã³ããããã³ã°ããæ¹æ³ãç¥ãããšã¯è¯ãç¿æ £ã§ãã æœåšçãªè匱æ§ã«ã€ããŠåŠç¿ããåŠæ³ãå¢å ããŸãã åæã«ãWebã¢ããªã±ãŒã·ã§ã³ãå£ããããšã«å¯Ÿããæ°ããªæè¬ã®æ°æã¡ãçµå¶è ã«äŒããå¿ èŠã¯ãããŸããã å¿ ãèªåããŒã«ã䜿çšããŠè匱æ§ãç¹å®ããŠãã ããã ãããã¯äŸ¿å©ã§ããããã¡ãããé«å質ã®ã³ãŒãã¬ãã¥ãŒãæåã®ã¢ããªã±ãŒã·ã§ã³ãã¹ãã«ä»£ãããã®ã§ã¯ãããŸããã ãã¹ãã«è²»ãããªãœãŒã¹ãå€ãã»ã©ãã¢ããªã±ãŒã·ã§ã³ã®ä¿¡é Œæ§ã¯é«ããªããŸãã
9.ããã¯åžžã«ããªãã®ééãã§ãïŒ
ããã°ã©ããŒã¯ãã»ãã¥ãªãã£ã®è匱æ§ã¯æ£åšããæ»æã§ããããã®çµæã¯ç¡èŠã§ãããšä¿¡ããŠããããšã«æ £ããŠããŸãã
ããšãã°ãããŒã¿ãªãŒã¯ïŒååã«ææžåãããåºç¯å²ã®ãããã³ã°ïŒã¯ããŠãŒã¶ãŒã«çŽæ¥åœ±é¿ãäžããªããããå€ãã®å Žåã軜埮ãªã»ãã¥ãªãã£åé¡ãšèŠãªãããŸãã ãã ãããœãããŠã§ã¢ããŒãžã§ã³ãéçºèšèªããœãŒã¹ã³ãŒãã®å Žæãã¢ããªã±ãŒã·ã§ã³ããžãã¯ãšããžãã¹ããžãã¯ãããŒã¿ããŒã¹æ§é ãWebã¢ããªã±ãŒã·ã§ã³ç°å¢ããã³å éšæäœã®ãã®ä»ã®åŽé¢ã«é¢ããããŒã¿æŒæŽ©ã¯ãæ»æãæåãããããã«ãã°ãã°éèŠã§ãã
åæã«ãã»ãã¥ãªãã£ã·ã¹ãã ã«å¯Ÿããæ»æã¯ãå€ãã®å Žåãæ»æã®çµã¿åããã§ãã å¥ã«ããããã¯éèŠã§ã¯ãããŸããããåæã«ä»ã®æ»æãžã®éãéãããšããããŸãã ããšãã°ãSQLã³ãŒããå®è£ ããã«ã¯ãç¹å®ã®ãŠãŒã¶ãŒåãå¿ èŠãªå ŽåããããŸããããã¯ãã¯ããã«é«äŸ¡ã§ç®ç«ã€ãã«ãŒããã©ãŒã¹ã§ã¯ãªãã管çã€ã³ã¿ãŒãã§ã€ã¹ã«å¯Ÿããã¿ã€ãã³ã°æ»æã䜿çšããŠååŸã§ããŸãã åæ§ã«ãSQLã®å°å ¥ã«ãããå€æ°ã®äžå¯©ãªãã°ãšã³ããªã®æ³šæãåŒãããšãªããç¹å®ã®ç®¡çã¢ã«ãŠã³ãã«XSSæ»æãå®è£ ã§ããŸãã
è匱æ§ãåç¬ã§èæ ®ããããšã®å±éºæ§ã¯ããããã®è åšãéå°è©äŸ¡ããããšã§ããããããã£ãŠããããã«å¯Ÿããäžæ³šæãªæ 床ã«ãããŸãã ããã°ã©ããŒã¯ãããŸãã«ãåãã«è¶³ããªããšèŠãªããŠãããããè匱æ§ãä¿®æ£ããã®ãé¢åã§ãã å®å šãªéçºã®è²¬ä»»ããšã³ãããã°ã©ããŒãŸãã¯ãŠãŒã¶ãŒã«ç§»ãæ £è¡ãå®è·µãããŸããå€ãã®å Žåãç¹å®ã®åé¡ãææžåããã«ããããã®è匱æ§ã®ååšããèªèãããŸããã
èŠããäžã®éèŠæ§ã¯éèŠã§ã¯ãããŸããã ç¹ã«ããã°ã©ããŒããŠãŒã¶ãŒã«è匱æ§ãä¿®æ£ããããã«åŒ·å¶ããããšã¯ç¡è²¬ä»»ã§ããç¹ã«è匱æ§ã«ã€ããŠç¥ããããŠããªãå Žåã¯ç¡è²¬ä»»ã§ãã
å ¥åæ€èšŒ
â -. -, . , , , . , , . ( ) «», «», « » « ». , , ⊠. , .
, ? . PHP « ». . , , , . ããã§ã¯ãããŸããã â , .
â , -. - , , . , . , , , , . , , . , PHP , , . , :
filter_var('php://example.org', FILTER_VALIDATE_URL);
ãã£ã«ã¿ã¯åé¡ãªãééããŸãã åé¡ã¯ãåãå ¥ããããphpïŒ// URLããå®è¡å¯èœãªPHPã¹ã¯ãªããããïŒPHPãã³ãã©ãŒãä»ããŠïŒããŒã¿ãè¿ãã®ã§ã¯ãªãããªã¢ãŒãHTTPã¢ãã¬ã¹ã®åä¿¡ãæåŸ ããPHPé¢æ°ã«æž¡ãããšãã§ããããšã§ãã ãã£ã«ã¿ãŒãªãã·ã§ã³ã«æå¹ãªURIãå¶éããã¡ãœããããªããããè匱æ§ãçºçããŸãã ã¢ããªã±ãŒã·ã§ã³ã¯ãPHPåºæã®URIã§ã¯ãªããhttpãhttpsããŸãã¯mailtoãªã³ã¯ãæ³å®ããŠãããšããäºå®ã«ããããããã ãã®ãããªããŸãã«ãäžè¬çãªæ€èšŒæ¹æ³ãé¿ããããšã¯ãã©ãããŠãå¿ èŠã§ãã
ã³ã³ããã¹ãã«æ³šæããŠãã ããã
å ¥åãæ€èšŒããããšã«ãããå®å šã§ãªãããŒã¿ãWebã¢ããªã±ãŒã·ã§ã³ã«å ¥åãããªãããã«ããå¿ èŠããããŸãã é倧ãªé害ïŒããŒã¿ã»ãã¥ãªãã£ãã§ãã¯ã¯éåžžãæåã®äœ¿çšç®çã«å¯ŸããŠã®ã¿å®è¡ãããŸãã
ååãå«ãããŒã¿ãååŸãããšããŸãã ã¢ãã¹ãããã£ããã€ãã³ãè§ãã£ããã¹ããŒã¹ãããã³è±æ°åã®Unicodeæåã®æ°ã確èªããã ãã§ãã ãã®ååã¯ã衚瀺ã«äœ¿çšã§ããæ£ããããŒã¿ã§ãïŒæåã®äœ¿çšç®çïŒã ãã ããä»ã®å ŽæïŒããšãã°ãããŒã¿ããŒã¹ãžã®ã¯ãšãªïŒã§äœ¿çšãããšãæ°ããã³ã³ããã¹ãã«è¡šç€ºãããŸãã ãŸãããã®ã³ã³ããã¹ãã§ã¯ãååã«æå¹ãªæåã®äžéšãå±éºã«ãªããŸããååãSQLã€ã³ãžã§ã¯ã·ã§ã³ãå®è¡ããããã«æååã«å€æãããå Žåã
å ¥åããŒã¿ã®æ€èšŒã¯æ¬è³ªçã«ä¿¡é Œã§ããªãããšãå€æããŠããŸãã æ確ã«ç¡å¹ãªå€ãåé€ããã®ã«æãå¹æçã§ãã äœããæŽæ°ãè±æ°åæååããŸãã¯HTTP URLã§ããå¿ èŠããããšãã«èšããŸãã ãã®ãããªåœ¢åŒãšå€ã«ã¯å¶éããããé©åã«æ€èšŒãããã°ãè åšã«ãªãå¯èœæ§ã¯äœããªããŸãã ãã®ä»ã®å€ïŒç¡å¶éã®ããã¹ããGET / POSTé åãããã³HTMLïŒã¯ãã§ãã¯ãé£ããããããã®å€ã§æªæã®ããããŒã¿ãåãåãå¯èœæ§ãé«ããªããŸãã
ã»ãšãã©ã®å Žåãã¢ããªã±ãŒã·ã§ã³ã¯ã³ã³ããã¹ãéã§ããŒã¿ã転éããããããã¹ãŠã®å ¥åããŒã¿ã確èªããŠåé¡ãå®äºãããšèŠãªãããšã¯ã§ããŸããã å ¥åãã§ãã¯ã¯æåã®ä¿è·åè·¯ã®ã¿ã§ããã決ããŠå¯äžã®ä¿è·åè·¯ã§ã¯ãããŸããã
å ¥åããŒã¿ã®ãã§ãã¯ã«å ããŠãã·ãŒã«ããªã©ã®ä¿è·æ¹æ³ãé »ç¹ã«äœ¿çšãããŸãã ããã«ãããæ°ããã³ã³ããã¹ããå ¥åãããã³ã«ããŒã¿ã®ã»ãã¥ãªãã£ããã§ãã¯ãããŸãã éåžžããã®æ¹æ³ã¯ã¯ãã¹ãµã€ãã¹ã¯ãªããã£ã³ã°ïŒXSSïŒããä¿è·ããããã«äœ¿çšãããŸããããã£ã«ã¿ãªã³ã°ã®æ段ãšããŠä»ã®å€ãã®ã¿ã¹ã¯ã§èŠæ±ãããŠããŸãã
ãšã¹ã±ãŒãã¯ãåä¿¡è ãéä¿¡ããŒã¿ã誀ã£ãŠè§£éããããšãé²ããŸãã ããããããã¯ååã§ã¯ãããŸãã-ããŒã¿ãæ°ããã³ã³ããã¹ãã§å°çããã®ã§ãç¹å®ã®ã³ã³ããã¹ãå°çšã®ãã§ãã¯ãå¿ èŠã§ãã
ããã¯æåã®å ¥åæã®æ€èšŒã®è€è£œãšèããããšãã§ããŸãããå®éã«ã¯ãããŒã¿èŠä»¶ãéåžžã«ç°ãªãå Žåãè¿œå ã®æ€èšŒæé ã¯çŸåšã®ã³ã³ããã¹ããããããèæ ®ããŸãã ããšãã°ããã©ãŒã ã®ããŒã¿ã«ã¯å²åãå«ãŸããå ŽåããããŸãã æåã®äœ¿çšæã«ãå€ãå®éã«æŽæ°ã§ããããšã確èªããŸãã ããããã¢ããªã±ãŒã·ã§ã³ã®ã¢ãã«ã«ç§»è¡ããå Žåãæ°ããèŠä»¶ãçºçããå¯èœæ§ããããŸããå€ã¯ç¹å®ã®ç¯å²ã«åãŸããªããã°ãªããŸãããããã¯ãã¢ããªã±ãŒã·ã§ã³ã®ããžãã¹ããžãã¯ãæ©èœããããã«å¿ é ã§ãã ãŸãããã®è¿œå ãã§ãã¯ãæ°ããã³ã³ããã¹ãã§å®è¡ãããªãå Žåãæ·±å»ãªåé¡ãçºçããå¯èœæ§ããããŸãã
ãã©ãã¯ãªã¹ãã§ã¯ãªãããã¯ã€ããªã¹ãã®ã¿ã䜿çšããŸã
ãã©ãã¯ãªã¹ããšãã¯ã€ããªã¹ãã¯ãå ¥åããŒã¿ãæ€èšŒããããã®2ã€ã®äž»èŠãªã¢ãããŒãã§ãã é»ããã®ã¯ç¡å¹ãªããŒã¿ã®ãã§ãã¯ãæå³ããçœããã®ã¯æå¹ãªããŒã¿ãæå³ããŸãã ãã¯ã€ããªã¹ããæãŸããã®ã¯ãæ€èšŒäžã«éä¿¡ãããã®ã¯äºæ³ãããããŒã¿ã®ã¿ã ããã§ãã åæ§ã«ããã©ãã¯ãªã¹ãã¯ãèãããããã¹ãŠã®èª€ã£ãããŒã¿ã«é¢ããããã°ã©ããŒã®ä»®å®ã®ã¿ãèæ ®ããŠãããããæ··ä¹±ããããäœããèŠéãããããã¹ãç¯ãããããã®ããã£ãšç°¡åã§ãã
è¯ãäŸã¯ããã³ãã¬ãŒãã®éã¹ã¯ãªãŒãã³ã°åºåã«é¢ããŠHTMLãå®å šã«ããããã«èšèšãããæ€èšŒæé ã§ãã ãã©ãã¯ãªã¹ãã䜿çšããå ŽåãHTMLã«å±éºãªèŠçŽ ãå±æ§ãã¹ã¿ã€ã«ãå®è¡å¯èœãªJavaScriptãå«ãŸããŠããªãããšã確èªããå¿ èŠããããŸãã ããã¯å€§éã®äœæ¥ã§ããããã©ãã¯ãªã¹ãã«ç»é²ãããHTMLã¯ãªãŒããŒã¯åžžã«ãã³ãŒãã®å±éºãªçµã¿åãããèŠéããŠããŸããŸãã ãŸãããã¯ã€ããªã¹ãã䜿çšããããŒã«ã¯ãèš±å¯ãããŠããæ¢ç¥ã®èŠçŽ ãšå±æ§ã®ã¿ãèš±å¯ããããšã«ããããã®äžç¢ºå®æ§ãæé€ããŸãã æ®ãã¯ãã¹ãŠãããããäœã§ãããã«é¢ä¿ãªããåçŽã«åé¢ãåé¢ããŸãã¯åé€ãããŸãã
ãããã£ãŠããã¯ã€ããªã¹ãã¯ã»ãã¥ãªãã£ãšä¿¡é Œæ§ãé«ããããæ€èšŒæé ã«é©ããŠããŸãã
å ¥åãä¿®æ£ããªãã§ãã ãã
å€ãã®å Žåãå ¥åæ€èšŒã«ã¯ãã£ã«ã¿ãªã³ã°ã䌎ããŸãã æ€èšŒäžã«ããŒã¿ã®æ£åœæ§ãåçŽã«è©äŸ¡ããå ŽåïŒæ£ãŸãã¯è² ã®çµæãçºè¡ãããå ŽåïŒããã£ã«ã¿ãªã³ã°ã¯ç¹å®ã®ã«ãŒã«ãæºããããã«ãã§ãã¯å¯Ÿè±¡ã®ããŒã¿ãå€æŽããŸãã
éåžžãããã¯ããæ害ã§ãã åŸæ¥ã®ãã£ã«ã¿ãŒã«ã¯ãããšãã°ãé»è©±çªå·ãããã¹ãŠã®æåãåé€ããïŒæ°åãé€ãïŒïŒäœåãªè§ãã£ãããã€ãã³ãå«ãïŒãäžèŠãªæ°Žå¹³ã¹ããŒã¹ãåçŽã¹ããŒã¹ãåé€ãããªã©ããããŸãã ãã®ãããªç¶æ³ã§ã¯ã衚瀺ãŸãã¯éä¿¡ãšã©ãŒãåé¿ããããã«æå°éã®ã¯ãªãŒãã³ã°ãå®è¡ãããŸãã ãã ãããã£ã«ã¿ãªã³ã°ã䜿çšããŠæªæã®ããããŒã¿ããããã¯ããããšã¯ããŸãã«ã倢äžã«ãªããŸãã
å ¥åãä¿®æ£ããããšããããšã®çµæã®1ã€ïŒæ»æè ã¯ä¿®æ£ã®å¹æãäºæž¬ã§ããŸãã ç¡å¹ãªæååå€ããããšä»®å®ããŸãã æ€çŽ¢ããŠåé€ãããã£ã«ã¿ãªã³ã°ãå®äºããŸãã ããããæ»æè ãæååã§åºåãããå€ãäœæããŠãã£ã«ã¿ãŒã«åãå Žåã¯ã©ãã§ããããïŒ
<scr<script>ipt>alert(document.cookie);</scr<script>ipt>
ãã®äŸã§ã¯ãã¿ã°ã«ããåçŽãªãã£ã«ã¿ãªã³ã°ã¯äœãè¡ããŸãããæ瀺çãª
<script>
ãåé€ãããšãããŒã¿ã¯HTMLã¹ã¯ãªããã®å®å šã«æå¹ãªèŠçŽ ãšèŠãªãããŸãã ç¹å®ã®åœ¢åŒã«ãããã£ã«ã¿ãªã³ã°ã«ã€ããŠãåãããšãèšããŸãã ããã¯ãã¹ãŠãã¢ããªã±ãŒã·ã§ã³ã®æåŸã®ä¿è·åè·¯ã§ã¯å ¥åããŒã¿ããã§ãã¯ã§ããªãçç±ãæ確ã«ç€ºããŠããŸãã
å ¥åãä¿®æ£ããããšãã代ããã«ããã¯ã€ããªã¹ãããŒã¹ã®ããªããŒã¿ã䜿çšããŠããã®ãããªå ¥åè©Šè¡ãå®å šã«æåŠããŸãã ãŸãããã£ã«ã¿ãªã³ã°ããå¿ èŠãããå Žåã¯ãå¿ ããã§ãã¯ããåã«ãã£ã«ã¿ãªã³ã°ãããã®åŸã«ã¯ãã£ã«ã¿ãªã³ã°ããªãã§ãã ããã
å€éšæ€èšŒããŒã«ãä¿¡é Œãããåžžã«è匱æ§ãç£èŠãã
以åãããŒã¿ãæ°ããã³ã³ããã¹ãã«è»¢éããããã³ã«æ€èšŒãå¿ èŠã§ããããšã«æ³šæããŸããã Webã¢ããªã±ãŒã·ã§ã³èªäœã®å€éšã§å®è¡ãããæ€èšŒã«ãåãããšãåœãŠã¯ãŸããŸãã ãã®ãããªããŒã«ã«ã¯ããã©ãŠã¶ãŒã®HTMLãã©ãŒã ã«é©çšãããæ€èšŒãŸãã¯ãã®ä»ã®å¶éãå«ãŸããŸãã HTML 5ã®ãã®ãã©ãŒã ãèŠãŠãã ããïŒã©ãã«ã¯çç¥ãããŠããŸãïŒïŒ
<form method="post" name="signup"> <input name="fname" placeholder="First Name" required /> <input name="lname" placeholder="Last Name" required /> <input type="email" name="email" placeholder="someone@example.com" required /> <input type="url" name="website" required /> <input name="birthday" type="date" pattern="^d{1,2}/d{1,2}/d{2}$" /> <select name="country" required> <option>Rep. Of Ireland</option> <option>United Kingdom</option> </select> <input type="number" size="3" name="countpets" min="0" max="100" value="1" required /> <textarea name="foundus" maxlength="140"></textarea> <input type="submit" name="submit" value="Submit" /> </form>
HTMLãã©ãŒã ã¯ãå ¥åããŒã¿ã«å¶éã課ãããšãã§ããŸãã åºå®ã¢ã€ãã ã®ãªã¹ãã䜿çšããŠéžæãå¶éããæå°å€ãšæ倧å€ãèšå®ããããã¹ãã®é·ããå¶éããããšãã§ããŸãã HTML 5ã¯ããã«åºããªã£ãŠããŸãã ãã©ãŠã¶ã¯URLãšã¡ãŒã«ã¢ãã¬ã¹ããã§ãã¯ããæ¥ä»ãæ°å€ãç¯å²ãå¶åŸ¡ã§ããŸãïŒãã ããæåŸã®2ã€ã®ãµããŒãã¯ããªãæ¡ä»¶ä»ãã§ãïŒã ãã©ãŠã¶ã¯ããã³ãã¬ãŒãå±æ§ã«å«ãŸããJavaScriptæ£èŠè¡šçŸã䜿çšããŠå ¥åããã§ãã¯ããããšãã§ããŸãã
ãã®è±å¯ãªã³ã³ãããŒã«ããã¹ãŠå¿ããªãã§ãã ããããããã®ç®çã¯ãã¢ããªã±ãŒã·ã§ã³ã®å©äŸ¿æ§ãåäžãããããšã§ãã æ»æè ã¯ãå ã®ãã©ãŒã ããã®å¶éãå«ãŸãªããã©ãŒã ãäœæã§ããŸãã èªåãã©ãŒã å ¥åçšã®HTTPã¯ã©ã€ã¢ã³ããäœæããããšãã§ããŸãïŒ
å€éšæ€èšŒããŒã«ã®ãã1ã€ã®äŸã¯ãTwitterãªã©ã®ãµãŒãããŒãã£APIããããŒã¿ãåä¿¡ããããšã§ãã ãã®ãœãŒã·ã£ã«ãããã¯ãŒã¯ã¯è©å€ãé«ããéåžžã¯çããªãä¿¡é ŒãããŠããŸãã ããããç§ãã¡ã¯åŠæ³çã§ãããããTwitterãä¿¡é Œããã¹ãã§ã¯ãããŸããã 劥åã®å Žåã圌ã®åçã§ã¯å®å šã§ãªãããŒã¿ã衚瀺ããããã®å€èŠ³ã«ã€ããŠã¯æºåãã§ããŠããŸããã ãããã£ãŠãããã§ããäœããèµ·ãã£ãŠãç¡é²åã«ãªããªãããã«ãç¬èªã®æ€èšŒã䜿çšããŠãã ããã
å€éšã®æ€èšŒæ段ã«èªä¿¡ãããå Žåã¯ãè匱æ§ã远跡ãããšäŸ¿å©ã§ãã ããšãã°ãHTMLãã©ãŒã ãæ倧é·ã«å¶éãèšå®ãããµã€ãºãå¶éã«éããå ¥åãååŸããå Žåããã®ãŠãŒã¶ãŒããã§ãã¯ããã€ãã¹ããããšããŠãããšä»®å®ããã®ã¯è«ççã§ãã ãããã£ãŠãå€éšæ段ã«ã®ã£ãããç»é²ããæœåšçãªæ»æã«å¯ŸããŠããã«ã¢ã¯ã·ã§ã³ãå®è¡ããŠãã¢ã¯ã»ã¹ãŸãã¯ãªã¯ãšã¹ãã®æ°ãå¶éã§ããŸãã
PHPã§ã®åå€æãé¿ãã
PHPã¯åŒ·ãåä»ããããèšèªã§ã¯ãªãããã®æ©èœãšæäœã®ã»ãšãã©ã¯å®å šã«åä»ããããŠããŸããã ããã¯æ·±å»ãªåé¡ã«ã€ãªããå¯èœæ§ããããŸãã ããã«ãå€èªäœã§ã¯ãªããããªããŒã¿ãŒã¯ç¹ã«è匱ã§ãã äŸïŒ
assert(0 == '0ABC'); // TRUE assert(0 == 'ABC'); // TRUE ( !) assert(0 === '0ABC'); // NULL/
ããªããŒã¿ãéçºãããšãã¯ãå ¥åå€ãŸãã¯åºåå€ãæååã§ããå¯èœæ§ãããå Žåãå³å¯ãªæ¯èŒãšæåã®åå€æã䜿çšããŠãã ããã ããšãã°ããã©ãŒã ã¯æååãè¿ãããšãã§ãããããæŽæ°ã§ããå¿ èŠãããããŒã¿ãæäœããŠããå Žåã¯ãå¿ ãåã確èªããŠãã ããã
function checkIntegerRange($int, $min, $max) { if (is_string($int) && !ctype_digit($int)) { return false; // } if (!is_int((int) $int)) { return false; // PHP_MAX_INT } return ($int >= $min && $int <= $max); }
ããã絶察ã«ããªãã§ãã ããïŒ
function checkIntegerRangeTheWrongWay($int, $min, $max) { return ($int >= $min && $int <= $max); }
ãã®å Žåãç®çã®ç¯å²ã«å ¥ãæ°å€ã§å§ãŸãè¡ã¯ãã¹ãŠãã¹ãã«åæ ŒããŸãã
assert(checkIntegerRange("6' OR 1=1", 5, 10)); // NULL/ assert(checkIntegerRangeTheWrongWay("6' OR 1=1", 5, 10)); // TRUE
åå€æã®åŸ®åŠãã¯ãå€ãã®æäœãé¢æ°ã«èŠãããŸããããšãã°ãé åå ã«æå¹ãªãªãã·ã§ã³ãååšãããã©ããã®å€ã確èªããããã«ãã䜿çšããã
in_array()
ãªã©ã§ãã
ããŒã¿æ€èšŒã®çš®é¡
å ¥åããŒã¿ã®æ€èšŒã§ãšã©ãŒãçºçãããšãè匱æ§ãšããŒã¿ç ŽæãçºçããŸãã 以äžã®PHPã®äŸã§ã¯ãããã€ãã®ã¿ã€ãã®æ€èšŒãæ€èšããŸãã
ããŒã¿åãã§ãã¯
ããŒã¿ã®çš®é¡ãæååãæŽæ°ãæµ®åå°æ°ç¹æ°ãé åãªã©ã«é¢é£ããŠããããšã確èªããŸããå€ãã®ããŒã¿ã¯ãã©ãŒã ãä»ããŠ
is_int()
ããã
is_int()
ãããªPHPé¢æ°ãç²ç®çã«äœ¿çšããããšã¯ã§ããŸããã 1ã€ã®å€ã¯æååã«ããããšãã§ããåæã«PHPã§ãµããŒããããŠããæŽæ°ã®æ倧å€ã«éããŸãã KISSã®ååã«éåããå¯èœæ§ããããããããŸãç¬åµçã§ããå¿ èŠããæ£èŠè¡šçŸã䜿çšããå¿ èŠããããŸããã
æåæ€èšŒ
æååã«æå¹ãªæåã®ã¿ãå«ãŸããŠããããšã確èªããŸãã ã»ãšãã©ã®å Žåããã®ããã«PHPã¯
ctype
é¢æ°ã䜿çšããããè€éãªå Žåã¯æ£èŠè¡šçŸã䜿çšããŸãã ASCIIæåã®ã¿ãå¿ èŠãªå Žåã¯ã
ctype
é¢æ°ã«
ctype
ããããšããå§ãããŸãã
ãã©ãŒããããã§ãã¯
ããã«ãããããŒã¿ãæå¹ãªæåã®ç¹å®ã®ã»ãããšäžèŽããããã«ãªããŸãã é®®æãªäŸã¯ãé»åã¡ãŒã«ãURLãæ¥ä»ã§ãã PHPã®
filter_var()
é¢æ°ã
DateTime
ã¯ã©ã¹ãããã³ä»ã®åœ¢åŒã®æ£èŠè¡šçŸã䜿çšããããšãã
filter_var()
ãŸãã 圢åŒãè€éã«ãªãã»ã©ã圢åŒãæ§æããã§ãã¯ããããã®ä¿¡é Œã§ããããŒã«ã«é Œãå¿ èŠãå¢ããŸãã
å¶éãã§ãã¯
ããã«ãããå€ã蚱容ç¯å²å ã«ãããã©ããã確èªãããŸãã ããšãã°ã5ãã倧ããå€ã0ã3ããŸãã¯34以å€ã®å€ã®ã¿ãåãå ¥ããå¿ èŠããããŸãããã§ãã¯å¶éã¯ãæååããã¡ã€ã«ãµã€ãºãç»å解å床ãæ¥ä»ç¯å²ãªã©ã«ãé©çšã§ããŸãã
ããŒã¿ãã§ãã¯
ä»åŸã®äœæ¥ã«å¿ èŠãªãã¹ãŠã®ããŒã¿ãå©çšå¯èœãã©ããã確èªããŸãã ããšãã°ãç»é²ãã©ãŒã ã§ã¯ãããã¯ãŠãŒã¶ãŒåããã¹ã¯ãŒããã¡ãŒã«ã¢ãã¬ã¹ã§ãã äœããå ¥åãããŠããªãå ŽåãããŒã¿ãæ£ãããªããšèŠãªãããŸãã
ããŒã¿ãããã³ã°
ãã®ã¿ã€ãã®ãã§ãã¯ã¯ããšã©ãŒãæé€ããããã«2ã€ã®åäžã®å€ãå ¥åããå¿ èŠãããå Žåã«äœ¿çšãããŸãã ããšãã°ããµã€ãã«ç»é²ãããšãã«ãã¹ã¯ãŒããç¹°ãè¿ããŸãã 2ã€ã®å€ãåãå ŽåãããŒã¿ã¯æ£ãããšèŠãªãããŸãã
è«çãã§ãã¯
æ¬è³ªçã«ãããã¯ãåä¿¡ããããŒã¿ãã¢ããªã±ãŒã·ã§ã³ã§ãšã©ãŒãäŸå€ãåŒãèµ·ãããªãããšã確èªãããå Žåã®ãšã©ãŒå¶åŸ¡ã§ãã ããšãã°ãæ€çŽ¢æååãæ£èŠè¡šçŸã«çœ®ãæãããšãåŒã®ã³ã³ãã€ã«ãšã©ãŒãçºçããå ŽåããããŸãã ç¹å®ã®å€ãè¶ ããæŽæ°ãå±éºã§ããå¯èœæ§ããããŸããé€ç®æäœäžã®åæ¯ã®ãŒãããŸãã¯+ 0ã0ãâ0ãªã©ã®å¥åŠãªãã®ã§ãã
ãªãœãŒã¹ã®å¯çšæ§ã確èªãã
ããŒã¿ã§ãªãœãŒã¹ãæå®ãããŠããå Žåããããå®éã«ååšãããã©ããã確èªããå¿ èŠããããŸãã ããã«ã¯ãã»ãšãã©ã®å ŽåãååšããªããªãœãŒã¹ã®èªåäœæããšã©ãŒã®ãããªãœãŒã¹ã®ãªãŒãã³ã®é€å€ãããã³ãã£ã¬ã¯ããªãã©ããŒãµã«æ»æãå®è¡ããããã«ãã¡ã€ã«ã·ã¹ãã ãã¹ã眮æããè©Šã¿ã®è¿œå ãã§ãã¯ã䌎ããŸãã
å ¥åãœãŒã¹ã®ç¢ºèª
åªåã«ãããããããå ¥åæ€èšŒã¯ãã¹ãŠã®ã»ãã¥ãªãã£åé¡ã解決ããããã§ã¯ãããŸããã å€ãã®å ŽåããŠãŒã¶ãŒãå ¥åããæ å ±ã確å®ã«æ€èšŒããããšã¯äžå¯èœã§ãã ã¢ããªã±ãŒã·ã§ã³ãä¿¡é Œã§ãããšèããããããŒã¿ãœãŒã¹ïŒããšãã°ãããŒã«ã«ããŒã¿ããŒã¹ïŒã§åäœããå Žåããã®å¯èœæ§ãé«ããªããŸãã ããŒã¿ããŒã¹ã®å Žåãè¿œå ã®ãã§ãã¯ã¿ã€ãã¯å€ããããŸããã ããããããšãã°HTTPSãä»ããŠAPIããæ å ±ãèŠæ±ããå Žåãªã©ãSSLãŸãã¯TLSã§ä¿è·ããããªã¢ãŒãWebãµãŒãã¹ã®äŸãèŠãŠã¿ãŸãããã
HTTPSã¯ãæ»æè ã2ã€ã®ããŒã¿äº€æãã€ã³ãã®éã®ä»²ä»è ã«ãªã£ããšãã«ãäžéè ïŒMITMïŒæ»æããä¿è·ããäž»ãªæ¹æ³ã§ãã ãã®ãããªä»²ä»è ã¯ãµãŒããŒãè£ ããŸãã ã€ãŸããã¯ã©ã€ã¢ã³ãã¯ãµãŒããŒã«æ¥ç¶ããŠãããšèããŠããŸãã å®éãèŠæ±ããããµãŒããŒãžã®å¥ã®æ¥ç¶ãäœæããã®ã¯æ»æè ã§ãã æ»æè ã¯ããŒã¿ãäž¡æ¹åã«äžç¶ããŠèªã¿åãããšãã§ããŸãããã¯ã©ã€ã¢ã³ãããµãŒããŒããããèªèããŠããŸããã ããã«ãäžç¶è ã¯äžç¶äžã«ããŒã¿ãå€æŽã§ããŸãã
ãã®ãããªæ»æãé²ãã«ã¯ããµãŒããŒãåœè£ ãããµãŒããŒãšã¯ã©ã€ã¢ã³ãéã§äº€æãããã¡ãã»ãŒãžãèªã¿åãèœåãæ»æè ã«äžããå¿ èŠããããŸãã ããã«ã¯SSL / TLSãããã2ã€ã®äž»èŠãªã»ãã¥ãªãã£æ©èœãå®è¡ããŸãã
- ã¯ã©ã€ã¢ã³ããšãµãŒããŒã®ã¿ãã¢ã¯ã»ã¹ã§ããå ±æããŒã䜿çšããŠãéä¿¡ããããã¹ãŠã®ããŒã¿ãæå·åããŸãã
- ãµãŒããŒã¯ãä¿¡é Œã§ããçµç¹ã«ãã£ãŠçºè¡ãããã¯ã©ã€ã¢ã³ãã«ãã£ãŠèªèãããå ¬é蚌ææžãšç§å¯ããŒã䜿çšããŠããµãŒããŒèªäœãèå¥ããå¿ èŠããããŸãã
SSL / TLSæå·åã¯ä»»æã®2è éã§çºçããå¯èœæ§ãããããšã«æ³šæããŠãã ããã ãäžéè ãæ»æã§ã¯ãã¯ã©ã€ã¢ã³ãã¯æ»æããŠããããµãŒããŒãã«é£çµ¡ããçžäºããŒã¿æå·åã®äœ¿çšã«ã€ããŠè°è«ãå§ããŸãã ãã®å ŽåãããµãŒããŒãã«èªåã䞻匵ãããšããã®äººç©ã§ããããšã蚌æããããã«äŸé Œããªãã£ããããããèªäœã¯åœ¹ã«ç«ã¡ãŸããã ãããã£ãŠãSSL / TLSã®ç¬¬2段éãå¿ é ã§ãããæ£åŒã«ã¯ãªãã·ã§ã³ã§ãã Webã¢ããªã±ãŒã·ã§ã³ã¯ããäžéè ãæ»æããèªèº«ãä¿è·ããããã«ãéä¿¡ãããµãŒããŒã®IDãæ€èšŒããå¿ èŠããããŸãã
æå·åã¯ãã®ãããªæ»æããä¿è·ããã®ã«ååã§ãããšåºãä¿¡ããããŠãããå€ãã®ã¢ããªã±ãŒã·ã§ã³ãšã©ã€ãã©ãªã¯ç¬¬2段éã䜿çšããŸããã ããã¯ããªãŒãã³ãœãŒã¹ã¢ããªã±ãŒã·ã§ã³ã§é »ç¹ã«æ€åºãããè匱æ§ã§ãã ããã€ãã®äžå¯è§£ãªçç±ã«ããã
stream_socket_client()
ã
fsockopen()
ãŸãã¯ãã®ä»ã®å éšé¢æ°ã䜿çšãããŠããå ŽåãPHPèªäœã¯ããã©ã«ãã§HTTPSã©ãããŒã®ãµãŒããŒãã§ãã¯ãç¡å¹ã«ããŸãã äŸïŒ
$body = file_get_contents('https://api.example.com/search?q=sphinx');
ããã§ã¯ãäžéæ»æã®ç·æ§ã«å¯Ÿããè匱æ§ãæããã§ãã ãã®HTTPSèŠæ±ããã®ããŒã¿ã¯ãå¿ èŠãªãµãŒãã¹ããåä¿¡ãããšèŠãªãããšã¯ã§ããŸããã ã€ã³ããªãžã§ã³ãã«ããµãŒããŒãã§ãã¯ã䜿çšããŠèŠæ±ãå®è¡ããå¿ èŠããããŸãã
$context = stream_context_create(array('ssl' => array('verify_peer' => TRUE))); $body = file_get_contents('https://api.example.com/search?q=sphinx', false, $context);
UPDã PHP 5.6以éã§ã¯ãssl.verify_peerãªãã·ã§ã³ã¯ããã©ã«ãã§
TRUE
èšå®ãããŠããŸãã
cURLæ¡åŒµæ©èœã«ã¯ããµãŒããŒã®ãã§ãã¯ã¢ãŠããå«ãŸããŠãããããäœãæ§æã§ããŸããã ãã ããããã°ã©ããŒã¯ãèªåã®ã©ã€ãã©ãªãŒãšã¢ããªã±ãŒã·ã§ã³ã®ã»ãã¥ãªãã£ãŒã«ã€ããŠæããããªãèããããšããããŸãã ãã®ã¢ãããŒãã¯ãã¢ããªã±ãŒã·ã§ã³ãäŸåããã©ã€ãã©ãªã§èŠã€ããããšãã§ããŸãã
curl_setopt(CURLOPT_SSL_VERIFYPEER, false);
SSLã®ã³ã³ããã¹ãã§ããŸãã¯
curl_setopt()
ã䜿çšããŠãããšãã«ãµãŒããŒæ€èšŒãç¡å¹ã«ãããšãäžéè æ»æã®è匱æ§ãçºçããŸãã ãã ããSSL蚌ææžãæ£ããæ§æãããŠããªããæå¹æéãåããŠãããã¹ããžã®æ»æãŸãã¯ã¢ããªã±ãŒã·ã§ã³ã®æ¥ç¶è©Šè¡ã瀺ãè¿·æãªãšã©ãŒã®åé¡ã解決ããããã ãã«ãªãã«ããŸãã
å€ãã®å ŽåãWebã¢ããªã±ãŒã·ã§ã³ã¯ããŠãŒã¶ãŒã¢ã¯ã·ã§ã³ã®ãããã·ãšããŠãããšãã°Twitterã¯ã©ã€ã¢ã³ããšããŠæ©èœã§ããŸãã ãããŠãç§ãã¡ã«ã§ããããšã¯ããŠãŒã¶ãŒã«èŠåããçããããµãŒããŒãžã®æ¥ç¶ãããŠãŒã¶ãŒãä¿è·ããããšãããã¢ããªã±ãŒã·ã§ã³ã®ãã©ãŠã¶ãŒã«ãã£ãŠèšå®ãããé«æ°Žæºã«æºæ ããããšã§ãã
çµè«
å€ãã®å Žåãå®å šãªã¢ããªã±ãŒã·ã§ã³ãäœæããããããæ©äŒããããŸãã ããããéçºããããã°ãããã³è¿·æãªãšã©ãŒåºåã®ç¡å¹åã容æã«ããããã«ãããã€ãã®åççãªå¶éãåé¿ããŠããŸãã ãŸãã¯ãæ£åœãªçç±ã®ããã«ãã¢ããªã±ãŒã·ã§ã³ã®ããžãã¯ãäžå¿ èŠã«è€éåããããšããŠããŸãã
ããããããã«ãŒã¯èªåã®ãã³ãé£ã¹ãŠãç¡é§ã§ã¯ãããŸããã . -, â . .