{"id":41,"date":"2023-06-05T12:39:29","date_gmt":"2023-06-05T04:39:29","guid":{"rendered":"http:\/\/pro369.com\/php\/?p=41"},"modified":"2019-06-21T00:49:00","modified_gmt":"2019-06-21T00:49:00","slug":"%e4%bd%bf%e7%94%a8php%e5%9f%b7%e8%a1%8clinux%e7%b3%bb%e7%b5%b1%e6%8c%87%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/por.tw\/php\/%e4%bd%bf%e7%94%a8php%e5%9f%b7%e8%a1%8clinux%e7%b3%bb%e7%b5%b1%e6%8c%87%e4%bb%a4\/","title":{"rendered":"\u4f7f\u7528PHP\u57f7\u884clinux\u7cfb\u7d71\u6307\u4ee4"},"content":{"rendered":"<p><font size=\"3\" color=\"#008000\"><strong>\u5982\u4f55\u4f7f\u7528PHP\u57f7\u884clinux\u7cfb\u7d71\u6307\u4ee4\u5462\uff1f<\/strong><\/font><br \/> <font size=\"4\" color=\"#ff0000\"><strong>\u76f8\u4fe1\u9019\u662f\u5f88\u591a\u5b78\u54e1\u60f3\u77e5\u9053\u7b54\u6848\uff01<\/strong><\/font><\/p>\n<p> <font size=\"4\" color=\"#800080\"><strong>\u9996\u5148\u5148\u8981\u7d66\u5927\u5bb6\u4ecb\u7d39PHP\u57f7\u884clinux\u7cfb\u7d71\u6307\u4ee4\u7684\u5e7e\u500b\u57fa\u672c\u51fd\u6578\u3002<\/strong><\/font><br \/> <font size=\"4\" style=\"background-color: #ffff00\"><strong><br \/> system\u51fd\u6578<\/strong><\/font><br \/> \u8aaa\u660e\uff1a\u57f7\u884c\u5916\u90e8\u7a0b\u5f0f\u4e26\u986f\u793a\u8f38\u51fa\u8cc7\u6599\u3002<br \/> \u8a9e\u6cd5\uff1astring system(string command, int [return_var]);<br \/> \u8fd4\u56de\u503c: \u5b57\u4e32<\/p>\n<p> <font size=\"4\" color=\"#ff00ff\"><strong>\u8a73\u7d30\u4ecb\u7d39\uff1a<\/strong><\/font><br \/> \u672c\u51fd\u6578\u5c31\u50cf\u662f C \u8a9e\u4e2d\u7684\u51fd\u6578 system()\uff0c\u7528\u4f86\u57f7\u884c\u6307\u4ee4\uff0c\u4e26\u8f38\u51fa\u7d50\u679c\u3002\u82e5\u662f return_var \u53c3\u6578\u5b58\u5728\uff0c\u5247\u57f7\u884c command \u4e4b\u5f8c\u7684\u72c0\u614b\u6703\u586b\u5165 return_var \u4e2d\u3002\u540c\u6a23\u503c\u5f97\u6ce8\u610f\u7684\u662f\u82e5\u9700\u8981\u8655\u7406\u4f7f\u7528\u8005\u8f38\u5165\u7684\u8cc7\u6599\uff0c\u800c\u53c8\u8981\u9632\u6b62\u4f7f\u7528\u8005\u800d\u82b1\u62db\u7834\u89e3\u7cfb\u7d71\uff0c\u5247\u53ef\u4ee5\u4f7f\u7528 EscapeShellCmd()\u3002\u82e5 PHP \u4ee5\u6a21\u7d44\u5f0f\u7684\u57f7\u884c\uff0c\u672c\u51fd\u6578\u6703\u5728\u6bcf\u4e00\u884c\u8f38\u51fa\u5f8c\u81ea\u52d5\u66f4\u65b0 Web \u4f3a\u670d\u5668\u7684\u8f38\u51fa\u7de9\u885d\u66ab\u5b58\u5340\u3002\u82e5\u9700\u8981\u5b8c\u6574\u7684\u8fd4\u56de\u5b57\u4e32\uff0c\u4e14\u4e0d\u60f3\u7d93\u7531\u4e0d\u5fc5\u8981\u7684\u5176\u5b83\u4e2d\u9593\u7684\u8f38\u51fa\u4ecb\u9762\uff0c\u53ef\u4ee5\u4f7f\u7528 PassThru()\u3002<\/p>\n<p> <font size=\"4\" color=\"#800080\"><strong>\u6848\u4f8b\u4ee3\u78bc\uff1a<\/strong><\/font><br \/> &lt; ?php<br \/> $last_line = system(&#39;ls&#39;, $retval);<br \/> echo &#39;Last line of the output: &#39; . $last_line;<br \/> echo &#39;&lt;hr \/&gt;Return value: &#39; . $retval;<br \/> ?&gt;<\/p>\n<p> <font size=\"4\" color=\"#0000ff\"><strong>exec\u51fd\u6578<\/strong><\/font><br \/> \u8aaa\u660e\uff1a\u57f7\u884c\u5916\u90e8\u7a0b\u5f0f\u3002<br \/> \u8a9e\u6cd5\uff1astring exec(string command, string [array], int [return_var]);<br \/> \u8fd4\u56de\u503c: \u5b57\u4e32<\/p>\n<p> <font size=\"4\" color=\"#ff00ff\"><strong>\u8a73\u7d30\u4ecb\u7d39\uff1a<\/strong><\/font><br \/> \u672c\u51fd\u6578\u57f7\u884c\u8f38\u5165 command \u7684\u5916\u90e8\u7a0b\u5f0f\u6216\u5916\u90e8\u6307\u4ee4\u3002<br \/> \u5b83\u7684\u8fd4\u56de\u5b57\u4e32\u53ea\u662f\u5916\u90e8\u7a0b\u5f0f\u57f7\u884c\u5f8c\u8fd4\u56de\u7684\u6700\u5f8c\u4e00\u884c\uff1b\u82e5\u9700\u8981\u5b8c\u6574\u7684\u8fd4\u56de\u5b57\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528 PassThru() \u9019\u500b\u51fd\u6578\u3002<\/p>\n<p> \u8981\u662f\u53c3\u6578 array \u5b58\u5728\uff0ccommand \u6703\u5c07 array \u52a0\u5230\u53c3\u6578\u4e2d\u57f7\u884c\uff0c\u82e5\u4e0d\u6b32 array \u88ab\u8655\u7406\uff0c\u53ef\u4ee5\u5728\u57f7\u884c exec() \u4e4b\u524d\u547c\u53eb unset()\u3002<br \/> \u82e5\u662f return_var \u8ddf array \u4e8c\u500b\u53c3\u6578\u90fd\u5b58\u5728\uff0c\u5247\u57f7\u884c command \u4e4b\u5f8c\u7684\u72c0\u614b\u6703\u586b\u5165 return_var \u4e2d\u3002<\/p>\n<p> \u503c\u5f97\u6ce8\u610f\u7684\u662f\u82e5\u9700\u8981\u8655\u7406\u4f7f\u7528\u8005\u8f38\u5165\u7684\u8cc7\u6599\uff0c\u800c\u53c8\u8981\u9632\u6b62\u4f7f\u7528\u8005\u800d\u82b1\u62db\u7834\u89e3\u7cfb\u7d71\uff0c\u5247\u53ef\u4ee5\u4f7f\u7528 EscapeShellCmd()\u3002<\/p>\n<p> <font size=\"4\" color=\"#800000\"><strong>\u6848\u4f8b\u4ee3\u78bc\uff1a<\/strong><\/font><br \/> &lt;?php<br \/> echo exec(&#39;whoami&#39;);<br \/> ?&gt; &nbsp;<\/p>\n<p> <font size=\"4\" color=\"#800080\"><strong>popen\u51fd\u6578<\/strong><\/font><br \/> \u8aaa\u660e\uff1a\u958b\u555f\u6a94\u6848\u3002<br \/> \u8a9e\u6cd5\uff1aint popen(string command, string mode);<br \/> \u8fd4\u56de\u503c: \u6574\u6578<\/p>\n<p> <font size=\"4\" color=\"#ff0000\"><strong>\u8a73\u7d30\u4ecb\u7d39\uff1a<\/strong><\/font><br \/> \u672c\u51fd\u6578\u57f7\u884c\u6307\u4ee4\u958b\u6a94\uff0c\u800c\u8a72\u6a94\u6848\u662f\u7528\u7ba1\u9053\u6a21\u5f0f\u8655\u7406\u7684\u6a94\u6848\u3002<br \/> \u7528\u672c\u51fd\u6578\u958b\u555f\u7684\u6a94\u6848\u53ea\u80fd\u662f\u55ae\u5411\u7684 (\u53ea\u80fd\u8b80\u6216\u53ea\u80fd\u5beb)\uff0c\u800c\u4e14\u4e00\u5b9a\u8981\u7528 pclose() \u95dc\u9589\u3002<br \/> \u5728\u6a94\u6848\u64cd\u4f5c\u4e0a\u53ef\u4f7f\u7528 fgets()\u3001fgetss() \u8207 fputs()\u3002\u82e5\u662f\u958b\u6a94\u767c\u751f\u932f\u8aa4\uff0c\u8fd4\u56de false \u503c\u3002<\/p>\n<p> <font size=\"4\" color=\"#0000ff\"><strong>\u6848\u4f8b\u4ee3\u78bc\uff1a<\/strong><\/font><br \/> &lt;?<br \/> $fp = popen( &quot;\/bin\/ls&quot;, &quot;r&quot; );<br \/> ?&gt; &nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528PHP\u57f7\u884clinux\u7cfb\u7d71\u6307\u4ee4\u5462\uff1f \u76f8\u4fe1\u9019\u662f\u5f88\u591a\u5b78\u54e1\u60f3\u77e5\u9053\u7b54\u6848\uff01 \u9996\u5148\u5148\u8981\u7d66\u5927\u5bb6\u4ecb\u7d39PHP\u57f7\u884clinux [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":387,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[22],"class_list":["post-41","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/41"}],"collection":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":0,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media\/387"}],"wp:attachment":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}