ç§ãã¡ã®ããã°ã©ã ã«ã¯ãOAuth2ä»æ§ã匱ç¹ãè åšã¢ãã«ã®
OAuth2ã¯ãã
é·ããŠãæ£ããåŠç¿æ¹æ³ã
æ zyãªäººã®ããã«ãç§ã¯èªåã®èšèã§æãäžè¬çã§å®å šãªãå¥åãµãŒããŒãµã€ããšããŠæ¿èªã³ãŒããããŒã説æããŸã ã
äž»ãªæŠå¿µã¯ãã¯ã©ã€ã¢ã³ãïŒãŠã§ããµã€ã/ãªã³ã©ã€ã³ã²ãŒã /ã¢ããªïŒããŠãŒã¶ãŒïŒããªãïŒããããã€ããŒïŒfacebook / vkontakte / googleïŒãã³ãŒãïŒã³ãŒãïŒããã³ããŒã¯ã³ïŒaccess_tokenïŒã§ãã
ã¯ã©ã€ã¢ã³ãã¯ãŠãŒã¶ãŒãéä¿¡ããŸã-ããªãœãŒã¹ãžã®ã¢ã¯ã»ã¹ãèš±å¯ããŠãã ãããã ãŠãŒã¶ãŒã¯ãããã€ããŒãžã®ãªã³ã¯ããã©ããå¿ èŠãªãã®ãæ¢ããŸã-ã¹ã³ãŒããã©ã¡ãŒã¿ãŒ-[èš±å¯]ãã¯ãªãã¯ããŸãã ããã«ããããã€ããŒã¯ã次ã®ãã©ã¡ãŒã¿ãŒã䜿çšããŠãã¯ã©ã€ã¢ã³ãã®ãã¡ã€ã³äžã®æå®ãããredirect_uriã«ãªãã€ã¬ã¯ãããŸãã
code-ãããã€ããŒã®ãŠãŒã¶ãŒã®èå¥åãã¯ã©ã€ã¢ã³ãã¯ããŒã¯ã³ãåä¿¡ããå¿ èŠããããŸã
state-éå§URLã«æž¡ãããã®ãšåãå€ã CSRFã«å¯Ÿããä¿è·ãšå©äŸ¿æ§ã®ããã«äœ¿çšãããŸãã
ã³ãŒãã¯ããŠãŒã¶ãŒïŒããã³ãããããŠãŒã¶ãŒãšãŒãžã§ã³ãïŒã®å€ãè¡šããŸããã ãã®å©ããåããŠãAPIãªã¯ãšã¹ããè¡ãããšã¯ã§ããŸãããããã¯ãããŒã¯ã³ã®ååŸãšãã1ã€ã®ç®çã«ã®ã¿å¿ èŠã§ãã
ããŒã¯ã³ãåä¿¡ããããã«ãã¯ã©ã€ã¢ã³ãã¯ç¹å®ã®ãšã³ããã€ã³ããèŠæ±ããã³ãŒããåä¿¡ããclient_idãclient_secretãcodeãredirect_uriãæž¡ããŸãããããã£ãŠããããã€ããŒã¯ãããæ£ããã¯ã©ã€ã¢ã³ãã§ãããåããŠãŒã¶ãŒã®ããŒã¯ã³ãäžããã³ãŒãã§ãããšç¢ºä¿¡ããŸãã ã芧ã®ãšããããŠãŒã¶ãŒããŠãŒã¶ãŒãšãŒãžã§ã³ããã¯ã©ã€ã¢ã³ãã¹ã¯ãªããã®ããããå®éã®ããŒã¯ã³ãèŠãŠããŸããã ã¯ã©ã€ã¢ã³ããšãããã€ããŒã ãã圌ãç¥ã£ãŠããŸã-çæ³çã§ãã
ããã«ãããŒã¯ã³ã¯APIãªã¯ãšã¹ãã®äœæã«äœ¿çšãããåŸã§æŽæ°ã§ããŸãïŒãã®ãããrefresh_tokenã¯ããŒã¯ã³ãšãšãã«è¿ãããŸãïŒã
è åšã¢ãã«ãŸãã¯ããªãã®èããç¥ã£ãŠããŸã
é·ããŠãæ£ããæ¹æ³ã¯ãOAuthãå®å šã«äœ¿çšããããšã§ãã
ããã§ç§ã¯æ³šæããŸãïŒ
1.ãããŠãç§ã®ãµã€ãã«ã€ãªããredirect_uriã眮ãæããŠããã®ã³ãŒããèªåã§èªèšŒã«äœ¿çšãããšã©ããªããŸããïŒ
ãã¹ãŠã®redirect_uriã¯ã¯ã©ã€ã¢ã³ãã®ãã¡ã€ã³äžã«ãªããã°ãªããŸããã å€ãã®å Žåãå¥ã®ãããã€ããŒãã¡ã€ã³ãèš±å¯ãããŸãã ãªã³ã¯ã¯redirect_uri_mismatchãè¿ããŸãã
2. OKãããããã¯ã©ã€ã¢ã³ãã®Webãµã€ãã§ã³ãŒããçµ±åããå ŽæãèŠã€ããå Žåã¯ã©ããªããŸããïŒ ãã¶ããsite.comïŒurl = httpïŒ//outsite.comã®åœ¢åŒã®ãªãŒãã³ãªãã€ã¬ã¯ããããªãã¡ã©ãŒãããŒãžããããããªã³ã¯ãããç»åã§ããããïŒ
åã³ãŒãã¯ãçºè¡ãããredirect_uriã«é¢é£ä»ããããŠãããããŒã¯ã³ãåä¿¡ããããã«ãã¯ã©ã€ã¢ã³ãã¯ãæ£ãããredirect_uriãéä¿¡ããŸãã ã³ãŒããclientsite.com/leak_refererã«å¯ŸããŠçºè¡ãããã¯ã©ã€ã¢ã³ããããŒã¯ã³ã®åä¿¡æã«clientsite.com/facebook_callbackãéä¿¡ããå Žåããããã€ããŒã¯ããŒã¯ã³ãæäŸããŸããã
3.æ£ããredirect_uriãæž¡ãããšã§ãäœããã®æ¹æ³ã§ã³ãŒããããŒãžããããšã¯å¯èœã§ããïŒ
ãããããªããªã ã¯ã©ã€ã¢ã³ãã®é©åãªå®è£ ã¯ãã³ãŒããåãåã£ãåŸããã«å¥ã®ããŒãžã«ãªãã€ã¬ã¯ãããå¿ èŠããããŸãããã®ãããã³ãŒãã¯ãã©ãŠã¶ã®å±¥æŽã«ã衚瀺ãããŸããã
æ£ããredirect_uriã®ã³ãŒããååŸã§ãããšããŠã ã¢ã¯ãã£ãã§ãªããªããšããã§ã«äœ¿çšãããŠããŸãã
4.æ£ããredirect_uriã«å¯ŸããŠçºè¡ããããœãŒã·ã£ã«ãããã¯ãŒã¯äžã®ã¢ã«ãŠã³ãã®ã³ãŒãããããšããŸãã Vasyaã«ãã®ãªã³ã¯ã蚪åããããšã©ããªããŸããïŒ
ãã®å Žåãã¯ã©ã€ã¢ã³ãã®ãŠã§ããµã€ãã¯ããœãŒã·ã£ã«ãããã¯ãŒã¯ã®ã¢ã«ãŠã³ããVasyaã«å±ããŠãããšå€æããŸãã ãããŠæ¥ç¶ããŸãã äžè¬çãªCSRFã®çºçãé²ãããã«ãã¯ã©ã€ã¢ã³ãã¯ã»ãã·ã§ã³/ Cookieã«ã©ã³ãã ãªç¶æ å€ãä¿åãããªã¿ãŒã³ã³ãŒã«ããã¯ã®ã³ã³ãã©ã€ã¢ã³ã¹ããã§ãã¯ããå¿ èŠããããŸãã ãã ãããããè¡ã人ã¯ã»ãšãã©ããŸããïŒãŸãã¯ããŸããã§ããïŒã
çŸå®
FBè¿ä¿¡æ»æ
Facebook Connectã¯ãåŸæ¥ã®Replayæ»æã«å¯ŸããŠè匱ã§ãã
ãã€ã³ã3ã¯ãã³ãŒãã1å䜿çšããåŸã§ãã60ã80å以å ã«èªèšŒã«äœ¿çšã§ããããšã瀺ããŠããŸããããã¯ãããŒã¯ã³ã®æšæºã®expire_inã§ãã æãçŽç²ãªåœ¢ã§ãªãã¬ã€æ»æã
ãµã€ãã§XSSãèŠã€ãããšããŸããã-ãã®ã€ã³ãžã§ã¯ã·ã§ã³ã®ãããªãã®ã¯ãdocument.referrerãã¬ãŒã ãéããŠæ£ããredirect_uriã®ã³ãŒããååŸããã®ã«åœ¹ç«ã¡ãŸãã
ã¬ããŒããå®æããããã«ä¿®æ£ããŸãã ãŸããããã«ãçŽ3ãæããšã³ã¿ãŒãã©ã€ãº
ã¢ã«ãŠã³ãã®ãã€ãžã£ãã¯
ããšãã°ãæãäžè¬çãªè匱æ§ã¯ããã«ååšããŸãã詳现ã«ã€ããŠã¯ä»¥äžãåç §ããŠãã ããã ãã€ã³ã4ã«éåããŠããŸãã
ãªã¯ãšã¹ãã«ç¶æ ã衚瀺ãããŠããå Žåã¯ããããããªãã§ãã ããã digg.comãa12b6467c3fb385e237109502277ab26ãšheyman0day123123ã®éããèªèããªãã£ãhabr
VK redirect_uri
å®è£
ã¯ããã€ãã®å€ä»£ã®åçš¿ã«åŸã£ãŠè¡ãããŸãã-ã³ãŒããçºè¡ãããredirect_uriã®æ€èšŒã®æ¬ åŠã¯ããã©ã°ã©ã3ã®é倧ãªéåã§ãã
ã芧ãã ããã ããã«ãªã³ã¯ããããŸãã®ã§ãæããã«ãããã¯ãŒã¯ããã«ãæŒããŠãã ãã ã ãªã¯ãšã¹ããåç §ããŠãã ããïŒ
ãªãã¡ã©ãŒãããŒãžãããã³ãŒããããŒãžãããŸãã-æ£ããredirect_uriã«é¢ããVKontakteïŒãªã³ã¯ããŠããå ŽåïŒãä»ããŠã¢ã«ãŠã³ãã«ãã°ã€ã³ããããã«äœ¿çšã§ããããã«ãªããŸããã
ã¬ããŒãã¯1é±éåã«äœæãããŸããããçããŠãã人ããããããã®å¿çã¯ãããŸããã§ããã
ãã®ä»
æé»çãããŒã䜿çšããŠããå Žå-ã€ãŸã ãŠãŒã¶ãŒããaccess_tokenãçŽæ¥ååŸããå Žåããã®ããŒã¯ã³ãçŸåšã®ãŠãŒã¶ãŒã«å±ãããšããä¿èšŒã¯ãããŸããã 圌ã¯åã«æªæã®ããã¯ã©ã€ã¢ã³ããä»ããŠãããçã¿ãããã䜿çšããŠããªãã®ãµã€ãã®ãããŠãŒã¶ãŒã®ã¢ã«ãŠã³ãã«å ¥ãå¯èœæ§ããããŸãã
ãã®ããŒã¯ã³ãclient_idã«å¯ŸããŠçºè¡ãããŠãããã©ãããå¿ ã確èªããŠãã ããã
ãŸããOAuth2ã¯ããŠãŒã¶ãŒãscopeãã©ã¡ãŒã¿ãŒã®æ¿èªæ®µéã§èŠæ±ããæš©éããŠãŒã¶ãŒã«ä»äžããããšãä¿èšŒããŸããã 圌ã¯åã«ããããåé€ããããšãã§ããŸã -æåŸã«ãããªããèŠæ±ãããã®ãèš±å¯ãããã©ãããã³ãŒã«ããã¯ã§ç¢ºèªããå¿ èŠããããŸãã
ãµã€ãã§XSSãèŠã€ãã£ãå Žåãaccess_token-sã倧éã«çãç°¡åãªæ¹æ³ããããŸãã ãµã€ããfacebookã«äœ¿çšããèªèšŒURLãååŸããresponse_type = codeãããŒã¯ã³ã«çœ®ãæããŸãã ãã®URLããã¬ãŒã ã«æ¿å ¥ããããŒã¯ã³ãã³ãŒã«ããã¯ãã©ãŒã ïŒaccess_token = 123ã®ãªã³ã¯ã«æ»ãã®ãåŸ ã£ãŠãããŒã¯ã³ãã«ããããŠããŒãžããŸãã å¥åº·äžã®ã¹ãã ïŒ
ããã©ãŒã§ã®0day
åããšã¯ã¹ããã€ããfacebook / googleã§ãæ©èœããŸããã³ãŒãã䜿çšããã«redirect_uriãååŸããã®ã¯é£ãããªããŸããNoRedirect+ FFãå¿ èŠã§ã
ãããã£ãŠãVKã®ãã¢ã
1. VKãæ¥ç¶ããªãã§ãã ããã ãã°ã€ã³oauth.vk.com/authorize?response_type=code&client_id=3110645&redirect_uri=http%3A%2F%2Fhabrahabr.ru&scope=offline&display=page
2. habrahabr.ru/?code=CODEã«æ»ããŸãã
3.å¥ã®habruiserã«habrahabr.ru/social/callback/vkontakte/?code=CODE&state=whogivesafuckaboutstateã«ã¢ã¯ã»ã¹ããŸãããªã³ã¯èªäœã¯ã¹ããŒã§ããŸãããimgãiframeãªã©ã§é衚瀺ã«ããæ¹ãè¯ãã§ãããã ããã«ãã°ã€ã³ããŠããå ŽåãVKã¯ããã¢ã«ãŠã³ãã«é¢é£ä»ããããŠããŸãã
4. VKããhabraaccountã«ãã°ã€ã³ããã¢ãã¿ãŒãnayncatã«å€æŽããŸãã
é埳
Vkontakte ïŒSupportã®æåãç¡èŠããã®ããããããéçºè ã«æ¥ãŠãåãªã人éãšè©±ãããããäŸé ŒããŠãã ããã ãŸããå ±å¥šéããã°ã©ã ã«ãåå ããŠãã ããïŒç®èïŒç Žããããªã¹ã¯ããããŸãïŒã
Habr ïŒãã°ããããŒãã¹ã¿ãŒããªãã«ããCookie /ã»ãã·ã§ã³ã®å€ã§ãç¶æ ããæ£ãããã§ãã¯ããããšã§è匱æ§ãä¿®æ£ããããšããå§ãããŸãã
å°çãžã®éã¯çãã ããŒãªã³ã°ããŒã¯ã³-OAuth2.aïŒ Charm-Provider ïŒã䜿çšããŠãæ ¹æ¬çã«æ°ããæšæºã®éçºã«åå ã§ããŸã ã 確ãã«ãã¯ãããŒã¯ãããŸããã
ãšãŽãŒã«ã» ããã³ã ïŒ @homakov ïŒïŒ ã€ã·ãŠã«ã¹ #RT pls
UPD2ïŒ
Habrã¯è匱æ§ãéããvkontakteã¯ãã¹ãŠã®æ°ããã¢ããªã±ãŒã·ã§ã³ã®redirect_uriãã§ãã¯ãšå€ãã¢ããªã±ãŒã·ã§ã³ã®éç¥ãfacebookãè¿œå ããŸããããèš±å¯ã³ãŒãã¯ã¢ã¯ã»ã¹ããŒã¯ã³ãš1åã ã亀æã§ããäœæåŸ10å以å ã«ã¢ã¯ã»ã¹ããŒã¯ã³ãšäº€æããå¿ èŠããããŸãã ãæäŸããããã°ã®è©³çŽ°ã確èªããåŸãã»ãã¥ãªãã£ããŒã ã¯ã2,000ç±³ãã«ã®å ±å¥šéãåãåãè³æ Œããããšå€æããŸããããšå床ããå¯ããŸãã 人ã ã¯å ±å¥šévkã®èŠéãã«ã€ããŠæšæž¬ããŸãã