{"id":5,"date":"2024-08-22T10:13:06","date_gmt":"2024-08-22T02:13:06","guid":{"rendered":"http:\/\/8.147.235.132:3838\/?p=5"},"modified":"2024-08-22T10:26:00","modified_gmt":"2024-08-22T02:26:00","slug":"php%e9%ab%98%e6%80%a7%e8%83%bd%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e4%b9%8b%e7%ae%a1%e9%81%931","status":"publish","type":"post","link":"https:\/\/www.jpxiao.cn\/index.php\/2024\/08\/22\/php%e9%ab%98%e6%80%a7%e8%83%bd%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e4%b9%8b%e7%ae%a1%e9%81%931\/","title":{"rendered":"PHP\u9ad8\u6027\u80fd\u7f51\u7edc\u7f16\u7a0b\u4e4b\u7ba1\u9053(1)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"javascript:;\">9<\/a><a href=\"javascript:;\">2<\/a><a href=\"https:\/\/learnku.com\/articles\/87778#replies\">5<\/a><a href=\"https:\/\/learnku.com\/topics\/87778\/patches\/create\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ba1\u9053\u662f\u4ec0\u4e48\uff1f<br>\u7ba1\u9053\uff08Pipe\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u8fde\u63a5\u4e24\u4e2a\u6216\u591a\u4e2a\u547d\u4ee4\u7684\u6807\u51c6\u5de5\u5177\uff0c\u4f7f\u5f97\u524d\u4e00\u4e2a\u547d\u4ee4\u7684\u8f93\u51fa\u6210\u4e3a\u540e\u4e00\u4e2a\u547d\u4ee4\u7684\u8f93\u5165\u3002\u867d\u7136\u7ba1\u9053\u8fd9\u4e2a\u8bcd\u5bf9\u4e00\u4e9b\u4eba\u6765\u8bf4\u53ef\u80fd\u6709\u4e9b\u964c\u751f\uff0c\u4f46\u5728\u65e5\u5e38\u7f16\u7a0b\u5de5\u4f5c\u4e2d\uff0c\u5c24\u5176\u662f\u4f7f\u7528 Linux \u6216 Unix<br>shell \u65f6\uff0c\u7ba1\u9053\u662f\u975e\u5e38\u5e38\u89c1\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u8003\u8651\u4e0b\u9762\u8fd9\u6761\u547d\u4ee4\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo &#8220;hello&#8221; | grep &#8220;he&#8221;<br>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u91cd\u5199\u4e3a\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(echo &#8220;hello&#8221;) | (grep &#8220;he&#8221;)<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u8fd9\u91cc\uff0c\u201cecho\u201d \u548c \u201cgrep\u201d \u90fd\u662f\u53ef\u6267\u884c\u7684\u4e8c\u8fdb\u5236\u7a0b\u5e8f\u3002<\/h1>\n\n\n\n<h1 class=\"wp-block-heading\">| \u7b26\u53f7\u8868\u793a\u7ba1\u9053\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u5c06\u524d\u4e00\u4e2a\u547d\u4ee4\u7684\u8f93\u51fa\u4f5c\u4e3a\u540e\u4e00\u4e2a\u547d\u4ee4\u7684\u8f93\u5165\u3002<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u6307\u4ee4\u7684\u6267\u884c\u6d41\u7a0b<br>\u521b\u5efa\u5b50\u8fdb\u7a0b\uff1ashell \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b50\u8fdb\u7a0b\u6765\u6267\u884c echo \u201chello\u201d \u547d\u4ee4\uff1b<br>\u6807\u51c6\u8f93\u51fa\uff1a\u4e8c\u8fdb\u5236\u6587\u4ef6 echo \u4f1a\u6839\u636e\u63a5\u6536\u5230\u7684\u53c2\u6570\u201dhello\u201d \u5c06\u5b57\u7b26\u4e32 \u201chello\u201d \u5199\u5165\u5176\u6807\u51c6\u8f93\u51fa\uff0c\u8fd9\u5c31\u662f echo \u8981\u505a\u7684\u4e8b\uff1b<br>\u7ba1\u9053\u4f20\u9012\uff1ashell \u901a\u8fc7\u7ba1\u9053\u5c06 \u201chello\u201d \u4ece echo \u7684\u6807\u51c6\u8f93\u51fa\u4f20\u9012\u5230 grep \u7684\u6807\u51c6\u8f93\u5165\uff1b<br>grep \u5904\u7406\uff1agrep \u4ece\u7ba1\u9053\u8bfb\u53d6 \u201chello\u201d \u5e76\u68c0\u67e5\u662f\u5426\u5305\u542b\u6a21\u5f0f \u201che\u201d;<br>\u8f93\u51fa\u7ed3\u679c\uff1a\u5982\u679c\u5339\u914d\u6210\u529f\uff0cgrep \u5c06\u5339\u914d\u7684\u7ed3\u679c\u6e32\u67d3\u5e76\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa\uff1b<br>\u5927\u591a\u6570 shell\uff08\u5982 bash \u6216 zsh\uff09\u90fd\u652f\u6301\u7ba1\u9053\u529f\u80fd\u3002\u901a\u8fc7\u7ba1\u9053\uff0c\u7528\u6237\u53ef\u4ee5\u6784\u5efa\u590d\u6742\u7684\u547d\u4ee4\u5e8f\u5217\u6765\u5b8c\u6210\u7279\u5b9a\u4efb\u52a1\uff1b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u4e0e PHP \u6709\u4f55\u5173\u7cfb\uff1f<br>\u73b0\u5728\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u5177\u4f53\u7684\u793a\u4f8b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(echo &#8220;&lt;?php sleep(1); echo &#8216;hello,world&#8217;;&#8221;) | (php)<br>\u6839\u636e\u4e0a\u9762\u7684\u6267\u884c\u6d41\u7a0b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u547d\u4ee4\u5206\u89e3\u4e3a\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u521b\u5efa\u5b50\u8fdb\u7a0b\uff1ashell \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b50\u8fdb\u7a0b\u6765\u6267\u884c echo \u201c&lt;?php sleep (1); echo \u2018hello,world\u2019;\u201d \u547d\u4ee4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u811a\u672c\u8f93\u51fa\uff1aecho \u547d\u4ee4\u5c06 PHP \u811a\u672c\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ba1\u9053\u4f20\u9012\uff1ashell \u4f7f\u7528\u7ba1\u9053\u5c06\u8fd9\u4e2a PHP \u811a\u672c\u4f5c\u4e3a\u8f93\u5165\u4f20\u9012\u7ed9 php \u547d\u4ee4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PHP \u89e3\u6790\uff1aphp \u89e3\u91ca\u5668\u8bfb\u53d6\u7ba1\u9053\u4e2d\u7684 PHP \u811a\u672c\uff0c\u5e76\u6267\u884c\u5176\u4e2d\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u7ed3\u679c\uff1a\u7531\u4e8e PHP \u811a\u672c\u4e2d\u5305\u542b\u4e86 echo \u2018hello,world\u2019;\uff0c\u6240\u4ee5 php \u89e3\u91ca\u5668\u4f1a\u8f93\u51fa \u201chello,world\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c1d\u8bd5\u4e00\u4e2a\u4e0d\u540c\u7684\u793a\u4f8b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(echo &#8220;&lt;?php sleep(1); echo &#8216;hello,world&#8217;;&#8221;) | (php -v)<br>\u7ed3\u679c\u5206\u6790\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b php -v \u8f93\u51fa PHP \u7248\u672c\u4fe1\u606f\u800c\u4e0d\u662f\u6267\u884c\u811a\u672c\u3002<br>\u8fd9\u662f\u56e0\u4e3a php -v \u662f\u4e00\u4e2a\u6574\u4f53\u547d\u4ee4\uff0c\u7528\u4e8e\u663e\u793a PHP \u7684\u7248\u672c\u4fe1\u606f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48\u4e0d\u6267\u884c\u7ba1\u9053\u4e2d\u7684\u6307\u4ee4\u5462\uff1f<br>\u4e8b\u5b9e\u4e0a\u8fd9\u4e0d\u662f\u5fc5\u7136\u6027\u7684\uff0c\u8fd9\u53ea\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6 php \u7684\u51b3\u5b9a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53 php \u547d\u4ee4\u5e26\u6709\u53c2\u6570\u65f6\uff0c\u5b83\u4e0d\u4f1a\u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u4efb\u4f55\u5185\u5bb9\uff0c\u800c\u662f\u76f4\u63a5\u6309\u7167\u53e6\u4e00\u79cd\u81ea\u884c\u51b3\u5b9a\u7684\u65b9\u5f0f\u6267\u884c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PHP \u4e2d\u7684\u7ba1\u9053<br>PHP \u5141\u8bb8\u4f7f\u7528 proc_open \u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\u63a7\u5236\u5757\uff0c\u8fd9\u4e2a\u8fdb\u7a0b\u63a7\u5236\u5757\u62e5\u6709\u72ec\u7acb\u7684\u8f93\u5165\u8f93\u51fa\u6d41\uff0c\u53ef\u4ee5\u7528\u6765\u5b9e\u73b0\u7ba1\u9053\u7684\u529f\u80fd<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;?php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/\/$descriptorspec\u7684\u4e3a\u56fa\u5b9a\u7ed3\u6784,\u8fd9\u662f\u5b83\u7684\u8bbe\u8ba1\u8005\u6307\u660e\u7684<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$descriptorspec = [<br>0 =&gt; [&#8216;pipe&#8217;, &#8216;r&#8217;], \/\/ \u6807\u51c6\u8f93\u5165<br>1 =&gt; [&#8216;pipe&#8217;, &#8216;w&#8217;], \/\/ \u6807\u51c6\u8f93\u51fa<br>2 =&gt; [&#8216;pipe&#8217;, &#8216;w&#8217;], \/\/ \u6807\u51c6\u9519\u8bef<br>];<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$process = proc_open(&#8216;\/bin\/sh&#8217;, $descriptorspec, $pipes);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if (is_resource($process)) {<br>fwrite($pipes[0], &#8216;echo &#8220;hello,world&#8221;&#8216;);<br>fclose($pipes[0]);<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo stream_get_contents($pipes&#91;1]);\nfclose($pipes&#91;1]);\n\nproc_close($process);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">}<br>\u901a\u8fc7\u4e0a\u8ff0\u7b80\u5355\u4f8b\u5b50\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 PHP \u6765\u5b9e\u73b0\u7ba1\u9053\u7684\u529f\u80fd\uff0c\u76f4\u63a5\u6a21\u62df\u4e00\u4e2a\u7ec8\u7aef\u4f1a\u8bdd\uff0c\u751a\u81f3\u80fd\u81ea\u5df1\u5b9e\u73b0\u6e32\u67d3\u5e76\u5b9e\u73b0\u4e00\u4e2a\u7c7b\u4f3c\u4e8e zsh \u4e00\u6837\u7684 shell \u7ba1\u7406\u5de5\u5177<br>\u5927\u80c6\u70b9\u60f3\u6211\u4eec\u662f\u4e0d\u662f\u53ef\u80fd\u76f4\u63a5\u8bbf\u95ee PHP \u4e8c\u8fdb\u5236\u6587\u4ef6\u6253\u5f00\u4e00\u4e2a PHP \u8fdb\u7a0b\uff0c\u7136\u540e\u901a\u8fc7\u7ba1\u9053\u7684\u65b9\u5f0f\u6765\u6267\u884c PHP \u811a\u672c\u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PHP \u4e2d\u6253\u5f00 PHP \u8fdb\u7a0b<br>&lt;?php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/\/$descriptorspec\u7684\u4e3a\u56fa\u5b9a\u7ed3\u6784,\u8fd9\u662f\u5b83\u7684\u8bbe\u8ba1\u8005\u6307\u660e\u7684<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$descriptorspec = [<br>0 =&gt; [&#8216;pipe&#8217;, &#8216;r&#8217;], \/\/ \u6807\u51c6\u8f93\u5165<br>1 =&gt; [&#8216;pipe&#8217;, &#8216;w&#8217;], \/\/ \u6807\u51c6\u8f93\u51fa<br>2 =&gt; [&#8216;pipe&#8217;, &#8216;w&#8217;], \/\/ \u6807\u51c6\u9519\u8bef<br>];<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$process = proc_open(PHP_BINARY, $descriptorspec, $pipes);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if (is_resource($process)) {<br>fwrite($pipes[0], file_get_contents(&#8216;test.php&#8217;));<br>fclose($pipes[0]);<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo stream_get_contents($pipes&#91;1]);\nfclose($pipes&#91;1]);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">}<br>\u662f\u7684\uff0c\u4e0a\u9762\u7684\u4ee3\u7801\u4f1a\u5982\u6211\u4eec\u6240\u60f3\u7684\u90a3\u6837\uff0c\u6253\u5f00\u4e00\u4e2a PHP \u8fdb\u7a0b\uff0c\u5e76\u901a\u8fc7\u7ba1\u9053\u7684\u65b9\u5f0f\u6267\u884c test.php \u5185\u7684\u811a\u672c\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u662f\u4e0d\u662f\u6709\u79cd\u53d1\u73b0\u65b0\u5927\u9646\u7684\u611f\u89c9\uff1a\u638c\u63e1\u4e86\u8fd9\u4e2a\u65b9\u6cd5\u662f\u4e0d\u662f\u53ef\u4ee5\u79bb\u5f00 shell_exec \u8fd9\u4e2a\u51fd\u6570\u4e86\u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ca1\u9519\uff0c\u5b83\u5b8c\u5168\u53ef\u4ee5\u505a\u5230\uff0c\u4f46\u5982\u679c\u9700\u8981\u81ea\u5df1\u6765\u7ba1\u7406\u8f93\u5165\u8f93\u51fa\u6d41\uff0c\u8fd9\u5728\u590d\u6742\u7684\u7ba1\u9053\u64cd\u4f5c\u4e2d\u4f1a\u53d8\u5f97\u975e\u5e38\u9ebb\u70e6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a rel=\"noreferrer noopener\" href=\"https:\/\/learnku.com\/topics\/87778\/patches\/create\" target=\"_blank\"><\/a><a href=\"javascript:void(0)\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>925 \u7ba1\u9053\u662f\u4ec0\u4e48\uff1f\u7ba1\u9053\uff08Pipe\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u8fde\u63a5\u4e24\u4e2a\u6216\u591a\u4e2a\u547d\u4ee4\u7684\u6807\u51c6\u5de5\u5177\uff0c\u4f7f\u5f97\u524d\u4e00\u4e2a\u547d\u4ee4\u7684\u8f93\u51fa\u6210\u4e3a\u540e\u4e00\u4e2a\u547d\u4ee4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":1,"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"predecessor-version":[{"id":7,"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/posts\/5\/revisions\/7"}],"wp:attachment":[{"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jpxiao.cn\/index.php\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}