{"id":1268,"date":"2026-01-06T17:30:27","date_gmt":"2026-01-06T09:30:27","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=1268"},"modified":"2026-01-06T17:30:27","modified_gmt":"2026-01-06T09:30:27","slug":"php%e9%98%b2%e6%ad%a2shell%e5%91%bd%e4%bb%a4%e6%b3%a8%e5%85%a5%e7%9a%84%e6%9c%89%e6%95%88%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2026\/01\/06\/php%e9%98%b2%e6%ad%a2shell%e5%91%bd%e4%bb%a4%e6%b3%a8%e5%85%a5%e7%9a%84%e6%9c%89%e6%95%88%e6%96%b9%e6%b3%95\/","title":{"rendered":"PHP\u9632\u6b62Shell\u547d\u4ee4\u6ce8\u5165\u7684\u6709\u6548\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u597d\u7684\uff0c\u963f\u82e5\u8431\uff0c\u9632\u6b62 <strong>Shell \u547d\u4ee4\u6ce8\u5165<\/strong> \u662f Web \u5b89\u5168\u4e2d\u7684\u5173\u952e\u95ee\u9898\u4e4b\u4e00\u3002\u5728 PHP \u4e2d\uff0cShell \u6ce8\u5165\u653b\u51fb\u901a\u5e38\u53d1\u751f\u5728\u7528\u6237\u8f93\u5165\u672a\u7ecf\u8fc7\u6ee4\u6216\u9a8c\u8bc1\u7684\u60c5\u51b5\u4e0b\u88ab\u76f4\u63a5\u4f20\u9012\u5230\u7cfb\u7edf\u547d\u4ee4\u4e2d\uff0c\u653b\u51fb\u8005\u53ef\u4ee5\u5229\u7528\u8fd9\u4e00\u70b9\u6765\u6267\u884c\u4efb\u610f\u547d\u4ee4\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u6211\u4f1a\u4ece <strong>\u9632\u8303\u539f\u7406<\/strong>\u3001<strong>\u5e38\u89c1\u653b\u51fb\u793a\u4f8b<\/strong> \u548c <strong>\u6709\u6548\u9632\u5fa1\u65b9\u6cd5<\/strong> \u7ed9\u4f60\u8be6\u7ec6\u8bb2\u89e3\uff0c\u5e76\u7ed9\u51fa <strong>\u5b9e\u9645\u793a\u4f8b<\/strong>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e00\u3001Shell \u547d\u4ee4\u6ce8\u5165\u539f\u7406<\/h1>\n\n\n\n<p>Shell \u547d\u4ee4\u6ce8\u5165\u662f\u6307\u653b\u51fb\u8005\u901a\u8fc7\u4e0d\u6b63\u5f53\u7684\u65b9\u5f0f\u5728\u7528\u6237\u8f93\u5165\u4e2d\u5d4c\u5165\u6076\u610f\u547d\u4ee4\uff0c\u6700\u7ec8\u6267\u884c\u7cfb\u7edf\u7ea7\u547d\u4ee4\u3002\u6076\u610f\u547d\u4ee4\u53ef\u80fd\u662f\u5220\u9664\u6587\u4ef6\u3001\u83b7\u53d6\u654f\u611f\u4fe1\u606f\u6216\u8fdc\u7a0b\u6267\u884c\u4ee3\u7801\u7b49\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e8c\u3001\u5e38\u89c1\u7684\u653b\u51fb\u793a\u4f8b<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 \u7b80\u5355\u7684 Shell \u6ce8\u5165<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\n\/\/ \u4e0d\u5b89\u5168\u7684\u4ee3\u7801\uff0c\u7528\u6237\u8f93\u5165\u76f4\u63a5\u4f20\u5165 Shell \u547d\u4ee4\n$filename = $_GET&#x5B;&#039;file&#039;];\nsystem(&quot;cat $filename&quot;);\n\n<\/pre><\/div>\n\n\n<p><strong>\u653b\u51fb\u8005<\/strong>\uff1a<code>http:\/\/example.com\/?file=..\/..\/etc\/passwd<\/code><\/p>\n\n\n\n<p>\u901a\u8fc7\u8def\u5f84\u904d\u5386\u653b\u51fb\uff0c\u653b\u51fb\u8005\u53ef\u4ee5\u8bfb\u53d6\u4efb\u610f\u6587\u4ef6\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2\ufe0f\u20e3 \u901a\u8fc7\u7ba1\u9053\u6ce8\u5165\u6076\u610f\u547d\u4ee4<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\n\/\/ \u4e0d\u5b89\u5168\u7684\u4ee3\u7801\uff0c\u7528\u6237\u8f93\u5165\u76f4\u63a5\u4f20\u5165 Shell \u547d\u4ee4\n$user_input = $_GET&#x5B;&#039;cmd&#039;];\nsystem(&quot;ls $user_input&quot;);\n\n<\/pre><\/div>\n\n\n<p><strong>\u653b\u51fb\u8005<\/strong>\uff1a<code>http:\/\/example.com\/?cmd=| rm -rf \/<\/code><\/p>\n\n\n\n<p>\u901a\u8fc7\u7ba1\u9053\u7b26 <code>|<\/code>\uff0c\u653b\u51fb\u8005\u53ef\u4ee5\u5c06\u6076\u610f\u547d\u4ee4\u6ce8\u5165\uff0c\u5bfc\u81f4\u7cfb\u7edf\u6587\u4ef6\u88ab\u5220\u9664\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e09\u3001\u6709\u6548\u7684\u9632\u8303\u65b9\u6cd5<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 \u4f7f\u7528 <code>escapeshellarg()<\/code> \u548c <code>escapeshellcmd()<\/code> \u51fd\u6570<\/h3>\n\n\n\n<p>\u8fd9\u4e24\u4e2a PHP \u5185\u7f6e\u51fd\u6570\u53ef\u4ee5\u5bf9\u7528\u6237\u8f93\u5165\u8fdb\u884c\u8f6c\u4e49\uff0c\u907f\u514d Shell \u6ce8\u5165\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>escapeshellarg()<\/code><\/strong>\uff1a\u8f6c\u4e49\u5355\u4e00\u53c2\u6570\uff0c\u4f7f\u5176\u5b89\u5168\u3002<\/li>\n\n\n\n<li><strong><code>escapeshellcmd()<\/code><\/strong>\uff1a\u8f6c\u4e49\u6574\u4e2a\u547d\u4ee4\uff0c\u4f7f\u5176\u5b89\u5168\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\n$filename = escapeshellarg($_GET&#x5B;&#039;file&#039;]);\nsystem(&quot;cat $filename&quot;);  \/\/ \u5b89\u5168\u4f7f\u7528\u7528\u6237\u8f93\u5165\n\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><code>escapeshellarg()<\/code> \u5c06\u6587\u4ef6\u540d\u53c2\u6570\u53d8\u6210 <code>cat 'user_input'<\/code>\uff0c\u9632\u6b62\u547d\u4ee4\u6ce8\u5165\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2\ufe0f\u20e3 \u4f7f\u7528 <code>proc_open()<\/code> \u6216 <code>exec()<\/code> \u65f6\u907f\u514d\u76f4\u63a5\u4f20\u9012\u7528\u6237\u8f93\u5165<\/h3>\n\n\n\n<p>\u5982\u679c\u8981\u6267\u884c\u5916\u90e8\u547d\u4ee4\uff0c\u907f\u514d\u76f4\u63a5\u5c06\u7528\u6237\u8f93\u5165\u653e\u5165\u547d\u4ee4\u884c\uff0c\u53ef\u4ee5\u901a\u8fc7\u5206\u5f00\u4f20\u9012\u547d\u4ee4\u548c\u53c2\u6570\u6765\u6267\u884c\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\n$filename = escapeshellarg($_GET&#x5B;&#039;file&#039;]);\n$command = &quot;cat $filename&quot;;\n$output = &#x5B;];\nexec($command, $output);\n\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>\u901a\u8fc7\u5206\u5f00\u4f20\u9012\u547d\u4ee4\u548c\u53c2\u6570\uff0c\u51cf\u5c11\u6ce8\u5165\u98ce\u9669\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3\ufe0f\u20e3 \u9650\u5236\u7528\u6237\u8f93\u5165<\/h3>\n\n\n\n<p>\u9664\u4e86\u5bf9\u7528\u6237\u8f93\u5165\u8fdb\u884c\u8f6c\u4e49\uff0c\u5f3a\u70c8\u5efa\u8bae<strong>\u9a8c\u8bc1\u548c\u8fc7\u6ee4<\/strong>\u7528\u6237\u8f93\u5165\u3002\u4f7f\u7528 <strong>\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong> \u6216 <strong>\u8fc7\u6ee4\u5668<\/strong> \u68c0\u67e5\u8f93\u5165\u662f\u5426\u7b26\u5408\u9884\u671f\u7684\u683c\u5f0f\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u8f93\u5165\u662f\u6587\u4ef6\u540d\uff0c\u53ef\u4ee5\u9650\u5236\u8f93\u5165\u4ec5\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u7b49\u5408\u6cd5\u5b57\u7b26\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\n$filename = $_GET&#x5B;&#039;file&#039;];\n\n\/\/ \u53ea\u5141\u8bb8\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\nif (preg_match(&#039;\/^&#x5B;a-zA-Z0-9_]+$\/&#039;, $filename)) {\n    $filename = escapeshellarg($filename);\n    system(&quot;cat $filename&quot;);\n} else {\n    echo &quot;Invalid filename!&quot;;\n}\n\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong>\uff1a\u901a\u8fc7 <code>\/^[a-zA-Z0-9_]+$\/<\/code> \u6765\u786e\u4fdd\u8f93\u5165\u5408\u6cd5\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4\ufe0f\u20e3 \u4f7f\u7528 PHP \u5185\u5efa\u7684\u51fd\u6570\u66ff\u4ee3 Shell \u547d\u4ee4<\/h3>\n\n\n\n<p>PHP \u63d0\u4f9b\u4e86\u8bb8\u591a <strong>\u5185\u5efa\u51fd\u6570<\/strong> \u53ef\u4ee5\u66ff\u4ee3 Shell \u547d\u4ee4\uff0c\u5c3d\u91cf\u907f\u514d\u8c03\u7528 Shell \u547d\u4ee4\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7528 <code>file_get_contents()<\/code> \u6216 <code>fopen()<\/code> \u66ff\u4ee3 <code>cat<\/code><\/li>\n\n\n\n<li>\u7528 <code>unlink()<\/code> \u66ff\u4ee3 <code>rm<\/code><\/li>\n\n\n\n<li>\u7528 <code>mkdir()<\/code> \u66ff\u4ee3 <code>mkdir -p<\/code><\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\n$filename = $_GET&#x5B;&#039;file&#039;];\nif (file_exists($filename)) {\n    $contents = file_get_contents($filename);\n    echo nl2br($contents);  \/\/ \u663e\u793a\u6587\u4ef6\u5185\u5bb9\n} else {\n    echo &quot;File not found!&quot;;\n}\n\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>\u901a\u8fc7\u4f7f\u7528 <strong>PHP \u5185\u5efa\u51fd\u6570<\/strong>\uff0c\u6211\u4eec\u53ef\u4ee5\u5b8c\u5168\u907f\u514d Shell \u547d\u4ee4\uff0c\u4ece\u6839\u672c\u4e0a\u907f\u514d Shell \u6ce8\u5165\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5\ufe0f\u20e3 \u4f7f\u7528 Web \u5e94\u7528\u9632\u706b\u5899\uff08WAF\uff09<\/h3>\n\n\n\n<p>\u90e8\u7f72 <strong>WAF<\/strong>\uff08\u5982 <strong>ModSecurity<\/strong>\uff09\u53ef\u4ee5\u5e2e\u52a9\u8fc7\u6ee4\u4e00\u4e9b\u6076\u610f\u8bf7\u6c42\u3002\u867d\u7136 WAF \u4e0d\u80fd\u5b8c\u5168\u66ff\u4ee3\u4ee3\u7801\u4e2d\u7684\u9632\u5fa1\u63aa\u65bd\uff0c\u4f46\u5b83\u662f\u4e00\u4e2a\u989d\u5916\u7684\u5b89\u5168\u5c42\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ModSecurity<\/strong> \u662f\u4e00\u4e2a\u5e38\u89c1\u7684 Web \u5e94\u7528\u9632\u706b\u5899\uff0c\u80fd\u591f\u9632\u6b62 SQL \u6ce8\u5165\u3001Shell \u6ce8\u5165\u7b49\u653b\u51fb\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">6\ufe0f\u20e3 \u9650\u5236 PHP \u6267\u884c\u7684\u6743\u9650<\/h3>\n\n\n\n<p><strong>\u6700\u5c0f\u6743\u9650\u539f\u5219<\/strong>\uff1a\u5c06 PHP \u8fdb\u7a0b\u7684\u6267\u884c\u6743\u9650\u9650\u5236\u5728\u6700\u5c0f\u8303\u56f4\u5185\uff0c\u53ea\u5141\u8bb8\u5176\u8bbf\u95ee\u5fc5\u9700\u7684\u6587\u4ef6\u548c\u6267\u884c\u7279\u5b9a\u7684\u547d\u4ee4\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 <code>chroot<\/code> \u9650\u5236\u6587\u4ef6\u8bbf\u95ee<\/strong><\/li>\n\n\n\n<li><strong>\u7981\u7528\u4e0d\u5fc5\u8981\u7684 PHP \u51fd\u6570<\/strong>\uff08\u5982 <code>exec()<\/code>\u3001<code>shell_exec()<\/code>\u3001<code>system()<\/code> \u7b49\uff09<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><br>\u5728 <code>php.ini<\/code> \u914d\u7f6e\u4e2d\u7981\u7528\u5371\u9669\u51fd\u6570\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndisable_functions = exec, system, shell_exec, passthru\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u56db\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u603b\u7ed3<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u95ee\u9898<\/th><th>\u89e3\u51b3\u65b9\u6848<\/th><\/tr><\/thead><tbody><tr><td><strong>\u901a\u8fc7\u7ba1\u9053\u7b26\u6ce8\u5165<\/strong><\/td><td>\u4f7f\u7528 <code>escapeshellarg()<\/code> \u548c <code>escapeshellcmd()<\/code><\/td><\/tr><tr><td><strong>\u7528\u6237\u8f93\u5165\u4e0d\u53d7\u63a7<\/strong><\/td><td>\u4f7f\u7528\u6b63\u5219\u9a8c\u8bc1\u3001\u8fc7\u6ee4\u8f93\u5165<\/td><\/tr><tr><td><strong>Shell \u547d\u4ee4\u4e0d\u53ef\u907f\u514d<\/strong><\/td><td>\u4f7f\u7528 PHP \u5185\u5efa\u51fd\u6570\u4ee3\u66ff\u5916\u90e8\u547d\u4ee4<\/td><\/tr><tr><td><strong>\u6743\u9650\u8fc7\u5927<\/strong><\/td><td>\u9650\u5236 PHP \u6267\u884c\u6743\u9650\uff0c\u7981\u7528\u4e0d\u5fc5\u8981\u7684\u51fd\u6570<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e94\u3001\u4e00\u53e5\u8bdd\u603b\u7ed3<\/h1>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u9632\u6b62 Shell \u6ce8\u5165\u7684\u5173\u952e\u662f\uff1a\u5bf9\u7528\u6237\u8f93\u5165\u8fdb\u884c\u5145\u5206\u9a8c\u8bc1\u4e0e\u8f6c\u4e49\uff0c\u5c3d\u91cf\u907f\u514d\u76f4\u63a5\u6267\u884c\u5916\u90e8\u547d\u4ee4\uff0c\u4f7f\u7528 PHP \u5185\u5efa\u51fd\u6570\u4ee3\u66ff Shell \u547d\u4ee4\u3002<\/strong><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u597d\u7684\uff0c\u963f\u82e5\u8431\uff0c\u9632\u6b62 Shell \u547d\u4ee4\u6ce8\u5165 \u662f Web \u5b89\u5168\u4e2d\u7684\u5173\u952e\u95ee\u9898\u4e4b\u4e00\u3002\u5728 &#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2026\/01\/06\/php%e9%98%b2%e6%ad%a2shell%e5%91%bd%e4%bb%a4%e6%b3%a8%e5%85%a5%e7%9a%84%e6%9c%89%e6%95%88%e6%96%b9%e6%b3%95\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-1268","post","type-post","status-publish","format-standard","hentry","category-php"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=1268"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1268\/revisions"}],"predecessor-version":[{"id":1269,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/1268\/revisions\/1269"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=1268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=1268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=1268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}