Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. // WSExam1.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include <iostream>
  7. #include <fstream>
  8.  
  9. #include <string>
  10.  
  11. #include <openssl/conf.h>
  12. #include <openssl/evp.h>
  13. #include <openssl/err.h>
  14. #include <openssl/aes.h>
  15.  
  16. #include "DBClass.h"
  17.  
  18. using namespace std;
  19.  
  20. void bruteforce(const char* filename, char pass_to_find[5]) {
  21. unsigned char *crypted = new unsigned char[1000]; // зашифрованная строка
  22. unsigned char *plaintext = new unsigned char[1000]; // дешифрованная строка
  23. unsigned char *iv = (unsigned char *)"0123456789012345"; // рандомайзер
  24. int plaintext_len = strlen((char *)plaintext); // длина строки после обработки
  25. int len = 0; // Длина строки
  26. int cr_len = 0; // Длина шифра
  27.  
  28. fstream in_crypted(filename, ios::binary | ios::in); // файловый поток
  29. if (in_crypted.is_open()) { // открываем файл
  30. in_crypted.read((char*)crypted, 1000); // считываем шифр
  31. cr_len = in_crypted.gcount(); // получаем кол во считанных символов
  32. in_crypted.close(); // закрываем файл
  33. }
  34. else {
  35. cout << "Не удалось открыть или прочитать файл" << endl;
  36. return;
  37. }
  38.  
  39. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); // Создание структуры с настройками метода
  40.  
  41. char* password = new char[256]; // шифр
  42.  
  43. for (int a = 0; a < 10; a++) {
  44. for (int b = 0; b < 10; b++) {
  45. for (int c = 0; c < 10; c++) {
  46. for (int d = 0; d < 10; d++) {
  47.  
  48. pass_to_find[0] = a + '0'; // конвертация из int в char
  49. pass_to_find[1] = b + '0';
  50. pass_to_find[2] = c + '0';
  51. pass_to_find[3] = d + '0';
  52. pass_to_find[4] = '\0';
  53.  
  54. sprintf(password, "0000000000000000000000000000%s", pass_to_find);
  55.  
  56. EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, (unsigned char*)password, iv); // Инициализация методом AES, ключом и вектором
  57.  
  58. EVP_DecryptUpdate(ctx, plaintext, &len, crypted, cr_len); // дешифровка
  59.  
  60. plaintext_len = len;
  61. EVP_DecryptFinal_ex(ctx, (unsigned char*)plaintext + len, &len); // Финальная обработка
  62.  
  63. plaintext_len += len;
  64. plaintext[plaintext_len] = '\0'; // Обозначаем конец строки
  65.  
  66. if (plaintext[0] == '{' && plaintext[1] == '\r') {
  67. cout << "Ключ: " << password << endl << "Данные: " << plaintext << endl; // вывод в консоль
  68. return;
  69. }
  70. }
  71. }
  72. }
  73. }
  74.  
  75. EVP_CIPHER_CTX_free(ctx); // Освобождение памяти
  76. }
  77.  
  78.  
  79. int main()
  80. {
  81. setlocale(LC_ALL, "Russian");
  82.  
  83. char pass[5] = "\0";
  84. bruteforce("3_encrypted", pass);
  85.  
  86. DBClass db1;
  87.  
  88. char* password = new char[256];
  89. sprintf(password, "0000000000000000000000000000%s", pass);
  90.  
  91. db1.load("1_encrypted", password);
  92.  
  93. //db1.printAll();
  94.  
  95. system("pause");
  96.  
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement