{"id":202460,"date":"2025-05-13T14:26:38","date_gmt":"2025-05-13T06:26:38","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202460\/"},"modified":"2025-05-13T14:26:38","modified_gmt":"2025-05-13T06:26:38","slug":"php%e5%87%bd%e6%95%b0%e5%ae%89%e5%85%a8%e9%97%ae%e9%a2%98%e7%9a%84%e7%8e%b0%e7%8a%b6%e4%b8%8e%e6%9c%aa%e6%9d%a5%e6%8c%91%e6%88%98","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202460\/","title":{"rendered":"php\u51fd\u6570\u5b89\u5168\u95ee\u9898\u7684\u73b0\u72b6\u4e0e\u672a\u6765\u6311\u6218"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u51fd\u6570\u5b89\u5168\u95ee\u9898\u7684\u73b0\u72b6\u4e0e\u672a\u6765\u6311\u6218<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aphp\u51fd\u6570\u5b89\u5168\u95ee\u9898\u7684\u73b0\u72b6\u4e0e\u672a\u6765\u6311\u6218\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p>PHP \u51fd\u6570\u5b89\u5168\u95ee\u9898\u5305\u62ec SQL \u6ce8\u5165\u3001XSS \u548c RCE\uff0c\u968f\u7740\u4e91\u8ba1\u7b97\u548c API \u7684\u666e\u53ca\uff0c\u65b0\u7684\u6311\u6218\u4e0d\u65ad\u6d8c\u73b0\u3002\u5e94\u5bf9\u63aa\u65bd\u5305\u62ec\u8f93\u5165\u9a8c\u8bc1\u3001\u53c2\u6570\u5316\u67e5\u8be2\u3001\u9650\u5236\u51fd\u6570\u8bbf\u95ee\uff0c\u4ee5\u53ca\u6301\u7eed\u76d1\u63a7\u548c\u66f4\u65b0\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729835673671b3299bafb3.jpg\" class=\"aligncenter\"><\/p>\n<h2>PHP \u51fd\u6570\u5b89\u5168\u95ee\u9898\u7684\u73b0\u72b6\u4e0e\u672a\u6765\u6311\u6218<\/h2>\n<p><strong>\u73b0\u72b6<\/strong><\/p>\n<p>PHP \u662f\u4f7f\u7528\u5e7f\u6cdb\u7684 Web \u5f00\u53d1\u8bed\u8a00\uff0c\u4f46\u5176\u51fd\u6570\u5b89\u5168\u95ee\u9898\u4e00\u76f4\u5907\u53d7\u5173\u6ce8\u3002\u5e38\u89c1\u7684\u5b89\u5168\u95ee\u9898\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>SQL \u6ce8\u5165\uff1a<\/strong> \u6076\u610f\u7528\u6237\u5728\u51fd\u6570\u8f93\u5165\u4e2d\u6ce8\u5165 SQL \u67e5\u8be2\uff0c\u5bfc\u81f4\u672a\u7ecf\u6388\u6743\u7684\u6570\u636e\u8bbf\u95ee\u6216\u4fee\u6539\u3002<\/li>\n<li><strong>\u8de8\u7ad9\u811a\u672c (XSS)\uff1a<\/strong> \u653b\u51fb\u8005\u5728\u8f93\u5165\u4e2d\u6ce8\u5165\u6076\u610f\u811a\u672c\uff0c\u5728\u7528\u6237\u7684\u6d4f\u89c8\u5668\u4e2d\u6267\u884c\u672a\u7ecf\u6388\u6743\u7684\u4ee3\u7801\u3002<\/li>\n<li><strong>\u8fdc\u7a0b\u4ee3\u7801\u6267\u884c (RCE)\uff1a<\/strong> \u653b\u51fb\u8005\u5229\u7528\u51fd\u6570\u6f0f\u6d1e\u6267\u884c\u4efb\u610f\u4ee3\u7801\uff0c\u83b7\u5f97\u5bf9\u670d\u52a1\u5668\u7684\u63a7\u5236\u6743\u3002<\/li>\n<\/ul>\n<p><strong>\u672a\u6765\u6311\u6218<\/strong><\/p>\n<p>\u968f\u7740 PHP \u751f\u6001\u7cfb\u7edf\u7684\u4e0d\u65ad\u53d1\u5c55\uff0c\u51fa\u73b0\u4e86\u65b0\u7684\u5b89\u5168\u6311\u6218\uff1a<\/p>\n<ul>\n<li><strong>\u4e91\u8ba1\u7b97\u548c\u5bb9\u5668\uff1a<\/strong> \u51fd\u6570\u5b89\u5168\u95ee\u9898\u5728\u4e91\u8ba1\u7b97\u548c\u5bb9\u5668\u5316\u73af\u5883\u4e2d\u53d8\u5f97\u66f4\u52a0\u590d\u6742\uff0c\u9700\u8981\u989d\u5916\u7684\u5b89\u5168\u63aa\u65bd\u3002<\/li>\n<li><strong>\u4ee3\u7801\u91cd\u7528\uff1a<\/strong> \u4ece\u5916\u90e8\u6765\u6e90\uff08\u5982\u7b2c\u4e09\u65b9\u5e93\uff09\u5bfc\u5165\u7684\u4ee3\u7801\u53ef\u80fd\u5305\u542b\u5b89\u5168\u6f0f\u6d1e\uff0c\u9700\u8981\u4e25\u683c\u7684\u7b5b\u9009\u548c\u9a8c\u8bc1\u3002<\/li>\n<li><strong>API \u5b89\u5168\u6027\uff1a<\/strong> \u968f\u7740 API \u7684\u5e7f\u6cdb\u4f7f\u7528\uff0c\u51fd\u6570\u5b89\u5168\u95ee\u9898\u53ef\u80fd\u4f1a\u8f6c\u79fb\u5230 API \u7ea7\u522b\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1aSQL \u6ce8\u5165<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b PHP \u51fd\u6570\uff1a<\/p>\n<pre>function get_user($username) {\n  $sql = \"SELECT * FROM users WHERE username='$username'\";\n  $result = mysqli_query($conn, $sql);\n  if (mysqli_num_rows($result) &gt; 0) {\n    $user = mysqli_fetch_assoc($result);\n    return $user;\n  } else {\n    return null;\n  }\n}<\/pre>\n<p>\u8fd9\u4e2a\u51fd\u6570\u4ece\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u7528\u6237\u6570\u636e\u3002\u5982\u679c <code>$username<\/code> \u8f93\u5165\u4e0d\u53d7\u4fe1\u4efb\uff0c\u653b\u51fb\u8005\u53ef\u4ee5\u6ce8\u5165\u6076\u610f SQL \u67e5\u8be2\uff0c\u5982\uff1a<\/p>\n<pre>$username = \"' OR true --\";\nget_user($username); \/\/ \u5c06\u8fd4\u56de\u6240\u6709\u7528\u6237\u6570\u636e<\/pre>\n<p><strong>\u5e94\u5bf9\u63aa\u65bd<\/strong><\/p>\n<p>\u4e3a\u4e86\u5e94\u5bf9\u8fd9\u4e9b\u5b89\u5168\u6311\u6218\uff0c\u6709\u4ee5\u4e0b\u63aa\u65bd\uff1a<\/p>\n<ul>\n<li><strong>\u8f93\u5165\u9a8c\u8bc1\u548c\u6e05\u7406\uff1a<\/strong> \u4f7f\u7528\u8fc7\u6ee4\u5668\u548c\u9a8c\u8bc1\u51fd\u6570\u9a8c\u8bc1\u6240\u6709\u7528\u6237\u8f93\u5165\uff0c\u6e05\u9664\u6f5c\u5728\u7684\u6076\u610f\u5b57\u7b26\u3002<\/li>\n<li><strong>\u4f7f\u7528\u53c2\u6570\u5316\u67e5\u8be2\uff1a<\/strong> \u4f7f\u7528\u53c2\u6570\u5316\u67e5\u8be2\uff08\u5982 PHP \u7684 PDO\uff09\u6765\u9632\u6b62 SQL \u6ce8\u5165\u3002<\/li>\n<li><strong>\u9650\u5236\u51fd\u6570\u8bbf\u95ee\uff1a<\/strong> \u53ea\u5141\u8bb8\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u7684\u7528\u6237\u8bbf\u95ee\u654f\u611f\u51fd\u6570\u3002<\/li>\n<li><strong>\u6301\u7eed\u5b89\u5168\u76d1\u63a7\u548c\u66f4\u65b0\uff1a<\/strong> \u5b9a\u671f\u76d1\u63a7\u7cfb\u7edf\u662f\u5426\u5b58\u5728\u5b89\u5168\u95ee\u9898\u5e76\u5e94\u7528\u5b89\u5168\u66f4\u65b0\u3002<\/li>\n<\/ul>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aphp\u51fd\u6570\u5b89\u5168\u95ee\u9898\u7684\u73b0\u72b6\u4e0e\u672a\u6765\u6311\u6218\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8ephp,\u5b89\u5168\u95ee\u9898\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u51fd\u6570\u5b89\u5168\u95ee\u9898\u7684\u73b0\u72b6\u4e0e\u672a\u6765\u6311&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202460","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202460"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202460\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}