{"id":96,"date":"2022-04-14T12:55:50","date_gmt":"2022-04-14T04:55:50","guid":{"rendered":"https:\/\/www.hm-zy.cn\/?p=96"},"modified":"2022-09-01T23:08:47","modified_gmt":"2022-09-01T15:08:47","slug":"fastjson","status":"publish","type":"post","link":"https:\/\/www.hm-zy.cn\/?p=96","title":{"rendered":"Fastjson\u539f\u7406\u548c\u5229\u7528"},"content":{"rendered":"<h3>fastjson\u53cd\u5e8f\u5217\u5316\u539f\u7406<\/h3>\n<p>\u5728\u8bf7\u6c42\u5305\u91cc\u9762\u4e2d\u53d1\u9001\u6076\u610f\u7684json\u683c\u5f0fpayload\uff0c\u6f0f\u6d1e\u5728\u5904\u7406json\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u6ca1\u6709\u5bf9@type\u5b57\u6bb5\u8fdb\u884c\u8fc7\u6ee4\uff0c\u4ece\u800c\u5bfc\u81f4\u653b\u51fb\u8005\u53ef\u4ee5\u4f20\u5165\u6076\u610f\u7684TemplatesImpl\u7c7b\uff0c\u800c\u8fd9\u4e2a\u7c7b\u6709\u4e00\u4e2a\u5b57\u6bb5\u5c31\u662f_bytecodes\uff0c\u6709\u90e8\u5206\u51fd\u6570\u4f1a\u6839\u636e\u8fd9\u4e2a_bytecodes\u751f\u6210java\u5b9e\u4f8b\uff0c\u8fd9\u5c31\u8fbe\u5230fastjson\u901a\u8fc7\u5b57\u6bb5\u4f20\u5165\u4e00\u4e2a\u7c7b\uff0c\u518d\u901a\u8fc7\u8fd9\u4e2a\u7c7b\u88ab\u751f\u6210\u65f6\u6267\u884c\u6784\u9020\u51fd\u6570\u3002<\/p>\n<h3>fastjson\u4e0d\u51fa\u7f51\u5982\u4f55\u5229\u7528?<\/h3>\n<p>1.\u5c06\u547d\u4ee4\u6267\u884c\u7ed3\u679c\u5199\u5165\u5230\u9759\u6001\u8d44\u6e90\u6587\u4ef6\u91cc\uff0c\u5982html\u3001js\u7b49\uff0c\u7136\u540e\u901a\u8fc7http\u8bbf\u95ee\u5c31\u53ef\u4ee5\u76f4\u63a5\u770b\u5230\u7ed3\u679c<br \/>\n2.\u901a\u8fc7dnslog\u8fdb\u884c\u6570\u636e\u5916\u5e26<br \/>\n3.\u76f4\u63a5\u5c06\u547d\u4ee4\u6267\u884c\u7ed3\u679c\u56de\u663e\u5230\u8bf7\u6c42Poc\u7684HTTP\u54cd\u5e94\u4e2d<br \/>\n4.\u6ce8\u5165\u5185\u5b58\u9a6c<br \/>\n5.\u4f7f\u7528\u53cd\u5e8f\u5217\u5316\u94fe\u76f4\u63a5\u672c\u5730\u53cd\u5e8f\u5217\u5316<\/p>\n<p>BasicDataSource`(tomcat-dbcp:7.x, tomcat-dbcp:9.x, commons-dbcp:1.4)<br \/>\nTemplatesImpl\u3001BCEL\u94fe\u5229\u7528\u3001c3p0\u5229\u7528<\/p>\n<h3>\u4f7f\u7528<code>JSON.parse()<\/code>\u548c<code>JSON.parseObject()<\/code>\u7684\u4e0d\u540c<\/h3>\n<p>\u524d\u8005\u4f1a\u5728JSON\u5b57\u7b26\u4e32\u4e2d\u89e3\u6790\u5b57\u7b26\u4e32\u83b7\u53d6<code>@type<\/code>\u6307\u5b9a\u7684\u7c7b\uff0c\u540e\u8005\u5219\u4f1a\u76f4\u63a5\u4f7f\u7528\u53c2\u6570\u4e2d\u7684<code>class<\/code>\uff0c\u5e76\u4e14\u5bf9\u5e94\u7c7b\u4e2d\u6240\u6709<code>getter<\/code>\u548c<code>setter<\/code>\u90fd\u4f1a\u88ab\u8c03\u7528<\/p>\n<h3>\u4ec0\u4e48\u60c5\u51b5\u4e0b\u53cd\u5e8f\u5217\u5316\u8fc7\u7a0b\u4f1a\u53cd\u5c04\u8c03\u7528<code>getter<\/code><\/h3>\n<p>\u7b26\u5408<code>getter<\/code>\u89c4\u8303\u7684\u60c5\u51b5\u4e14\u4e0d\u5b58\u5728<code>setter<\/code><\/p>\n<h3>\u5982\u679c\u4e0d\u5b58\u5728<code>setter<\/code>\u548c<code>getter<\/code>\u65b9\u6cd5\u53ef\u4ee5\u53cd\u5c04\u8bbe\u7f6e\u503c\u5417<\/h3>\n<p>\u9700\u8981\u670d\u52a1\u7aef\u5f00\u542f<code>Feature.SupportNonPublicFiel<\/code>\u53c2\u6570\uff0c\u5b9e\u6218\u65e0\u7528<\/p>\n<h3>Fastjson\u5728\u53cd\u5e8f\u5217\u5316<code>byte[]<\/code>\u7c7b\u578b\u7684\u5c5e\u6027\u65f6\u4f1a\u505a\u4ec0\u4e48\u4e8b\u60c5<\/h3>\n<p>\u5c06\u4f1a\u5728\u53cd\u5e8f\u5217\u5316\u65f6\u5019\u8fdb\u884c<code>base64<\/code>\u7f16\u7801<\/p>\n<h3>\u5e38\u89c1\u7684\u51e0\u79cdPayload<\/h3>\n<p>\u9996\u5148\u662f\u6700\u5e38\u89c1\u7684<code>JdbcRowSetImpl<\/code>\u5229\u7528<code>JDNI<\/code>\u6ce8\u5165\u65b9\u5f0f\u89e6\u53d1\uff0c\u9700\u8981\u51fa\u7f51<\/p>\n<p>\u5229\u7528<code>TemplatesImpl<\/code>\u7c7b\u6bd4\u8f83\u9e21\u808b\uff0c\u9700\u8981\u670d\u52a1\u7aef\u5f00\u542f\u7279\u6b8a\u53c2\u6570<\/p>\n<p>\u4e0d\u51fa\u7f51\u7684\u5229\u7528\u65b9\u5f0f\u6709\u4e00\u79cd<code>BasicDataSource<\/code>\u914d\u5408<code>BCEL<\/code>\u53ef\u5b9e\u73b0<code>RCE<\/code><\/p>\n<p>\u53e6\u5916\u67d0\u4e2a\u7248\u672c\u4e4b\u540e\u652f\u6301<code>$ref<\/code>\u7684\u529f\u80fd\uff0c\u4e5f\u53ef\u4ee5\u6784\u9020\u4e00\u4e9bPayload<\/p>\n<h3>1.2.47\u7248\u672c\u4e4b\u524d\u5404\u4e2a\u5c0f\u7248\u672c\u7684\u7ed5\u8fc7<\/h3>\n<p>\u9996\u5148\u662f\u5229\u7528\u89e3\u6790\u95ee\u9898\u53ef\u4ee5\u52a0\u62ec\u53f7\u6216\u5927\u5199L\u7ed5\u8fc7\u4f4e\u7248\u672c\uff0c\u9ad8\u7248\u672c\u5229\u7528\u4e86\u54c8\u5e0c\u9ed1\u540d\u5355\uff0c\u4e4b\u6240\u4ee5\u8981\u54c8\u5e0c\u662f\u56e0\u4e3a\u9632\u6b62\u9ed1\u5ba2\u8fdb\u884c\u5206\u6790\u3002\u4f46\u9ed1\u540d\u5355\u8fd8\u662f\u88ab\u7834\u89e3\u4e86\uff0c\u6709\u5e08\u5085\u627e\u5230\u53ef\u4ee5\u7ed5\u8fc7\u4e86\u7c7b\u3002\u57281.2.47\u7248\u672c\u4e2d\u5229\u7528\u7f13\u5b58\u7ed5\u8fc7<\/p>\n<h3>Fastjson\u63a2\u6d4b<\/h3>\n<p>\u4f7f\u7528<code>dnslog<\/code>\u505a\u68c0\u6d4b\u662f\u6700\u5e38\u89c1\u7684\u65b9\u5f0f\uff0c\u5229\u7528<code>java.net.Inet[4][6]Address<\/code>\u6216<code>java.net.InetSocketAddress<\/code>\u6216<code>java.net.URL<\/code>\u7c7b\uff0c\u4e4b\u6240\u4ee5\u4f7f\u7528\u8fd9\u4e09\u4e2a\u56e0\u4e3a\u4e0d\u5728\u9ed1\u540d\u5355\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u68c0\u6d4b<\/p>\n<p>\u9664\u4e86\u8fd9\u79cd\u65b9\u5f0f\uff0c\u8fd8\u53ef\u4ee5\u81ea\u884c\u5b9e\u73b0\u865a\u5047\u7684<code>JNDI Server<\/code>\u4f5c\u4e3a\u53cd\u8fde\u5e73\u53f0\uff0c\u7528<code>JdbcRowSetImpl<\/code>\u8fd9\u6837\u7684<code>Payload<\/code>\u6765\u89e6\u53d1<\/p>\n<p>\u5982\u679c\u4e0d\u80fd\u51fa\u7f51\uff0c\u53ef\u4ee5\u7ed3\u5408\u4e0d\u51fa\u7f51\u7684\u5229\u7528\u65b9\u5f0f\u548c\u4e2d\u95f4\u4ef6\u7684\u56de\u663e\u624b\u6bb5\uff0c\u6267\u884c\u65e0\u5bb3\u547d\u4ee4\u68c0\u6d4b\uff0c\u6216\u5229\u7528\u62a5\u9519\u56de\u663e<\/p>\n<h3>1.2.68\u7248\u672c\u7684\u7ed5\u8fc7<\/h3>\n<p>1.2.68\u4e4b\u524d\u768466\u548c67\u53ef\u4ee5\u5229\u7528<code>JNDI<\/code>\u76f8\u5173\u7c7b\uff0c\u6bd4\u5982<code>Shiro<\/code>\u7684<code>JndiObjectFactory<\/code>\u548c<code>ignite<\/code>\u9879\u76ee\u7684\u7c7b<\/p>\n<p>1.2.68\u4e2d\u6709\u4e00\u4e2a\u671f\u671b\u7c7b\u5c5e\u6027\uff0c\u5b9e\u73b0\u4e86\u671f\u671b\u63a5\u53e3\u7684\u7c7b\u53ef\u4ee5\u88ab\u53cd\u5e8f\u5217\u5316<\/p>\n<p>\u5229\u7528\u7c7b\u5fc5\u987b\u662f<code>expectClass<\/code>\u7c7b\u7684\u5b50\u7c7b\u6216\u5b9e\u73b0\u7c7b\uff0c\u5e76\u4e14\u4e0d\u5728\u9ed1\u540d\u5355\u4e2d\uff0c\u5373\u53ef\u76f4\u63a5\u7ed5\u8fc7<code>AutoType<\/code>\u68c0\u6d4b\uff0c\u4f8b\u5982\u5e38\u89c1\u7684<code>AutoCloseable<\/code><\/p>\n<p>\u8fd9\u6837\u7684Payload\u901a\u5e38\u7b2c\u4e00\u4e2a<code>@type<\/code>\u662f<code>AutoCloseable<\/code>\u7b49\u5408\u6cd5\u7c7b\uff0c\u7b2c\u4e8c\u4e2a<code>@type<\/code>\u662f\u6076\u610f\u7c7b\uff0c\u540e\u7eed\u53c2\u6570\u662f\u6076\u610f\u7c7b\u9700\u8981\u7684\u53c2\u6570<\/p>\n<h3>Fastjson\u7684WAF Bypass\u624b\u6bb5<\/h3>\n<p>Fastjson\u9ed8\u8ba4\u4f1a\u53bb\u9664\u952e\u503c\u5916\u7684\u7a7a\u683c\u3001\\b\u3001\\n\u3001\\r\u3001\\f\u7b49\u5b57\u7b26\uff0c\u540c\u65f6\u8fd8\u4f1a\u81ea\u52a8\u5c06\u952e\u503c\u8fdb\u884c<code>unicode<\/code>\u4e0e\u5341\u516d\u8fdb\u5236\u89e3\u7801<\/p>\n<p>\u4f8b\u5982\u9488\u5bf9<code>@type<\/code>\u7684\u7ed5\u8fc7\uff1a<code>\\u0040\\u0074\\u0079\\u0070\\u0065<\/code><\/p>\n<p>\u52a0\u5165\u7279\u6b8a\u5b57\u7b26\u7684\u7ed5\u8fc7\uff1a<code>{\\n&quot;@type&quot;:&quot;com.sun.rowset.JdbcRowSetImpl&quot;...}<\/code><\/p>\n<h3>\u9664\u4e86RCE\u8fd8\u80fd\u6709\u4ec0\u4e48\u5229\u7528<\/h3>\n<p>\u4fe1\u606f\u6cc4\u9732\u6216\u8005ReDoS\uff0c\u53c2\u8003\u4e0b\u65b9Payload<\/p>\n<pre><code class=\"language-json\">{\n    &quot;regex&quot;:{\n        &quot;$ref&quot;:&quot;$[\\blue = \/\\^[a###zA###Z]+(([a###zA###Z ])?[a###zA###Z]*)*$\/]&quot;\n    },\n    &quot;blue&quot;:&quot;aaaaaaaaaaaaaaaaaaaaaaaaaaaa!&quot;\n}<\/code><\/pre>\n<p>\u8fd8\u53ef\u4ee5\u5b9e\u73b0\u5199\u6587\u4ef6\uff0c\u4f8b\u5982\u4ee5\u4e0b\u8fd9\u4e2a\u9488\u5bf91.2.68\u5199\u6587\u4ef6\u7684Payload<\/p>\n<pre><code class=\"language-json\">{\n  &quot;@type&quot;: &quot;java.lang.AutoCloseable&quot;,\n  &quot;@type&quot;: &quot;java.io.FileOutputStream&quot;,\n  &quot;file&quot;: &quot;\/tmp\/nonexist&quot;,\n  &quot;append&quot;: &quot;false&quot;\n}<\/code><\/pre>\n<h3>\u81ea\u52a8\u6316\u6398Fastjson\u5229\u7528\u94fe\u7684\u65b9\u5f0f<\/h3>\n<p>\u5229\u7528\u94fe\u4e3b\u8981\u96c6\u4e2d\u5728<code>getter<\/code>\u548c<code>setter<\/code>\u65b9\u6cd5\u4e2d\uff0c\u5982\u679c<code>getter<\/code>\u6216\u8005<code>setter<\/code>\u7684\u65b9\u6cd5\u4e2d\u5b58\u5728\u4e00\u4e9b\u5371\u9669\u64cd\u4f5c\u6bd4\u5982<code>JNDI<\/code>\u67e5\u8be2\uff0c\u5982\u679c\u53c2\u6570\u53ef\u63a7\u5c31\u53ef\u4ee5\u5bfc\u81f4<code>JNDI<\/code>\u6ce8\u5165<\/p>\n<p>\u7b80\u5355\u6765\u8bf4\uff0c\u76f4\u63a5\u641c\u5bf9\u5e94\u9879\u76ee\u4e2d<code>JNDI<\/code>\u7684<code>lookup<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u57fa\u4e8e<code>ASM<\/code>\u89e3\u538b\u5206\u6790<code>Jar<\/code>\u5305\uff0c\u8fd9\u79cd\u534a\u81ea\u52a8\u7ed3\u5408\u4eba\u5de5\u5ba1\u6838\u7684\u65b9\u5f0f\u5176\u5b9e\u5f88\u597d\u7528\uff08\u4e4b\u524d\u6316\u5230\u8fc7\u51e0\u4e2a\uff09<\/p>\n<p>\u8fdb\u4e00\u6b65\u6765\u8bf4\uff0c\u5168\u81ea\u52a8\u7684\u65b9\u5f0f\u53ef\u4ee5\u4f7f\u7528<code>codeql<\/code>\u6216<code>gadget###inspector<\/code>\u5de5\u5177\u6765\u505a\uff0c\u4e3b\u8981\u662f\u52a0\u5165\u4e86\u6c61\u70b9\u4f20\u9012\uff0c\u5206\u6790<code>getter\/setter<\/code>\u53c2\u6570\u5982\u4f55\u4f20\u9012\u5230<code>lookup<\/code><\/p>\n<p>\u5173\u95ed\u5168\u81ea\u52a8\u5206\u6790\u539f\u7406\uff0c\u4e00\u822c\u9762\u8bd5\u5b98\u4e0d\u4f1a\u95ee\u592a\u6df1\u5165\uff0c\u56e0\u4e3a\u53ef\u80fd\u6d89\u53ca\u5230\u9759\u6001\u5206\u6790\u76f8\u5173\u7684\u6280\u672f\uff0c\u666e\u901a\u5b89\u670d\u5d3d\u7684\u9762\u8bd5\u4e0d\u4f1a\u592a\u8fc7\u6df1\u5165\uff0c\u5982\u679c\u662f\u5b9e\u9a8c\u5ba4\u53ef\u80fd\u9700\u8981\u518d\u5b66\u4e60\u4e00\u4e0b<\/p>\n","protected":false},"excerpt":{"rendered":"fastjson\u53cd\u5e8f\u5217\u5316\u539f\u7406 \u5728\u8bf7\u6c42\u5305\u91cc\u9762\u4e2d\u53d1\u9001\u6076\u610f\u7684json\u683c\u5f0fpayload\uff0c\u6f0f\u6d1e\u5728\u5904\u7406json\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u6ca1\u6709\u5bf9@type\u5b57\u6bb5\u8fdb\u884c\u8fc7\u6ee4\uff0c\u4ece\u800c\u5bfc\u81f4\u653b\u51fb\u8005\u53ef\u4ee5\u4f20\u5165\u6076\u610f\u7684TemplatesImpl\u7c7b\uff0c\u800c\u8fd9\u4e2a\u7c7b\u6709\u4e00\u4e2a\u5b57\u6bb5\u5c31\u662f_bytecode&#8230;<a rel=\"nofollow\" class=\"more-link\" href=\"https:\/\/www.hm-zy.cn\/?p=96\">Read more \u00bb<\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-96","post","type-post","status-publish","format-standard","hentry","category-12"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=96"}],"version-history":[{"count":2,"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=\/wp\/v2\/posts\/96\/revisions"}],"predecessor-version":[{"id":105,"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=\/wp\/v2\/posts\/96\/revisions\/105"}],"wp:attachment":[{"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hm-zy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}