ã¯ããã«
ãä»åã¯XSSã®èå¼±æ§ããã§ãã¯ããPerlã¹ã¯ãªãããä½æãããã¨æãã¾ãããã¹ã¦ã®XSSã«ããèå¼±æ§ãåé¿ã§ããããã§ã¯ããã¾ãããããã¹ãã³ã¼ãä½æã®ãã³ãã«ãªãã°å¹¸ãã§ãã
対象èªè
ãWebã¢ããªã±ã¼ã·ã§ã³éçºè ã§ãXSSã®ãã¹ãã±ã¼ã¹ãä½æãããæ¹ã
å¿ è¦ãªç°å¢
ãPerl 5.8以ä¸ãåä½ããç°å¢ãåºæ¬åä½ã®ç¢ºèªã¯Mac OS Xãå©ç¨ãã¾ããã次ã®Perlã¢ã¸ã¥ã¼ã«ãå©ç¨ããã®ã§ããããããã¤ã³ã¹ãã¼ã«ãã¦ããã¦ãã ããã
ãã¾ãCGIã使ç¨ããã®ã§ãApacheãªã©ã®CGIãå®è¡ã§ããWebãµã¼ããç¨æãã¦ãã ããã
解説å 容
ã½ã¼ã¹ã³ã¼ã解説
ãã¾ãæåã«ã½ã¼ã¹ã³ã¼ãã®è§£èª¬ããã¾ãã
- xss.pl
- xss2.pl
- xss.cgi
- xss2.cgi
ããxss.cgiãã¨ãxss2.cgiãã¯CGIãå®è¡å¯è½ãªå ´æã¸è¨ç½®ãã¦ãã ããããxss.plãã¨ãxss2.plãã¯ä»»æã®å ´æã§OKã§ããæ¬ç¨¿ã§ã¯xss.cgiã¨xss2.cgiã¯ãhttp://localhost/cgi-bin/ã以ä¸ã«è¨ç½®ãã¦ããåæã§é²ãã¾ãã
ãå©ç¨ããçµã¿åããã¨ãã¦ã¯ã
- xss.plï¼xss.cgi
- xss2.plï¼xss.cgiï¼xss2.cgi
ãã«ãªãã¾ããé çªã«è§£èª¬ããã¦ããã¾ãã
åç´ãªXSSã®ãã§ãã¯
ãã¾ãã¯ã1çªç®ã®xss.plã¨xss.cgiãå©ç¨ããç°¡åãªã¹ã¯ãªãããè¦ã¾ããå¦çã®æµãã¨ãã¦ã¯æ¬¡ã®ããã«ãªãã¾ãã
- ãã©ã¼ã ãããHTMLãã¼ã¸ãåå¾ãã¾ãã
- HTMLãã¼ã¸ã®ä¸ããformã¿ã°ã«å²ã¾ãããã¹ã¦ãæãåºãã¾ãï¼è¤æ°åã®formã¿ã°ãããã°ãããããåå¾ãã¾ãï¼ã
- formã¿ã°ã®ä¸ããinputãselectãtextareaã®nameå±æ§ãããããWeb::Scraperã¢ã¸ã¥ã¼ã«ã使ã£ã¦æ½åºãã¾ãã
- ä¸è¨ã§åå¾ããnameå±æ§ãå©ç¨ãã¦æªæããã¹ã¯ãªããã®ä¾
<code><script>alertï¼"XSS"ï¼;</script></code>
ãã¯ã¨ãªã¼æååã«ã®ãã¦éä¿¡ãã¾ãã - éä¿¡ããå¾ã®ãã¼ã¸ãåå¾ãã¦ãã¹ã¯ãªããããã®ã¾ã¾æ®ã£ã¦ãããã©ããããã§ãã¯ãã¾ããã¹ã¯ãªããããã®ã¾ã¾æ®ã£ã¦ããã¨ãããã¨ã¯ãã¹ã¯ãªãããå®è¡ãããå¯è½æ§ãããã¨ãããã¨ã§NGã¨ãã¾ããã¹ã¯ãªãããæ®ã£ã¦ããªããã°ã¨ã¹ã±ã¼ããããã¨è¦ãªãã¦OKã¨ãã¾ãã
ãOKãNGãã®ãã§ãã¯ãããéã«ã¯ãTest::Simpleã¢ã¸ã¥ã¼ã«ã®ok
ã¡ã½ãããæã£åãæ©ãã§ããprove
ã³ãã³ãã使ããã¨ã§ã¬ãã¼ããã¾ã¨ã¾ãã¾ããå®è¡æ¹æ³ã¯<code>perl xss.pl</code>
ã§ã¯ãªãã次ã®ããã«è¡ãã¾ãï¼ãã¡ãã<code>perl xss.pl</code>
ã§ãæ§ãã¾ããï¼ã
$ prove xss.pl xss.... # Failed test 'p1' # in xss.pl at line 41. xss....ok 2/0 xss....NOK 3# Failed test 'p3' # in xss.pl at line 41. # Failed test 'mode' # in xss.pl at line 41. # Looks like you failed 3 tests of 6. xss....dubious Test returned status 3 (wstat 768, 0x300) DIED. FAILED tests 1, 3, 6 Failed 3/6 tests, 50.00% okay Failed Test Stat Wstat Total Fail List of Failed --------------------------------------------------------------------- xss.pl 3 768 6 3 1 3 6 Failed 1/1 test scripts. 3/6 subtests failed. Files=1, Tests=6, 1 wallclock secs (0.20 cusr + 0.03 csys = 0.23 CPU) Failed 1/1 test programs. 3/6 subtests failed.
ã3件ã®NGãçºçãããã¨ãåããã¾ããå¾ã¯Failãããã¹ãã±ã¼ã¹ã解æ¶ãã¦ãããã¨ã§XSSã®èå¼±æ§ããåé¿ã§ãããã¨ã§ãããã
ãTemplate::Toolkitã«ã¯ãã£ã«ã¿æ©è½ãåãã£ã¦ãã¦ãHTMLãã¨ã¹ã±ã¼ããã¦ãããæ©è½ãããã¾ãã|
ã®ãã¨ã«html
ã¨è¨è¿°ããã ãã§ãããã®è¨è¿°ããã°ã¨ã¹ã±ã¼ããã¦åºåãã¦ããã¾ãã®ã§XSS対çã«éå®ãã¾ãã
[% value | html %]
ãxss.cgiã®get_template
ã¡ã½ããã«è¨è¿°ãããTemplate Toolkitã®ãã£ã¬ã¯ãã£ãã®é¨åãã¹ã¦ã«htmlãã£ã«ã¿ãè¨è¿°ãããã¨ã§ãã¹ãã±ã¼ã¹ããã¹ã¦okã«ãªãã¨æãã¾ãã試ãã¦ã¿ã¦ãã ããã
$ prove xss.pl xss....ok All tests successful. Files=1, Tests=6, 1 wallclock secs (0.20 cusr + 0.03 csys = 0.23 CPU)
ãããã§XSSã®èå¼±æ§ã®ãªã¹ã¯ãåé¿ãããã¨ãã§ãã¾ããã
ããæ±ç¨çãªã¹ã¯ãªãã
ã次ã«ã2çªç®ã®xss2.plã¨xss.cgiã¨xss2.cgiãå©ç¨ããå ´åãè¦ã¾ãã
ãæ¨ä»ã®Webãµã¼ãã¹ãè¦ãã¨å ¥åãã©ã¼ã ã®ç´å¾ã«çµæã表示ãããã±ã¼ã¹ã¯ç¨ã«ãªã£ã¦ãã¾ãããä¾ãã°ããã°ãã¼ã«ã®ããã«ç®¡çç»é¢ã§æ稿ããå¾ã«å¥ã®URLã§ãã®çµæãåç §ãããã¨ã®æ¹ãå¤ãã¨æãã¾ããããã§xss.plãããå°ãæ±ç¨çã«ãã¦ã¿ããã¨æãã¾ãã
ãxss.plã§ã¯ãscrape_and_check
ã¡ã½ããã§formé¨åã®ã¹ã¯ã¬ã¤ãã³ã°ã¨ãã¼ã¿ã®éä¿¡ã¨çµæã®ãã§ãã¯ãåæã«è¡ã£ã¦ãã¾ããããã®é¨åã¯åé¢ãããã¨ããã§ããçµæã®ãã§ãã¯é¨åãå¥ã¡ã½ããã¨ãã¦å®ç¾©ãããã¨ã§å½¹å²ãåæ
ãã¾ããã
ãããã«xss.plã§ã¯ãã¼ã¿ãç´æ¥ã½ã¼ã¹ã³ã¼ãã«è¨è¿°ãã¦ãã¾ãããããã ã¨ãã§ãã¯ããããµã¤ããå¢ãããã³ã«ã½ã¼ã¹ã³ã¼ãã«æãå ¥ããå¿ è¦ãåºã¦ããã®ã§å°ãåä»ã§ããããã§ãTest::Baseã¢ã¸ã¥ã¼ã«ãå©ç¨ãããã¨ã§ãã¹ããã¼ã¿ã¨ã½ã¼ã¹ã³ã¼ããåé¢ããã¦æ±ç¨æ§ãå®ç¾ãã¾ããã
ãTest::Baseã§ã¯ãã¹ããã¼ã¿é¨åã¯ã__END__
以éã«è¨è¿°ãã¾ãã===
ããã¼ã¿ãããã¯ã®åºåããæå³ãã---
ããã¼ã¿ã®ã»ã¯ã·ã§ã³ã®åºåããæå³ãã¾ããããã¦filteræ©è½ãå©ç¨ãããã¨ã§ãã¹ããã¼ã¿é¨åãyamlã§è¨è¿°ãããã¨ãã§ãã¾ããxss2.plã§ã¯yamlã使ã£ã¦ãã¹ããã¼ã¿ãçæãã¾ããã
__END__ === XSS Data --- input form_url: http://localhost/cgi-bin/xss.cgi check_urls: - http://localhost/cgi-bin/xss2.cgi - http://localhost/cgi-bin/xss2.cgi?text=1 - http://localhost/cgi-bin/xss2.cgi?attr=1 script: <script>alert("XSS");</script>
ã¾ã¨ã
ãXSSã®ãã¹ããå®æ½ããããã¼ã¸ãè¤æ°ããå ´åã¯ãã¹ããã¼ã¿é¨åã«è¿½å ããã¨è¯ãã¨æãã¾ããã¾ããã°ã¤ã³ãå¿
è¦ãªãã¼ã¸ã«ã¤ãã¦ã¯ãget_form_html
ã¡ã½ãããæ¡å¼µãããã¨ã§å¯¾å¦å¯è½ã«ãªãã®ã§ã¯ãªãã§ããããã
ãæ¬ç¨¿ã®ãµã³ãã«ã¹ã¯ãªããã§ãã¹ã¦ã®XSSãæ¤ç¥ã§ããããã§ã¯ããã¾ããããèª¤å ±ãçºçããå¯è½æ§ãããã¾ãããããã1ã¤ã§ãå¤ãã® XSS ã«ããèå¼±æ§ãåãé¤ãããã®ãäºå®ã§ããçãããéå¶ã¾ãã¯éçºãããWebãµã¼ãã¹ãå°ãã§ãã»ãã¥ã¢ãªç°å¢ã«ãªãããããã®åèã«ãªãã°å¹¸ãã§ãã