{"id":577,"date":"2018-04-07T09:39:26","date_gmt":"2018-04-07T00:39:26","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=577"},"modified":"2023-04-27T21:55:24","modified_gmt":"2023-04-27T12:55:24","slug":"%e3%80%90web%e3%82%bb%e3%82%ad%e3%83%a5%e3%83%aa%e3%83%86%e3%82%a3%e3%80%91java%e3%82%b5%e3%83%bc%e3%83%96%e3%83%ac%e3%83%83%e3%83%88%e3%81%a7%e3%80%81xss%e6%94%bb%e6%92%83%e3%82%92%e4%bd%93%e9%a8%93","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=577","title":{"rendered":"\u3010Web\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u3011Java\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8\u3067\u3001XSS\u3092\u4f53\u9a13\u3057\u3066\u307f\u308b\u3002"},"content":{"rendered":"<p>\u305d\u308c\u3067\u306f\u3001\u5b9f\u969b\u306b\u3001XSS(\u30af\u30ed\u30b9\u30b5\u30a4\u30c8\u30b9\u30af\u30ea\u30d7\u30c6\u30a3\u30f3\u30b0\uff09\u3092Java\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8\u3067\u3001\u4f53\u9a13\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u767e\u805e\u306f\u4e00\u898b\u306b\u5982\u304b\u305a\u3068\u3044\u3044\u307e\u3059\u3057\u306d\u3002<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u306a\u304a\u3001Chrome\u3060\u3068\u3001XSS\u304c\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u52d5\u304d\u307e\u305b\u3093\u306e\u3067\u3001IE\u3067\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/strong><\/span><\/p>\n<h2>XSS\u653b\u6483\u3092\u4f53\u9a13\u3059\u308b\u3002<\/h2>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;%@ page language=&quot;java&quot; contentType=&quot;text\/html; charset=UTF8&quot; pageEncoding=&quot;UTF-8&quot; %&gt;\r\n&lt;html&gt;\r\n &lt;head&gt;\r\n   &lt;title&gt;Xss\u30b5\u30f3\u30d7\u30eb&lt;\/title&gt;\r\n   &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=UTF-8&quot;&gt;\r\n &lt;\/head&gt;\r\n &lt;body&gt;\r\n \r\n\r\n\r\n&lt;form action='XssServlet' method='POST'&gt;\r\n   \u540d\u524d\uff1a&lt;input type=&quot;text&quot; name=&quot;name&quot; value=''&gt;\r\n\r\n  &lt;input type=&quot;submit&quot; value=&quot;\u9001\u4fe1&quot;&gt;\r\n &lt;\/form&gt;\r\n\r\n\r\n\r\n \r\n\r\n\r\n&lt;hr&gt;\r\n\r\n\r\n\r\n  \u9001\u4fe1\u3057\u305f\u540d\u524d\uff1a&lt;%= request.getAttribute(&quot;name&quot;) %&gt;\r\n\r\n &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage servlet;\r\n\r\nimport java.io.IOException;\r\n\r\nimport javax.servlet.RequestDispatcher;\r\nimport javax.servlet.ServletException;\r\nimport javax.servlet.annotation.WebServlet;\r\nimport javax.servlet.http.Cookie;\r\nimport javax.servlet.http.HttpServlet;\r\nimport javax.servlet.http.HttpServletRequest;\r\nimport javax.servlet.http.HttpServletResponse;\r\n\r\n@WebServlet(&quot;\/XssServlet&quot;)\r\npublic class XssServlet extends HttpServlet {\r\n\r\n@Override\r\nprotected void doGet(HttpServletRequest req,\r\nHttpServletResponse resp) throws ServletException,IOException{\r\n\r\nreq.setAttribute(&quot;name&quot;, &quot;&quot;);\r\n\r\n\/\/ \u30af\u30c3\u30ad\u30fc\u8a2d\u5b9a\r\nresp.addCookie(new Cookie(&quot;xss&quot;, &quot;xsstest&quot;));\r\n\r\ncommon(req,resp);\r\n}\r\n\r\n@Override\r\nprotected void doPost(HttpServletRequest req,\r\nHttpServletResponse resp) throws ServletException,IOException{\r\n\r\n\/\/ \u6587\u5b57\u30b3\u30fc\u30c9\u8a2d\u5b9a\r\nreq.setCharacterEncoding(&quot;UTF-8&quot;);\r\n\r\nString name = req.getParameter(&quot;name&quot;);\r\n\r\nreq.setAttribute(&quot;name&quot;, name);\r\n\r\ncommon(req,resp);\r\n}\r\n\r\nprotected void common(HttpServletRequest req,\r\nHttpServletResponse resp) throws ServletException,IOException{\r\n\r\nRequestDispatcher disp = req.getRequestDispatcher(&quot;\/xss.jsp&quot;);\r\ndisp.forward(req, resp);\r\n}\r\n\r\n}\r\n<\/pre>\n<p>\u4e0a\u8a18\u3001\u30bd\u30fc\u30b9\u3092Tomcat\u7b49\u3067\u5b9f\u884c\u3059\u308b\u3068\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u8868\u793a\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-586\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS1-1.png\" alt=\"\" width=\"382\" height=\"204\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS1-1.png 382w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS1-1-300x160.png 300w\" sizes=\"(max-width: 382px) 100vw, 382px\" \/><\/p>\n<p>\u592a\u90ce\u3068\u3001\u540d\u524d\u306e\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306b\u5165\u529b\u3057\u3066\u3001\u300c\u9001\u4fe1\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-587\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS2.png\" alt=\"\" width=\"389\" height=\"219\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS2.png 389w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS2-300x169.png 300w\" sizes=\"(max-width: 389px) 100vw, 389px\" \/><\/p>\n<p>\u305d\u3053\u3067\u3001\u4e0b\u8a18\u306eJavaScript\u3092\u540d\u524d\u6b04\u306b\u5165\u529b\u3057\u3066\u3001\u300c\u9001\u4fe1\u300d\u3092\u62bc\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;alert(document.cookie);&lt;\/script&gt;\r\n<\/pre>\n<p>\u3059\u308b\u3068\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3001\u7c21\u5358\u306b\u30af\u30c3\u30ad\u30fc\u3067\u8a2d\u5b9a\u3057\u305f\u60c5\u5831\u3092JavaScript\u3092\u4f7f\u7528\u3057\u3066\u76d7\u307f\u51fa\u305b\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-588\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS3.png\" alt=\"\" width=\"216\" height=\"191\" \/><\/p>\n<h2>\u5bfe\u7b56<\/h2>\n<p>\u4e0b\u8a18\u306e\u6587\u5b57\u3092\u3001\u8868\u793a\u3055\u305b\u308b\u7b87\u6240\u3092\u30a8\u30b9\u30b1\u30fc\u30d7\u3059\u308b\u51e6\u7406\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<div class=\"graybox\">\u300c<\u300d\u300c>\u300d\u300c&\u300d\u300c\u201d\u300d\u300c\u2019\u300d<\/div>\n<p>\u4fee\u6b63\u5f8c\u306e\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8\uff08\u30e1\u30bd\u30c3\u30c9\u300cescape\u300d\u3092\u8ffd\u52a0\u3057\u3066\u3001\u30a8\u30b9\u30b1\u30fc\u30d7\u3057\u3066\u3044\u307e\u3059\u3002\uff09 <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\"> package servlet; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet(&quot;\/XssServlet&quot;) public class XssServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException{ req.setAttribute(&quot;name&quot;, &quot;&quot;); \/\/ \u30af\u30c3\u30ad\u30fc\u8a2d\u5b9a resp.addCookie(new Cookie(&quot;xss&quot;, &quot;xsstest&quot;)); common(req,resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException{ \/\/ \u6587\u5b57\u30b3\u30fc\u30c9\u8a2d\u5b9a req.setCharacterEncoding(&quot;UTF-8&quot;); String name = req.getParameter(&quot;name&quot;); req.setAttribute(&quot;name&quot;, escape(name)); common(req,resp); } protected void common(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException{ RequestDispatcher disp = req.getRequestDispatcher(&quot;\/xss.jsp&quot;); disp.forward(req, resp); } private static String escape(String val) { if (val == null) return &quot;&quot;; val = val.replaceAll(&quot;&amp;&quot;, &quot;&amp; amp;&quot;); val = val.replaceAll(&quot;&lt;&quot;, &quot;&amp; lt;&quot;); val = val.replaceAll(&quot;&gt;&quot;, &quot;&amp; gt;&quot;); val = val.replaceAll(&quot;\\&quot;&quot;, &quot;&amp;quot;&quot;); val = val.replaceAll(&quot;'&quot;, &quot;&amp;apos;&quot;); return val; } } <\/pre>\n<p>\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u540c\u3058JavaScript\u3092\u5b9f\u884c\u3057\u3066\u3082\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30bf\u30b0\u304c\u30a8\u30b9\u30b1\u30fc\u30d7\u3055\u308c\u308b\u306e\u3067\u3001<span style=\"color: #ff0000;\"><strong>JavaScript\u304c\u5b9f\u884c\u3055\u308c\u307e\u305b\u3093\u3002<\/strong><\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-592\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS4.png\" alt=\"\" width=\"493\" height=\"188\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS4.png 493w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/04\/XSS4-300x114.png 300w\" sizes=\"(max-width: 493px) 100vw, 493px\" \/><\/p>\n<p>\u307e\u305f\u3001\u5b9f\u969b\u306e\u653b\u6483\u3067\u306f\u3001<strong>\u3053\u306e\u3088\u3046\u306b\u81ea\u5206\u306e\u30af\u30c3\u30ad\u30fc\u60c5\u5831\u3092\u76d7\u3093\u3067\u3082\u610f\u5473\u304c\u3042\u308a\u307e\u305b\u3093<\/strong>\u306e\u3067\u3001\u653b\u6483\u7528\u306e\u4ed6\u30b5\u30a4\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3089\u3001iframe\u3067\u672c\u8a18\u4e8b\u306e\u3088\u3046\u306a\u8106\u5f31\u6027\u30b5\u30a4\u30c8\u3092\u57cb\u3081\u8fbc\u3093\u3067\u3001\u30af\u30c3\u30ad\u30fc\u60c5\u5831\u3092\u76d7\u307f\u51fa\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u305d\u308c\u3067\u306f\u3001\u5b9f\u969b\u306b\u3001XSS(\u30af\u30ed\u30b9\u30b5\u30a4\u30c8\u30b9\u30af\u30ea\u30d7\u30c6\u30a3\u30f3\u30b0\uff09\u3092Java\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8\u3067\u3001\u4f53\u9a13\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u767e\u805e\u306f\u4e00\u898b\u306b\u5982\u304b\u305a\u3068\u3044\u3044\u307e\u3059\u3057\u306d\u3002 \u306a\u304a\u3001Chrome\u3060\u3068\u3001XSS\u304c\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u52d5\u304d\u307e\u305b\u3093\u306e\u3067\u3001IE\u3067\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057 [&hellip;]","protected":false},"author":1,"featured_media":607,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,9],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/577"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=577"}],"version-history":[{"count":20,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/577\/revisions"}],"predecessor-version":[{"id":19246,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/577\/revisions\/19246"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/607"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=577"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}