It's starting to become a proper challange

This commit is contained in:
2019-06-26 14:44:06 +02:00
parent da749e84f4
commit 0c9768e065
8 changed files with 500265 additions and 46 deletions

View File

@@ -1,34 +1,87 @@
#include "aes.hpp"
#include <iostream>
#include <chrono>
#include <fstream>
#include <thread>
#include <cstring>
#include <string>
#include "profiler.hpp"
using namespace std;
using namespace std::chrono;
string prompt(char separator = '>')
{
PROFILER_RECORD;
string input;
cout << separator << ' ';
cin >> input;
if (!cin.good())
{
cout << "OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this!" << endl;
exit(1);
}
return input;
}
void print_help()
{
PROFILER_RECORD;
// TODO Verify whether there are more/less commands
cout << "The following commands are available: help, login, exit" << endl;
}
void login()
{
PROFILER_RECORD;
uint8_t key[16] = {0xA0,0x7C,0x3D,0x99,0xFA,0x00,0x02,0x46,0x97,0x33,0x73,0x50,0x31,0x7C,0xD3,0xDC}; // TODO Load me from a file
cout << "Username";
string username = prompt(':');
cout << "Password";
string password = prompt(':');
uint8_t encrypted_password[16];
if (password.length() != 16)
{
cout << "Password format error" << endl;
return;
}
for (int i = 0;i < 16;i++)
{
encrypted_password[i] = password[i];
}
AES::encrypt_ecb(encrypted_password, key);
// TODO Validate encrypted password
}
bool execute_command(const string &input)
{
PROFILER_RECORD;
if (input == "exit")
{
cout << "Thank you for visiting the Secutech customer portal. Please visit us again soon!" << endl;
return false;
}
if (input == "login")
{
login();
}
else if (input == "help")
{
print_help();
}
else if (!profiler.command_line(input))
{
cout << "Invalid command '" << input << "'" << endl;
}
return true;
}
int main(int argc, char **argv) {
//uint8_t data[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uint8_t data[16] = {0xA0,0x7C,0x3D,0x99,0xFA,0x00,0x02,0x46,0x97,0x33,0x73,0x50,0x31,0x7C,0xD3,0xDC};
//const uint8_t key[16] = {0xA0,0x7C,0x3D,0x99,0xFA,0x00,0x02,0x46,0x97,0x33,0x73,0x50,0x31,0x7C,0xD3,0xDC};
uint8_t key[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ifstream input("/dev/urandom", ios::binary);
for (int i = 0;i < 100000;i++)
PROFILER_RECORD;
cout << "Welcome to the Secutech customer portal." << endl;
cout << "How can we help you today? (type 'help' for help)" << endl;
string input;
do
{
input.read((char*) key, 16);
AES::encrypt_ecb(data, key);
for (int d = 0;d < 16;d++)
{
cout << dec << (int) key[d] << ",";
}
profiler.clear();
AES::decrypt_ecb(data, key);
cout << profiler.calls["gf_reduce"] << endl;
profiler.clear();
}
input = prompt();
} while (execute_command(input));
return 0;
}