PHPUnit Command Injection Vulnerability — PHPUnit allows remote attackers to execute arbitrary PHP code via HTTP POST data beginning with a "<?php " substring, as demonstrated by an attack on a site with an exposed /vendor folder, i.e., external access to the /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php URI.
CVE-2017-9841 is a critical command injection vulnerability in PHPUnit that allows remote attackers to execute arbitrary PHP code by sending HTTP POST requests containing PHP code to the exposed eval-stdin.php file. This vulnerability has a CVSS score of 9.0 and active exploits are widely available in the wild, making it extremely dangerous for any web application that inadvertently exposes the /vendor directory. Despite being discovered in 2017, this vulnerability continues to be actively exploited against unpatched and misconfigured systems. Organizations must immediately audit their web servers for exposed vendor directories and apply patches.
Immediate Actions:
1. Search all web servers for exposed PHPUnit eval-stdin.php files: find / -name 'eval-stdin.php' -path '*/phpunit/*' 2>/dev/null
2. Block external access to /vendor directories immediately via web server configuration (Apache .htaccess or Nginx location blocks)
3. Add WAF rules to block POST requests to */vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php
Patching Guidance:
4. Update PHPUnit to version 7.5.19+, 8.5.1+, or 9.0+ where the vulnerability is fixed
5. Remove PHPUnit and other development dependencies from production environments entirely: composer install --no-dev
6. If using composer, ensure require-dev packages are never deployed to production
Compensating Controls:
7. Configure web server to deny access to all /vendor directories: Deny from all (Apache) or return 403 (Nginx)
8. Implement network segmentation to limit web server access
9. Deploy file integrity monitoring on web application directories
Detection Rules:
10. Monitor web server access logs for requests to eval-stdin.php: grep -r 'eval-stdin' /var/log/
11. Create IDS/IPS signatures for POST requests containing '<?php' to vendor paths
12. Monitor for unexpected PHP process spawning or outbound connections from web servers
الإجراءات الفورية:
1. البحث في جميع خوادم الويب عن ملفات eval-stdin.php المكشوفة في PHPUnit: find / -name 'eval-stdin.php' -path '*/phpunit/*' 2>/dev/null
2. حظر الوصول الخارجي إلى مجلدات /vendor فوراً عبر تهيئة خادم الويب (Apache .htaccess أو Nginx location blocks)
3. إضافة قواعد WAF لحظر طلبات POST إلى */vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php
إرشادات التصحيح:
4. تحديث PHPUnit إلى الإصدار 7.5.19+ أو 8.5.1+ أو 9.0+ حيث تم إصلاح الثغرة
5. إزالة PHPUnit وجميع تبعيات التطوير من بيئات الإنتاج نهائياً: composer install --no-dev
6. التأكد من عدم نشر حزم require-dev على بيئات الإنتاج
الضوابط التعويضية:
7. تهيئة خادم الويب لرفض الوصول إلى جميع مجلدات /vendor
8. تطبيق تجزئة الشبكة للحد من الوصول إلى خادم الويب
9. نشر مراقبة سلامة الملفات على مجلدات تطبيقات الويب
قواعد الكشف:
10. مراقبة سجلات وصول خادم الويب بحثاً عن طلبات إلى eval-stdin.php
11. إنشاء توقيعات IDS/IPS لطلبات POST التي تحتوي على '<?php' إلى مسارات vendor
12. مراقبة عمليات PHP غير المتوقعة أو الاتصالات الصادرة من خوادم الويب