{"id":1260,"date":"2016-06-04T11:38:55","date_gmt":"2016-06-04T03:38:55","guid":{"rendered":"http:\/\/ufqi.com\/blog\/?p=1260"},"modified":"2016-06-04T18:38:00","modified_gmt":"2016-06-04T10:38:00","slug":"gwa2_imprv_cmdline_no_sql_check","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/gwa2_imprv_cmdline_no_sql_check\/","title":{"rendered":"-GWA2\u65b0\u589e\u547d\u4ee4\u884c\u8fd0\u884c\u53caNO_SQL_CHECK\u652f\u6301"},"content":{"rendered":"<p>\u4f7f\u7528\u4e2d\u7684\u6846\u67b6\u624d\u4f1a\u88ab\u8fdb\u5316\u3002<\/p>\n<p>-GWA2 \u5728\u5b9e\u9645\u90e8\u7f72\u548c\u5e94\u7528\u4e2d\u9047\u5230\u65b0\u9700\u6c42\uff0c\u4e8e\u662f\u5c31\u589e\u52a0\u65b0\u529f\u80fd\uff0c\u5982\u4e0b\u4e24\u4e2a\uff1a1\uff09\u65b0\u589e\u547d\u4ee4\u884c\u8fd0\u884c\u6a21\u5f0f\u652f\u6301\uff1b2\uff09\u65b0\u589e\u5bf9NO_SQL_CHECK\u7684\u652f\u6301\uff0c\u5206\u8ff0\u5982\u4e0b\uff0c\u5907\u5fd8\u3002<\/p>\n<p>1. GWA2 \u65b0\u589e\u5bf9\u547d\u4ee4\u884c\u8fd0\u884c\u6a21\u5f0f\u7684\u652f\u6301<br \/>\n\u5982\u679c\u4f7f\u7528-GWA2\u7684PHP\u5b9e\u73b0\uff0c\u53ef\u4ee5\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5728PHP\u7684\u547d\u4ee4\u884c\uff08command line\uff09\u6a21\u5f0f\u4e0b\u6267\u884c\u67d0\u4e9b\u4efb\u52a1\u7a0b\u5e8f\uff0c\u5982\u4e0b\u662f\u9700\u6c42\u573a\u666f\u3002<br \/>\n\u6709 \/?mod=abc&amp;act=read \u7684\u7a0b\u5e8f\uff0cWeb\u8bbf\u95ee\u662f<br \/>\nhttp:\/\/domain\/path\/?mod=abc&#038;act=read<\/p>\n<p>\u8fd9\u6837\u53ef\u4ee5\u83b7\u5f97\u7a0b\u5e8f\u7684\u6267\u884c\uff0c\u53d6\u5f97\u9884\u671f\u7684\u7ed3\u679c\u8fd4\u56de\u3002\u8fd9\u4e00\u60c5\u51b5\u662f\u8fdc\u7a0b\u7684\uff0c\u9700\u8981Web Server\u63a5\u8f6c\uff0c\u7136\u540e\u4ea4\u7ed9 Mod_PHP\u6216\u8005FastCGI\u7ed9PHP\u89e3\u91ca\u5668\u53bb\u6267\u884c\uff0c\u7136\u540e\u518d\u5c06\u7ed3\u679c\u8fd4\u56de\u7ed9Web Server\uff0cWeb Server\u8fdb\u4e00\u6b65\u5730\u8fd4\u56de\u7ed9\u7528\u6237\u3002\u8fd9\u663e\u7136\u6709\u70b9\u7ed5\uff0c\u5982\u679cPHP\u5904\u7406\u7684\u4e1a\u52a1\u903b\u8f91\u662f\u5728\u540e\u53f0\u7684\u67d0\u9879\u8ba1\u7b97\u3002\u5e94\u666f\u7684\uff0c\u5c31\u662f\u8ba9PHP\u7684\u811a\u672c\u76f4\u63a5\u5728\u540e\u53f0\u6267\u884c\uff0c\u4f8b\u5982\uff0c<br \/>\n\/usr\/local\/php\/bin\/php -c \/www\/bin\/php\/php.ini &#8220;\/path\/index.php&#8221; &#8220;?mod=abc&amp;act=read&amp;fmt=json&#8221;<\/p>\n<p>\u5c31\u53ef\u80fd\u76f4\u63a5\u548c\u5feb\u5f88\u591a\uff0c\u800c\u4e14\u6709\u4e9b\u65f6\u5019\uff0cWeb Server\u548c\uff08\u6216\uff09Mod_PHP\u6216FastCGI\u90fd\u6709\u6267\u884c\u65f6\u957f\u7684\u9650\u5236\uff0c\u8fd9\u5bf9\u67d0\u4e9b\u9700\u8981\u8017\u65f6\u7684\u7a0b\u5e8f\u4e5f\u4e0d\u5229\uff0c\u4e8e\u662f\u5c31\u60f3\u6cd5\u8bbe\u6cd5\uff0c\u8ba9\u57fa\u4e8e -GWA2 \u5199\u7684\u811a\u672c\u7a0b\u5e8f\uff0c\u65e2\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u6267\u884c\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7PHP\u811a\u672c\u6267\u884c\uff0c\u4e8b\u60c5\u5c31\u8fd9\u6837\u6210\u4e86\u3002<\/p>\n<p>\u4e3b\u8981\u6539\u52a8\u662f\u5728\u5165\u53e3\u7a0b\u5e8f\uff0c\u5bf9\u4e8ePHP \u547d\u4ee4\u884c\u7684\u8c03\u7528\uff0c\u6784\u5efa\u4e00\u4e9b\u57fa\u672c\u7684$_SERVER\u53d8\u91cf\u51fa\u6765\u3002\u5982\u6b64\u4ee5\u6765\uff0c\u4e00\u6bb5\u811a\u672c\u7a0b\u5e8f\uff0c\u65e2\u53ef\u4ee5\u5728web\u4e0a\u88ab\u8bbf\u95ee\uff0c\u4e5f\u80fd\u591f\u5728\u672c\u5730\u901a\u8fc7\u547d\u4ee4\u884c\u6765\u6267\u884c\uff0c\u4e5f\u5373,<br \/>\nhttp:\/\/domain\/path-to-webapp\/index.php?mod=abc&#038;act=efg<br \/>\nshell&gt; php &#8220;\/path-to-webapp\/index.php&#8221; &#8220;?mod=acd&amp;act=efg&#8221;<\/p>\n<p>2) \u5bf9NO_SQL_CHECK\u7684\u652f\u6301<br \/>\n-GWA2 \u5728\u8bbe\u8ba1\u65f6\uff0c\u8003\u8651\u4e86\u5bf9SQL Injection\u7684\u89c4\u907f\uff0c\u6240\u6709\u5bf9\u6bcf\u6b21SQL\u7684\u62fc\u63a5\u548c\u6267\u884c\uff0c\u90fd\u505a\u5b89\u5168\u6027\u68c0\u6d4b\uff0c\u4f46\u6709\u65f6\u5019\uff0c\u9650\u4e8eJava\u6216\u8005PHP\u7a0b\u5e8f\u672c\u8eab\u7684\u95ee\u9898\uff0c\u5982<br \/>\n&lt;?php<\/p>\n<p>$idArr\u00a0=\u00a0&#8220;1, 2, 3, 4&#8221;;<\/p>\n<p>$db\u00a0= new\u00a0MySQLi();<br \/>\n$bad_stmt\u00a0=\u00a0$db-&gt;prepare(SELECT\u00a0`idAsLetters`\u00a0FROM\u00a0`tbl`\u00a0WHERE\u00a0`id`\u00a0IN(?));<br \/>\n$bad_stmt-&gt;bind_param(&#8220;s&#8221;,\u00a0$idArr);<br \/>\n$bad_stmt-&gt;bind_result($ias);<br \/>\n$bad_stmt-&gt;execute();<br \/>\n?&gt;<br \/>\n<a href=\"http:\/\/php.net\/manual\/en\/mysqli-stmt.bind-param.php\" target=\"_blank\">\u5c31\u4e0d\u80fd\u53c2\u6570\u9884\u671f\u7ed3\u679c\uff0c\u53d6\u800c\u4ee3\u4e4b\u7684\u662f\u4f1a\u5c06\u6574\u4e2a $idArr \u89c6\u4e3a\u4e00\u4e2a String<\/a>\uff0c\u800c\u4e0d\u662f\u4e00\u4e2alist.<br \/>\n\u53cd\u5411\u7684\uff0c\u5982\u679c\u6211\u4eec\u4e0d\u8fd9\u6837\u505a\uff0c\u800c\u662f\u5c06 id list\u76f4\u63a5\u653e\u5165SQL\u4e2d\uff0c\u4e0d\u4f7f\u7528bind_param\u8fdb\u884c\u53d8\u91cf\u7684\u4ee3\u5165\uff0c\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\u4e5f\u80fd\u591f\u901a\u8fc7\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5982\u679cwhere\u8bed\u53e5\u8fdb\u4e00\u6b65\u7684\u590d\u6742\u6210 where url in (URL_LIST)\u65f6\uff0cURL\u4e2d\u53ef\u80fd\u5305\u62ec?\uff0c\u8fd9\u4e2a\u5b57\u7b26\u5728-GWA2\u7684SQL\u68c0\u67e5\u4e2d\u4f1a\u88ab\u89c6\u4e3a\u662f\u5f85\u66ff\u6362\u53d8\u91cf\uff0c\u4f1a\u7531\u6b64\u5728\u8fd0\u884c\u65f6\u53d8\u91cf\u5bb9\u5668hmf\u4e2d\u8fdb\u884c\u67e5\u627e\u5bf9\u5e94\u7684\u53c2\u6570\uff0c\u663e\u7136\u627e\u4e0d\u5230\uff0c\u4e8e\u662f\u5c31\u4f1a\u89e6\u53d1\u9519\u8bef\u3002<\/p>\n<p>\u6709\u9274\u4e8e\u6b64\uff0c\u6211\u4eec\u5728 $_CONFIG\u4e2d\u589e\u52a0\u4e86:<br \/>\n$conf[&#8216;no_sql_check&#8217;] = &#8216;omit_sql_security_check&#8217;; # keep original form of sql in some cases, 14:24 Friday, May 20, 2016, refer: http:\/\/php.net\/manual\/en\/mysqli-stmt.bind-param.php, &#8220;2 asb(.d o,t )han(a t)n i h e i(d.o_t)dk \u00b6&#8221;<\/p>\n<p>\u5f53\u8bbf\u95ee\u65f6\uff0c\u8bbe\u7f6e\u67d0\u4e2a$obj\u4e3a\u4e34\u65f6\u4e0d\u68c0\u67e5SQL\u65f6\uff08SQL\u68c0\u67e5\u524d\u7f6e\uff09\uff0c\u8fd9\u4e0d\u5bf9SQL\u505a\u8fdb\u4e00\u6b65\u7684\u68c0\u67e5\uff0c\u4ece\u800c\u7565\u8fc7\u8fd9\u4e00\u6b65\u9aa4\uff0c\u5982<\/p>\n<p>$obj-&gt;set($_CONFIG[&#8216;no_sql_check&#8217;], true); # omit sql check<br \/>\n$sql = &#8216;select * from &#8216;.$obj-&gt;getTbl().&#8217; where url in (&#8216;.$tmpStr.&#8217;)&#8217;;<br \/>\n$result = $obj-&gt;execBy($sql, null);<br \/>\n$obj-&gt;set($_CONFIG[&#8216;no_sql_check&#8217;], false); # restore it as check<\/p>\n<p><a href=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/06\/gwa2-logo-201606.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1270\" alt=\"gwa2-logo-201606\" src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/06\/gwa2-logo-201606.png\" width=\"300\" height=\"300\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u4e2d\u7684\u6846\u67b6\u624d\u4f1a\u88ab\u8fdb\u5316\u3002 -GWA2 \u5728\u5b9e\u9645\u90e8\u7f72\u548c\u5e94\u7528\u4e2d\u9047\u5230\u65b0\u9700\u6c42\uff0c\u4e8e\u662f\u5c31\u589e\u52a0\u65b0 &hellip; <a href=\"https:\/\/ufqi.com\/blog\/gwa2_imprv_cmdline_no_sql_check\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42,2],"tags":[144,143,86,110],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1260"}],"collection":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/comments?post=1260"}],"version-history":[{"count":7,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1260\/revisions"}],"predecessor-version":[{"id":1263,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1260\/revisions\/1263"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=1260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=1260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=1260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}