{"id":467,"date":"2010-06-25T09:16:12","date_gmt":"2010-06-25T09:16:12","guid":{"rendered":""},"modified":"2010-06-25T09:16:12","modified_gmt":"2010-06-25T09:16:12","slug":"467","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=467","title":{"rendered":"PHP\u5b89\u5168\u9632\u62a4\u8981\u70b9\u5206\u6790"},"content":{"rendered":"<p>\u5173\u4e8e Web \u5e94\u7528\u7a0b\u5e8f\u5b89\u5168\u6027\uff0c\u5fc5\u987b\u8ba4\u8bc6\u5230\u7684\u7b2c\u4e00\u4ef6\u4e8b\u662f\u4e0d\u5e94\u8be5\u4fe1\u4efb\u5916\u90e8\u6570\u636e\u3002\u5916\u90e8\u6570\u636e\uff08outside data\uff09 \u5305\u62ec\u4e0d\u662f\u7531\u7a0b\u5e8f\u5458\u5728 PHP \u4ee3\u7801\u4e2d\u76f4\u63a5\u8f93\u5165\u7684\u4efb\u4f55\u6570\u636e\u3002\u5728\u91c7\u53d6\u63aa\u65bd\u786e\u4fdd\u5b89\u5168\u4e4b\u524d\uff0c\u6765\u81ea\u4efb\u4f55\u5176\u4ed6\u6765\u6e90\uff08\u6bd4\u5982 GET \u53d8\u91cf\u3001\u8868\u5355 POST\u3001\u6570\u636e\u5e93\u3001\u914d\u7f6e\u6587\u4ef6\u3001\u4f1a\u8bdd\u53d8\u91cf\u6216 cookie\uff09\u7684\u4efb\u4f55\u6570\u636e\u90fd\u662f\u4e0d\u53ef\u4fe1\u4efb\u7684\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u6570\u636e\u5143\u7d20\u53ef\u4ee5\u88ab\u8ba4\u4e3a\u662f\u5b89\u5168\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u662f\u5728 PHP \u4e2d\u8bbe\u7f6e\u7684\u3002<\/p>\n<p>PHP\u5b89\u5168\u9632\u62a4\u6e05\u5355 <br \/><strong>1. \u5b89\u5168\u65e0\u6687\u7684\u4ee3\u7801<\/strong><\/p>\n<p><code><br \/>&lt; ?php&nbsp;&nbsp;<br \/>$myUsername = \u2018tmyer\u2019;&nbsp;&nbsp;<br \/>$arrayarrayUsers = array(\u2019tmyer\u2019, \u2018tom\u2019, \u2018tommy\u2019);&nbsp;&nbsp;<br \/>define(\u201dGREETING\u201d, \u2018hello there\u2019 . $myUsername);&nbsp;&nbsp;<br \/>?&gt; <br \/><\/code><\/p>\n<p>\u4f46\u662f\uff0c\u4e0b\u9762\u7684\u6570\u636e\u5143\u7d20\u90fd\u662f\u6709\u7455\u75b5\u7684\u3002<\/p>\n<p>PHP\u5b89\u5168\u9632\u62a4\u6e05\u5355 <br \/><strong>2. \u4e0d\u5b89\u5168\u3001\u6709\u7455\u75b5\u7684\u4ee3\u7801<\/strong><br \/><code><br \/>&lt; ?php&nbsp;&nbsp;<br \/>$myUsername = $_POST[\u2019username\u2019]; \/\/tainted!&nbsp;&nbsp;<br \/>$arrayarrayUsers = array($myUsername, \u2018tom\u2019, \u2018tommy\u2019); \/\/tainted!&nbsp;&nbsp;<br \/>define(\u201dGREETING\u201d, \u2018hello there\u2019 . $myUsername); \/\/tainted!&nbsp;&nbsp;<br \/>?&gt; <br \/><\/code><\/p>\n<p>\u4e3a \u4ec0\u4e48\u7b2c\u4e00\u4e2a\u53d8\u91cf $myUsername \u662f\u6709\u7455\u75b5\u7684\uff1f\u56e0\u4e3a\u5b83\u76f4\u63a5\u6765\u81ea\u8868\u5355 POST\u3002\u7528\u6237\u53ef\u4ee5\u5728\u8fd9\u4e2a\u8f93\u5165\u57df\u4e2d\u8f93\u5165\u4efb\u4f55\u5b57\u7b26\u4e32\uff0c\u5305\u62ec\u7528\u6765\u6e05\u9664\u6587\u4ef6\u6216\u8fd0\u884c\u4ee5\u524d\u4e0a\u4f20\u7684\u6587\u4ef6\u7684\u6076\u610f\u547d\u4ee4\u3002<\/p>\n<p>\u60a8\u53ef\u80fd\u4f1a\u95ee\uff0c\u201c\u96be\u9053\u4e0d\u80fd\u4f7f\u7528\u53ea\u63a5\u53d7\u5b57\u6bcd A-Z \u7684\u5ba2\u6237\u7aef\uff08Javascr\u012bpt\uff09\u8868\u5355\u68c0\u9a8c\u811a\u672c\u6765\u907f\u514d\u8fd9\u79cd\u5371\u9669\u5417\uff1f\u201d\u662f\u7684\uff0c\u8fd9\u603b\u662f\u4e00\u4e2a\u6709\u597d\u5904\u7684\u6b65\u9aa4\uff0c\u4f46\u662f\u6b63\u5982\u5728\u540e\u9762\u4f1a\u770b\u5230\u7684\uff0c\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u5c06\u4efb\u4f55\u8868\u5355\u4e0b\u8f7d \u5230\u81ea\u5df1\u7684\u673a\u5668\u4e0a\uff0c\u4fee\u6539\u5b83\uff0c\u7136\u540e\u91cd\u65b0\u63d0\u4ea4\u4ed6\u4eec\u9700\u8981\u7684\u4efb\u4f55\u5185\u5bb9\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6848\u5f88\u7b80\u5355\uff1a\u5fc5\u987b\u5bf9 $_POST[\u2019username\u2019] \u8fd0\u884c\u6e05\u7406\u4ee3\u7801\u3002\u5982\u679c\u4e0d\u8fd9\u4e48\u505a\uff0c\u90a3\u4e48\u5728\u4f7f\u7528 $myUsername \u7684\u4efb\u4f55\u5176\u4ed6\u65f6\u5019\uff08\u6bd4\u5982\u5728\u6570\u7ec4\u6216\u5e38\u91cf\u4e2d\uff09\uff0c\u5c31\u53ef\u80fd\u6c61\u67d3\u8fd9\u4e9b\u5bf9\u8c61\u3002<\/p>\n<p>\u5bf9\u7528\u6237\u8f93\u5165\u8fdb\u884c\u6e05\u7406\u7684\u4e00\u4e2a\u7b80\u5355\u65b9\u6cd5\u662f\uff0c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5904\u7406\u5b83\u3002\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u53ea\u5e0c\u671b\u63a5\u53d7\u5b57\u6bcd\u3002\u5c06\u5b57\u7b26\u4e32\u9650\u5236\u4e3a\u7279\u5b9a\u6570\u91cf\u7684\u5b57\u7b26\uff0c\u6216\u8005\u8981\u6c42\u6240\u6709\u5b57\u6bcd\u90fd\u662f\u5c0f\u5199\u7684\uff0c\u8fd9\u53ef\u80fd\u4e5f\u662f\u4e2a\u597d\u4e3b\u610f\u3002<\/p>\n<p>PHP\u5b89\u5168\u9632\u62a4\u6e05\u5355 <br \/><strong>3. \u4f7f\u7528\u6237\u8f93\u5165\u53d8\u5f97\u5b89\u5168<\/strong><br \/><code><br \/>&lt; ?php&nbsp;&nbsp;<br \/>$myUsername = cleanInput($_POST[\u2019username\u2019]); \/\/clean!&nbsp;&nbsp;<br \/>$arrayarrayUsers = array($myUsername, \u2018tom\u2019, \u2018tommy\u2019); \/\/clean!&nbsp;&nbsp;<br \/>define(\u201dGREETING\u201d, \u2018hello there\u2019 . $myUsername); \/\/clean!&nbsp;&nbsp;<\/p>\n<p>function cleanInput($input){&nbsp;&nbsp;<br \/>$clean = strtolower($input);&nbsp;&nbsp;<br \/>$clean = preg_replace(\u201d\/[^a-z]\/\u201d, \u201c\u201d, $clean);&nbsp;&nbsp;<br \/>$clean = substr($clean,0,12);&nbsp;&nbsp;<br \/>return $clean;&nbsp;&nbsp;<br \/>}&nbsp;&nbsp;<br \/>?&gt; <br \/><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e Web \u5e94\u7528\u7a0b\u5e8f\u5b89\u5168\u6027\uff0c\u5fc5\u987b\u8ba4\u8bc6\u5230\u7684\u7b2c\u4e00\u4ef6\u4e8b\u662f\u4e0d\u5e94\u8be5\u4fe1\u4efb\u5916\u90e8\u6570&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-Php"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=467"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}