æä½éç¥ã£ã¦ããã¹ãwebãµã¤ãã®ã»ãã¥ãªãã£
Webãµã¤ããæ§ç¯ããä¸ã§æ°äººåãã®èª¬æç¨ã«å¿
è¦ãªåæç¥èãã¾ã¨ããã
以前同じタイトルで書いた事があるãã©ãä»åã¯ãã£ã¨åæ©ãã解説ãã¾ãã
æ®éã®ã»ãã¥ãªãã£ã¨ããã°ããã¢ã®æ¸ç· ãã¨ãã¬ã¹ã®å
æ ãç· ãããããäºã§ãã
Webãµã¤ãã®ã»ãã¥ãªãã£ã¨ããã°ãWebãµã¤ãã®ãµã¼ãã¹ãç½å®³ããå®ã£ããã
æªæã®ããå©ç¨è
ããã®ä¸æ£ãªå©ç¨ãã誤æä½ã«ãããã¼ã¿ã®ç ´å£ãæµåºçãã
å®ãäºã§ãã
Webãµã¼ãã¹ã§ã¯ä»¥ä¸ã®æ§ãªç®æã®ã»ãã¥ãªãã£ãæèããå¿
è¦ãããã¾ãã
- Webãµã¤ãã®ã¢ããªã±ã¼ã·ã§ã³
- ã¢ããªã±ã¼ã·ã§ã³ãè¨ç½®ãã¦ãããµã¼ã
- ãµã¼ããè¨ç½®ãã¦ããå ´æ
- ãµã¼ãããããã¯ã¼ã¯ã«æ¥ç¶ããã¤ã³ãã©ç°å¢
- ãµã¼ããã¢ããªã±ã¼ã·ã§ã³ãä¿å®ãã管çè ã®ç«¯æ«
- å©ç¨è ã®ãã©ã¦ã¶
ä»åã¯ãWebãµã¼ãã¹ã«ã¤ãã¦ä¸»ã«è§£èª¬ãã¾ãã®ã§ããã以å¤ã®é ç®ã«ã¤ãã¦å ã«ç°¡åã«èª¬æãã¾ãã
ã¢ããªã±ã¼ã·ã§ã³ãè¨ç½®ãã¦ãããµã¼ã
Linuxã ã£ããWindowsã ã£ããããã¨æãã¾ããããµã¼ãã®æä¾ãããµã¼ãã¹ã«ãã»ãã¥ãªãã£ãã¼ã«ãè¦ã¤ããã¨ããã«å¯¾çãããå¿
è¦ãããã¾ãã
å
æ¥ãDebianç³»ã®ãã£ã¹ããªãã¥ã¼ã·ã§ã³ã®SSHçã«èª°ã§ããã°ã¤ã³ã§ããæ§ãªã»ãã¥ãªãã£ãã¼ã«ãè¦ã¤ããã¾ããã
ãµã¼ããè¨ç½®ãã¦ããå ´æ
誰ã§ã触ããæ§ãªå ´æã«ãµã¼ããããã¨ããµã¼ããçãã ããç ´æããããããã¼ã¿ãæãåºããããã§ããæ§ã«ãªãã¾ãã
å
¥é室ã®ç®¡çããã£ããã¨è¡ããä¸é¨ã®äººéã®ã¿ãå
¥ããæ§ãªç°å¢ãæ§ç¯ããæ¹ããã¿ã¼ã§ãã
ãµã¼ãããããã¯ã¼ã¯ã«æ¥ç¶ããã¤ã³ãã©ç°å¢
åç·ãé »ç¹ã«åæãããæ§ãªç¶æ³ã§ãã£ãããå¤é¨ããã®ã¢ã¯ã»ã¹ãFWã«ãã£ã¦ç£è¦ãã¦ããªãç¶æ³ã§ããã¨ãäºæããªãã¢ã¯ã»ã¹ãè¡ãããäºãããã¾ãã
ãµã¼ããã¢ããªã±ã¼ã·ã§ã³ãä¿å®ãã管çè ã®ç«¯æ«
ãµã¼ãã以ä¸ã«ã»ãã¥ã¢ã§ã管çè ã®ç«¯æ«ã«ãã¹ã¯ã¼ããããã£ã¦ãããã誰ã§ãæä½ã§ããæ§ã ã¨ãããããæ å ±ã®æµåºããµã¼ãã¹ã®ç ´å£ãè¡ããããªã¹ã¯ãããã¾ãã
å©ç¨è ã®ãã©ã¦ã¶
å©ç¨è
ã®ãã©ã¦ã¶ã®è¨å®ã«ãã£ã¦ã¯ãå
é¨ã®ã¯ããã¼ãå¤é¨ã®ãµã¤ãã«åãæµããããã¦ã¤ã«ã¹ã«ææãã¦å
¥åãã¦ããæ
å ±ãæµåºãã¦ããå¯è½æ§ãããã¾ãã
Webãµã¼ãã¹ã®ã»ãã¥ãªãã£
ä¸è¬çã«ä»¥ä¸ã®æ§ãªæ»ææ¹æ³ãããã対çã®å¿ è¦ãããã¾ãã
- XSS(ã¯ãã¹ãµã¤ãã¹ã¯ãªããã£ã³ã°)
- CSRF(ã¯ãã¹ãµã¤ããªã¯ã¨ã¹ããã©ã¼ã¸ã§ãª)
- ãã©ã¡ã¼ã¿æ¹ç«
- ã»ãã·ã§ã³ãã¤ã¸ã£ãã¯
- ã»ãã·ã§ã³åºå®æ»æ
- SQLã¤ã³ã¸ã§ã¯ã·ã§ã³
XSS(ã¯ãã¹ãµã¤ãã¹ã¯ãªããã£ã³ã°)
ã¦ã¼ã¶ã®å ¥åããå 容ã表示ããå ´æ(æ²ç¤ºæ¿ã®ã³ã¡ã³ãã¨ã)ã«ãjavascriptã®ã½ã¼ã¹ã³ã¼ãçãå¼µãäºã§ãæ»æè ãä»ã®ã¦ã¼ã¶ã«ä»»æã®ã³ã¼ããå®è¡ãããæ»æãè¨ãã¾ãã
対çæ¹æ³
æç« å 容ããµãã¿ã¤ãº(& ã & ã«ã< ã < ã«ã> ã > ã«ã" ã " ãªã©)ãããã許å¯ããæ§æã®ã¿ã«éå®ããæ§æã«å½ã¦ã¯ã¾ããªãå ¥åå¤ãã¯ããæ§ã«ãã¾ãã
CSRF(ã¯ãã¹ãµã¤ããªã¯ã¨ã¹ããã©ã¼ã¸ã§ãª)
ãªã³ã¯ã«ãã©ã¡ã¼ã¿ãã¤ãããã®ãªã³ã¯ãã¯ãªãã¯ããã¦ã¼ã¶ã¼ã«æå³ããªãæä½ãå¼·å¶ãããæ»æã§ãã
対çæ¹æ³
主ã«GETã§urlã®æ«å°¾ã«?çã§ã¤ããæ»æãå¤ãã®ã§ãpostã®ã¿ã«éå®ããã ãã§ã
æ²ç¤ºæ¿ããã®æ»æã¯æ¸ãã(ã¡ããã¨ãã対çãããªããã©)
ã»ãã·ã§ã³æ
å ±ã種ã«ä¹±æ°ã使ã£ããã¼ã¯ã³ãçæãã¦ãå
¥åç»é¢ãããã®ãã¼ã¯ã³æ
å ±ãéãæ§ã«ããä½æç»é¢ã§ããã¼ã¯ã³æ
å ±ãã»ãã·ã§ã³æ
å ±ã¨ä¸è´ãããã確èªããã
Railsã§ã®å¯¾ç
ãã©ã¼ã ãè¨è¿°ããæã«form_tag ã¡ã½ããã使ã£ã¦è¨è¿°ããã
ãã©ã¡ã¼ã¿æ¹ç«
hiddenãã©ã¡ã¼ã¿ãã³ã³ãããã¯ã¹çã®ãã©ã¡ã¼ã¿ããã½ã¼ã¹ã³ã¼ãã®è¨è¿°å 容ãå¤ãã¦ãéããã©ã¡ã¼ã¿ãæ³å®å¤ã®ãã©ã¡ã¼ã¿ã«ããæ»æã
対çæ¹æ³
éããã¦ãããã©ã¡ã¼ã¿ã®ãã§ãã¯ã権éã®ç¢ºèªã確å®ã«å®æ½ããã
ã¾ãããããããããã£ããã©ã¡ã¼ã¿ã¯ãµã¼ãå´ã§ç®¡çããã
Railsã§ã®å¯¾ç
対çæ¹æ³ã«æºããã
ãã¼ã¿çæã«éã£ã¦ã¯vaildateã使ã£ã¦ç¢ºå®ã«ç¢ºèªããã®ã¯æãã
èªåã®ã¦ã¼ã¶ã¼æ
å ±ãè¦ãç»é¢ã®è¨è¨ã/user/show/1çã«ãã¦ã
idãå¤ãããä»ã®ã¦ã¼ã¶ã¼ã®å人æ
å ±ãè¦ããçãã£ã¦ã®å¤ã
ã»ãã·ã§ã³ãã¤ã¸ã£ãã¯
ä»äººãå©ç¨ãã¦ããã»ãã·ã§ã³ã®idã使ã£ã¦ã¢ã¯ã»ã¹ãããã¨ã§ä»äººã«ãªããã¾ãæ»æã
ãã°ã¤ã³æ¸ã¿ã®ã¦ã¼ã¶ã¼ã®ã»ãã·ã§ã³ããã¤ã¸ã£ãã¯ããã¨ãã®ã¦ã¼ã¶ã¼ã§ãã°ã¤ã³ããããã«æ±ãããã
対çæ¹æ³
ã»ãã·ã§ã³IDããé·ãã¦ãã¼ã¯ãªé¡æ¨ã§ããªãç©ã«ããã(1,2,3....ã®æ§ãªã®ã¯æä½)
ã»ãã·ã§ã³ã®å¤å¥ã«IPã¢ãã¬ã¹çãå«ããã
çè´ãããªãæ§ãsslãå©ç¨ããã
Railsã§ã®å¯¾ç
ã»ãã·ã§ã³IDã¯æ¢ã«é·ãã¦ãã¼ã¯ãªé¡æ¨ãè¾ãç©ãªã®ã§ãã»ãã·ã§ã³ã®å¤å¥ã«IPã¢ãã¬ã¹ã追å ãããããã
ã»ãã·ã§ã³åºå®æ»æ
CSRFã¨ã»ãã·ã§ã³ãã¤ã¸ã£ãã¯ã®åããæã®æ§ãªè¡çºã
ãªã³ã¯å
ã«ã»ãã·ã§ã³IDãä»å ãã¦ãå©ç¨ããã»ãã·ã§ã³IDãç¹å®ãããã
対çæ¹æ³
ã»ãã·ã§ã³ã®å¤å¥ã«IPã¢ãã¬ã¹çãå«ããã
ã»ãã·ã§ã³å©ç¨æã«ã»ãã·ã§ã³ãåæåããã
Railsã§ã®å¯¾çã
rails1.2.6ã§å¯¾çãããã
ãããã¨ããã¨ã»ãã·ã§ã³ã®å¤å¥ã«IPã¢ãã¬ã¹çãå«ããã
ãã°ã¤ã³æã«ã»ãã·ã§ã³ãåæåããç
SQLã¤ã³ã¸ã§ã¯ã·ã§ã³
SQLæã«å©ç¨ãããããªãã©ã¡ã¼ã¿ã«ãä½æè
ã®æ³å®å¤ã®ææ³ãæ¸ãäºã§ä¸æ£ãªåä½ãèµ·ããããæ»æã
ãã°ã¤ã³ç»é¢ã§ãuser_id,passwdã¨ãããã©ã¡ã¼ã¿ãæã£ãå ´åã
"select * from users where user_id = '" + params[:user_id] + "' and passwd = '" + params[:passwd] + "'"ã¨æ¸ããã¦ããã¨é¡æ¨ãã¦ã
passwd ã« [' or '' = ']çã¨å
¥åããç
対çæ¹æ³
å ¥åå¤ããã§ãã¯ãã¦ããsqlãå®è¡ããã
Railsã§ã®å¯¾çæ¹æ³
ActiveRecordã®conditionsãæ¸ãéã?ã確å®ã«ä½¿ãã
æ£ï¼User.find(:first,:conditions => ["user_id = ? and passwd = ?", params[:user_id], params[passwd] ])
誤ï¼User.find(:first,:conditions => "user_id = '#{ params[:user_id] }' and passwd = '#{ params[:passwd] }'")
ã¨ããããã§ã»ãã¥ãªãã£ã«ã¤ãã¦ã¾ã¨ãã¦ã¿ãã
ããããããããããï¼ãã£ã¦å¥´ããã°æ¯éæãã¦ä¸ããã