Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Parameter injection in .exe (C++)

The parameters injection at the end of the file is very useful, for example, in trojans creation like keyloggers or rats.
We create two projects (I'm in Visual Studio), one for the stub and the other one for the builder. The builder will inject the parameters into the stub, and the stub will read the injected message from the builder.

Stub source code:
Code
#include <fstream>
#include <iostream>
#include <Windows.h>

using namespace std;

#define STUB_SIZE 232448 //Compiled stub size

struct Configuration {
    int port;
    char ip[16];
};

int main(){
    Configuration data;
    char filename[256];
    GetModuleFileNameA(NULL, filename, 256);
    ifstream file(filename, ios::binary);
    file.seekg(STUB_SIZE);
    file.read((char*)&data, sizeof(Settings));
    file.close();
    cout << data.ip << endl;
    cout << data.port << endl;
    return 0;
}

Builder source code:
Code
#include <fstream>
#include <iostream>
#include <Windows.h>

using namespace std;

#define STUB_NAME "Stub.exe"

struct Configuration {
    int port;
    char ip[16];
    char built[32];
};

int main(){
    Configuration data;
    cout << endl << "Ip: ";
    cin >> data.ip;
    cout << endl << "Port: ";
    cin >> data.port;
    cout << endl << "Built name: ";
    cin >> data.built;
    ifstream file(STUB_NAME, ios::binary);
    ofstream built(data.built, ios::binary);
    built << file.rdbuf();
    file.close();
    built.write((char*)&data, sizeof(Configuration));
    built.close();
    return 0;
}

Then we compile the two projects and run the builder and introduce the parameters.
We execute the new .exe generated by the builder and it should show us the parameters that we had injected by the builder.
The more common method on Windows at least legitimately is to use the Resources API. Another would by to allocate a new section in the PE headers, then read and write to that section.
Thanks, I will look at it.
Greetings.
(Jun 5, 2022 07:18 PM)yuumi Wrote:  The more common method on Windows at least legitimately is to use the Resources API. Another would by to allocate a new section in the PE headers, then read and write to that section.

that should be the next step for you OP
#c/c++# & #asm#  


The way to patch bad code is to remove the bad code, not to add new bad code that hides the old bad code 
this method called EOF (end of file) theres betters methods to use in malware
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Lor‌dJul 7, 2020 12:52 PM 19 410 Jul 7, 2020 12:52 PM
Last Post: n0$f3ratu$
[C] by HiddenEyEJul 24, 2018 03:20 AM 3 233 Jul 24, 2018 03:20 AM
Last Post: HiddenEyE
[C#] by SilentkillarHFJan 24, 2018 12:51 PM 1 131 Jan 24, 2018 12:51 PM
Last Post: Dotexe