SQLite \u6ce8\u5165<\/strong><\/div>\n\u5982\u679c\u60a8\u7684\u7ad9\u70b9\u5141\u8bb8\u7528\u6237\u901a\u8fc7\u7f51\u9875\u8f93\u5165\uff0c\u5e76\u5c06\u8f93\u5165\u5185\u5bb9\u63d2\u5165\u5230 SQLite \u6570\u636e\u5e93\u4e2d\uff0c\u8fd9\u4e2a\u65f6\u5019\u60a8\u5c31\u9762\u4e34\u7740\u4e00\u4e2a\u88ab\u79f0\u4e3a SQL \u6ce8\u5165\u7684\u5b89\u5168\u95ee\u9898\u3002\u672c\u7ae0\u8282\u5c06\u5411\u60a8\u8bb2\u89e3\u5982\u4f55\u9632\u6b62\u8fd9\u79cd\u60c5\u51b5\u7684\u53d1\u751f\uff0c\u786e\u4fdd\u811a\u672c\u548c SQLite \u8bed\u53e5\u7684\u5b89\u5168\u3002<\/p>\n
\u6ce8\u5165\u901a\u5e38\u5728\u8bf7\u6c42\u7528\u6237\u8f93\u5165\u65f6\u53d1\u751f\uff0c\u6bd4\u5982\u9700\u8981\u7528\u6237\u8f93\u5165\u59d3\u540d\uff0c\u4f46\u7528\u6237\u5374\u8f93\u5165\u4e86\u4e00\u4e2a SQLite \u8bed\u53e5\uff0c\u800c\u8fd9\u8bed\u53e5\u5c31\u4f1a\u5728\u4e0d\u77e5\u4e0d\u89c9\u4e2d\u5728\u6570\u636e\u5e93\u4e0a\u8fd0\u884c\u3002<\/p>\n
\u6c38\u8fdc\u4e0d\u8981\u76f8\u4fe1\u7528\u6237\u63d0\u4f9b\u7684\u6570\u636e\uff0c\u6240\u4ee5\u53ea\u5904\u7406\u901a\u8fc7\u9a8c\u8bc1\u7684\u6570\u636e\uff0c\u8fd9\u9879\u89c4\u5219\u662f\u901a\u8fc7\u6a21\u5f0f\u5339\u914d\u6765\u5b8c\u6210\u7684\u3002\u5728\u4e0b\u9762\u7684\u5b9e\u4f8b\u4e2d\uff0c\u7528\u6237\u540d username \u88ab\u9650\u5236\u4e3a\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\u6216\u8005\u4e0b\u5212\u7ebf\uff0c\u957f\u5ea6\u5fc5\u987b\u5728 8 \u5230 20 \u4e2a\u5b57\u7b26\u4e4b\u95f4 - \u8bf7\u6839\u636e\u9700\u8981\u4fee\u6539\u8fd9\u4e9b\u89c4\u5219\u3002<\/p>\n
\r\nif (preg_match(\"\/^\\w{8,20}$\/\", $_GET['username'], $matches)){\r\n $db = new SQLiteDatabase('filename');\r\n $result = @$db->query(\"SELECT * FROM users WHERE username=$matches[0]\");\r\n}else{\r\n echo \"username not accepted\";\r\n}<\/pre>\n\u4e3a\u4e86\u6f14\u793a\u8fd9\u4e2a\u95ee\u9898\uff0c\u5047\u8bbe\u8003\u8651\u6b64\u6458\u5f55\uff1aTo demonstrate the problem, consider this excerpt:<\/p>\n
\r\n$name = \"Qadir'; DELETE FROM users;\";\r\n@$db->query(\"SELECT * FROM users WHERE username='{$name}'\");<\/pre>\n\u51fd\u6570\u8c03\u7528\u662f\u4e3a\u4e86\u4ece\u7528\u6237\u8868\u4e2d\u68c0\u7d22 name \u5217\u4e0e\u7528\u6237\u6307\u5b9a\u7684\u540d\u79f0\u76f8\u5339\u914d\u7684\u8bb0\u5f55\u3002\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c$name \u53ea\u5305\u542b\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\u6216\u8005\u7a7a\u683c\uff0c\u6bd4\u5982\u5b57\u7b26\u4e32 ilia\u3002\u4f46\u5728\u8fd9\u91cc\uff0c\u5411 $name \u8ffd\u52a0\u4e86\u4e00\u4e2a\u5168\u65b0\u7684\u67e5\u8be2\uff0c\u8fd9\u4e2a\u5bf9\u6570\u636e\u5e93\u7684\u8c03\u7528\u5c06\u4f1a\u9020\u6210\u707e\u96be\u6027\u7684\u95ee\u9898\uff1a\u6ce8\u5165\u7684 DELETE \u67e5\u8be2\u4f1a\u5220\u9664 users \u7684\u6240\u6709\u8bb0\u5f55\u3002<\/p>\n
\u867d\u7136\u5df2\u7ecf\u5b58\u5728\u6709\u4e0d\u5141\u8bb8\u67e5\u8be2\u5806\u53e0\u6216\u5728\u5355\u4e2a\u51fd\u6570\u8c03\u7528\u4e2d\u6267\u884c\u591a\u4e2a\u67e5\u8be2\u7684\u6570\u636e\u5e93\u63a5\u53e3\uff0c\u5982\u679c\u5c1d\u8bd5\u5806\u53e0\u67e5\u8be2\uff0c\u5219\u4f1a\u8c03\u7528\u5931\u8d25\uff0c\u4f46 SQLite \u548c PostgreSQL \u91cc\u4ecd\u8fdb\u884c\u5806\u53e0\u67e5\u8be2\uff0c\u5373\u6267\u884c\u5728\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u63d0\u4f9b\u7684\u6240\u6709\u67e5\u8be2\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u4e25\u91cd\u7684\u5b89\u5168\u95ee\u9898\u3002<\/p>\n
\u9632\u6b62 SQL \u6ce8\u5165<\/strong><\/div>\n\u5728\u811a\u672c\u8bed\u8a00\u4e2d\uff0c\u6bd4\u5982 PERL \u548c PHP\uff0c\u60a8\u53ef\u4ee5\u5de7\u5999\u5730\u5904\u7406\u6240\u6709\u7684\u8f6c\u4e49\u5b57\u7b26\u3002\u7f16\u7a0b\u8bed\u8a00 PHP \u63d0\u4f9b\u4e86\u5b57\u7b26\u4e32\u51fd\u6570 SQLite3::escapeString($string) \u548c sqlite_escape_string() \u6765\u8f6c\u4e49\u5bf9\u4e8e SQLite \u6765\u8bf4\u6bd4\u8f83\u7279\u6b8a\u7684\u8f93\u5165\u5b57\u7b26\u3002<\/p>\n
\u6ce8\u610f\uff1a\u4f7f\u7528\u51fd\u6570 sqlite_escape_string() \u7684 PHP \u7248\u672c\u8981\u6c42\u4e3a PHP 5 < 5.4.0\u3002\n\n\u66f4\u9ad8\u7248\u672c PHP 5 >= 5.3.0, PHP 7 \u4f7f\u7528\u4ee5\u4e0a\u51fd\u6570:<\/p>\n
\r\nSQLite3::escapeString($string);\/\/$string\u4e3a\u8981\u8f6c\u4e49\u7684\u5b57\u7b26\u4e32<\/pre>\n\u4ee5\u4e0b\u65b9\u5f0f\u5728\u6700\u65b0\u7248\u672c\u7684 PHP \u4e2d\u4e0d\u652f\u6301\uff1a<\/p>\n
\r\nif (get_magic_quotes_gpc()) \r\n{\r\n $name = sqlite_escape_string($name);\r\n}\r\n$result = @$db->query(\"SELECT * FROM users WHERE username='{$name}'\");<\/pre>\n\u867d\u7136\u7f16\u7801\u4f7f\u5f97\u63d2\u5165\u6570\u636e\u53d8\u5f97\u5b89\u5168\uff0c\u4f46\u662f\u5b83\u4f1a\u5448\u73b0\u7b80\u5355\u7684\u6587\u672c\u6bd4\u8f83\uff0c\u5728\u67e5\u8be2\u4e2d\uff0c\u5bf9\u4e8e\u5305\u542b\u4e8c\u8fdb\u5236\u6570\u636e\u7684\u5217\uff0cLIKE \u5b50\u53e5\u662f\u4e0d\u53ef\u7528\u7684\u3002<\/p>\n
\u8bf7\u6ce8\u610f\uff0caddslashes() \u4e0d\u5e94\u8be5\u88ab\u7528\u5728 SQLite \u67e5\u8be2\u4e2d\u5f15\u7528\u5b57\u7b26\u4e32\uff0c\u5b83\u4f1a\u5728\u68c0\u7d22\u6570\u636e\u65f6\u5bfc\u81f4\u5947\u602a\u7684\u7ed3\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5982\u679c\u60a8\u7684\u7ad9\u70b9\u5141\u8bb8\u7528\u6237\u901a\u8fc7\u7f51\u9875\u8f93\u5165\uff0c\u5e76\u5c06\u8f93\u5165\u5185\u5bb9\u63d2\u5165\u5230 SQLite \u6570\u636e\u5e93\u4e2d\uff0c\u8fd9\u4e2a\u65f6\u5019\u60a8\u5c31\u9762\u4e34\u7740\u4e00\u4e2a\u88ab\u79f0\u4e3a S […]<\/p>\n","protected":false},"author":1481,"featured_media":201702,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-201708","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=201708"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201708\/revisions"}],"predecessor-version":[{"id":201715,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201708\/revisions\/201715"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/201702"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=201708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=201708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=201708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}