{"id":60,"date":"2011-01-29T07:10:27","date_gmt":"2011-01-29T07:10:27","guid":{"rendered":"http:\/\/hgtas.com\/?p=60"},"modified":"2011-01-29T07:14:23","modified_gmt":"2011-01-29T07:14:23","slug":"php-vulnerability-nine-total-solution-file-upload-vulnerability","status":"publish","type":"post","link":"https:\/\/508.me\/?p=60","title":{"rendered":"PHP\u6f0f\u6d1e\u5168\u89e3(\u4e5d)-\u6587\u4ef6\u4e0a\u4f20\u6f0f\u6d1e"},"content":{"rendered":"<p>\u4e00\u5957web\u5e94\u7528\u7a0b\u5e8f\uff0c\u4e00\u822c\u90fd\u4f1a\u63d0\u4f9b\u6587\u4ef6\u4e0a\u4f20\u7684\u529f\u80fd\uff0c\u65b9\u4fbf\u6765\u8bbf\u8005\u4e0a\u4f20\u4e00\u4e9b\u6587\u4ef6\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6587\u4ef6\u4e0a\u4f20\u8868\u5355<\/p>\n<p>&lt;form action=&#8221;upload.php&#8221; method=&#8221;post&#8221; enctype=&#8221;multipart\/form-data&#8221; name=&#8221;form1&#8243;&gt;<br \/>\n&lt;input type=&#8221;file&#8221; name=&#8221;file1&#8243; \/&gt;&lt;br \/&gt;<br \/>\n&lt;input type=&#8221;submit&#8221; value=&#8221;\u4e0a\u4f20\u6587\u4ef6&#8221; \/&gt;<br \/>\n&lt;input type=&#8221;hidden&#8221; name=&#8221;MAX_FILE_SIZE&#8221; value=&#8221;1024&#8243; \/&gt;<br \/>\n&lt;\/form&gt;<\/p>\n<p>php\u7684\u914d\u7f6e\u6587\u4ef6php.ini\uff0c\u5176\u4e2d\u9009\u9879upload_max_filesize\u6307\u5b9a\u5141\u8bb8\u4e0a\u4f20\u7684\u6587\u4ef6\u5927\u5c0f\uff0c\u9ed8\u8ba4\u662f2M<\/p>\n<p><strong>$_FILES\u6570\u7ec4\u53d8\u91cf<\/strong><\/p>\n<p>PHP\u4f7f\u7528\u53d8\u91cf$_FILES\u6765\u4e0a\u4f20\u6587\u4ef6\uff0c$_FILES\u662f\u4e00\u4e2a\u6570\u7ec4\u3002\u5982\u679c\u4e0a\u4f20test.txt\uff0c\u90a3\u4e48$_FILES\u6570\u7ec4\u7684\u5185\u5bb9\u4e3a\uff1a<\/p>\n<p>$FILES<\/p>\n<p>Array<\/p>\n<p>{<\/p>\n<p>[file] =&gt; Array<\/p>\n<p>{<\/p>\n<p>[name] =&gt; test.txt\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u6587\u4ef6\u540d\u79f0<\/p>\n<p>[type] =&gt; text\/plain\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/MIME\u7c7b\u578b<\/p>\n<p>[tmp_name] =&gt; \/tmp\/php5D.tmp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u4e34\u65f6\u6587\u4ef6<\/p>\n<p>[error] =&gt; 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u9519\u8bef\u4fe1\u606f<\/p>\n<p>[size] =&gt; 536\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u6587\u4ef6\u5927\u5c0f\uff0c\u5355\u4f4d\u5b57\u8282<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u5982\u679c\u4e0a\u4f20\u6587\u4ef6\u6309\u94ae\u7684name\u5c5e\u6027\u503c\u4e3afile<\/p>\n<p>&lt;input type=&#8221;file&#8221; name=&#8221;file&#8221; \/&gt;<\/p>\n<p>\u90a3\u4e48\u4f7f\u7528$_FILES[&#8216;file&#8217;][&#8216;name&#8217;]\u6765\u83b7\u5f97\u5ba2\u6237\u7aef\u4e0a\u4f20\u6587\u4ef6\u540d\u79f0\uff0c\u4e0d\u5305\u542b\u8def\u5f84\u3002\u4f7f\u7528$_FILES[&#8216;file&#8217;][&#8216;tmp_name&#8217;]\u6765\u83b7\u5f97\u670d\u52a1\u7aef\u4fdd\u5b58\u4e0a\u4f20\u6587\u4ef6\u7684\u4e34\u65f6\u6587\u4ef6\u8def\u5f84<\/p>\n<p><strong>\u5b58\u653e\u4e0a\u4f20\u6587\u4ef6\u7684\u6587\u4ef6\u5939<\/strong><\/p>\n<p>PHP\u4e0d\u4f1a\u76f4\u63a5\u5c06\u4e0a\u4f20\u6587\u4ef6\u653e\u5230\u7f51\u7ad9\u6839\u76ee\u5f55\u4e2d\uff0c\u800c\u662f\u4fdd\u5b58\u4e3a\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\uff0c\u540d\u79f0\u5c31\u662f$_FILES[&#8216;file&#8217;][&#8216;tmp_name&#8217;]\u7684\u503c\uff0c\u5f00\u53d1\u8005\u5fc5\u987b\u628a\u8fd9\u4e2a\u4e34\u65f6\u6587\u4ef6\u590d\u5236\u5230\u5b58\u653e\u7684\u7f51\u7ad9\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p>$_FILES[&#8216;file&#8217;][&#8216;tmp_name&#8217;]\u7684\u503c\u662f\u7531PHP\u8bbe\u7f6e\u7684\uff0c\u4e0e\u6587\u4ef6\u539f\u59cb\u540d\u79f0\u4e0d\u4e00\u6837\uff0c\u5f00\u53d1\u8005\u5fc5\u987b\u4f7f\u7528$_FILES[&#8216;file&#8217;][&#8216;name&#8217;]\u6765\u53d6\u5f97\u4e0a\u4f20\u6587\u4ef6\u7684\u539f\u59cb\u540d\u79f0\u3002<\/p>\n<p><strong>\u4e0a\u4f20\u6587\u4ef6\u65f6\u7684\u9519\u8bef\u4fe1\u606f<\/strong><\/p>\n<p>$_FILES[&#8216;file&#8217;][&#8216;error&#8217;]\u53d8\u91cf\u7528\u6765\u4fdd\u5b58\u4e0a\u4f20\u6587\u4ef6\u65f6\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u5b83\u7684\u503c\u5982\u4e0b\uff1a<\/p>\n<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\" width=\"600\">\n<tbody>\n<tr>\n<td width=\"70\" align=\"center\" bgcolor=\"#cccccc\"><strong>\u9519\u8bef\u4fe1\u606f<\/strong><\/td>\n<td width=\"50\" align=\"center\" bgcolor=\"#cccccc\"><strong>\u6570\u503c<\/strong><\/td>\n<td align=\"center\" bgcolor=\"#cccccc\"><strong>\u8bf4\u00a0\u00a0\u00a0 \u660e<\/strong><\/td>\n<\/tr>\n<tr>\n<td>UPLOAD_ERR_OK<\/td>\n<td align=\"center\">0<\/td>\n<td>\u6ca1\u6709\u9519\u8bef<\/td>\n<\/tr>\n<tr>\n<td>UPLOAD_ERR_INI_SIZE<\/td>\n<td align=\"center\">1<\/td>\n<td>\u4e0a\u4f20\u6587\u4ef6\u7684\u5927\u5c0f\u8d85\u8fc7php.ini\u7684\u8bbe\u7f6e<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">UPLOAD_ERR_FROM_SIZE<\/td>\n<td align=\"center\">2<\/td>\n<td>\u4e0a\u4f20\u6587\u4ef6\u7684\u5927\u5c0f\u8d85\u8fc7HTML\u8868\u5355\u4e2dMAX_FILE_SIZE\u7684\u503c<\/td>\n<\/tr>\n<tr>\n<td>UPLOAD_ERR_PARTIAL<\/td>\n<td align=\"center\">3<\/td>\n<td>\u53ea\u4e0a\u4f20\u90e8\u5206\u7684\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>UPLOAD_ERR_NO_FILE<\/td>\n<td align=\"center\">4<\/td>\n<td>\u6ca1\u6709\u6587\u4ef6\u4e0a\u4f20<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u6587\u4ef6\u4e0a\u4f20\u6f0f\u6d1e<\/strong><\/p>\n<p>\u5982\u679c\u63d0\u4f9b\u7ed9\u7f51\u7ad9\u8bbf\u95ee\u8005\u4e0a\u4f20\u56fe\u7247\u7684\u529f\u80fd\uff0c\u90a3\u5fc5\u987b\u5c0f\u5fc3\u8bbf\u95ee\u8005\u4e0a\u4f20\u7684\u5b9e\u9645\u53ef\u80fd\u4e0d\u662f\u56fe\u7247\uff0c\u800c\u662f\u53ef\u4ee5\u6307\u5b9a\u7684PHP\u7a0b\u5e8f\u3002\u5982\u679c\u5b58\u653e\u56fe\u7247\u7684\u76ee\u5f55\u662f\u4e00\u4e2a\u5f00\u653e\u7684\u6587\u4ef6\u5939\uff0c\u5219\u5165\u4fb5\u8005\u5c31\u53ef\u4ee5\u8fdc\u7a0b\u6267\u884c\u4e0a\u4f20\u7684PHP\u6587\u4ef6\u6765\u8fdb\u884c\u653b\u51fb\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6587\u4ef6\u4e0a\u4f20\u4f8b\u5b50\uff1a<\/p>\n<p>&lt;?php<br \/>\n\/\/ \u8bbe\u7f6e\u4e0a\u4f20\u6587\u4ef6\u7684\u76ee\u5f55<br \/>\n$uploaddir = &#8220;D:\/www\/images\/&#8221;;<\/p>\n<p>\/\/ \u68c0\u67e5file\u662f\u5426\u5b58\u5728<br \/>\nif (isset($_FILES[&#8216;file1&#8217;]))<br \/>\n{<br \/>\n\/\/ \u8981\u653e\u5728\u7f51\u7ad9\u76ee\u5f55\u4e2d\u7684\u5b8c\u6574\u8def\u5f84\uff0c\u5305\u542b\u6587\u4ef6\u540d<br \/>\n$uploadfile = $uploaddir . $_FILES[&#8216;file1&#8217;][&#8216;name&#8217;];<br \/>\n\/\/ \u5c06\u670d\u52a1\u5668\u5b58\u653e\u7684\u8def\u5f84\uff0c\u79fb\u52a8\u5230\u771f\u5b9e\u6587\u4ef6\u540d<br \/>\nmove_uploaded_file($_FILES[&#8216;file1&#8217;][&#8216;tmp_name&#8217;], $uploadfile);<br \/>\n}<br \/>\n?&gt;<br \/>\n&#8230;&#8230;<br \/>\n&lt;form method=&#8221;post&#8221; enctype=&#8221;multipart\/form-data&#8221; name=&#8221;form1&#8243;&gt;<br \/>\n&lt;input type=&#8221;file&#8221; name=&#8221;file1&#8243; \/&gt;&lt;br \/&gt;<br \/>\n&lt;input type=&#8221;submit&#8221; value=&#8221;\u4e0a\u4f20\u6587\u4ef6&#8221; \/&gt;<br \/>\n&lt;input type=&#8221;hidden&#8221; name=&#8221;MAX_FILE_SIZE&#8221; value=&#8221;1024&#8243; \/&gt;<br \/>\n&lt;\/form&gt;<\/p>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u6ca1\u6709\u68c0\u9a8c\u6587\u4ef6\u540e\u7f00\uff0c\u53ef\u4ee5\u4e0a\u4f20\u4efb\u610f\u6587\u4ef6\uff0c\u5f88\u660e\u663e\u7684\u4e0a\u4f20\u6f0f\u6d1e<\/p>\n<p>\u6587\u7ae0\u6765\u6e90\uff1a<a href=\"http:\/\/www.sectop.com\/\">DoDo&#8217;s Blog<\/a><\/p>\n<p>\u539f\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.sectop.com\/post\/73.html\">http:\/\/www.sectop.com\/post\/73.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u5957web\u5e94\u7528\u7a0b\u5e8f\uff0c\u4e00\u822c\u90fd\u4f1a\u63d0\u4f9b\u6587\u4ef6\u4e0a\u4f20\u7684\u529f\u80fd\uff0c\u65b9\u4fbf\u6765\u8bbf\u8005\u4e0a\u4f20\u4e00\u4e9b\u6587\u4ef6\u3002 \u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u6587\u4ef6\u4e0a\u4f20\u8868\u5355 &#038;lt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[140,31],"class_list":["post-60","post","type-post","status-publish","format-standard","hentry","category-php","tag-php","tag-31"],"_links":{"self":[{"href":"https:\/\/508.me\/index.php?rest_route=\/wp\/v2\/posts\/60","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/508.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/508.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/508.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/508.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=60"}],"version-history":[{"count":4,"href":"https:\/\/508.me\/index.php?rest_route=\/wp\/v2\/posts\/60\/revisions"}],"predecessor-version":[{"id":65,"href":"https:\/\/508.me\/index.php?rest_route=\/wp\/v2\/posts\/60\/revisions\/65"}],"wp:attachment":[{"href":"https:\/\/508.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/508.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/508.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}