This should be a first proper version

This commit is contained in:
2019-07-02 18:04:55 +02:00
parent bcb7f00f68
commit 28fe1a971f

View File

@@ -31,6 +31,16 @@ void print_help()
cout << "The following commands are available: help, login, register, exit" << endl; cout << "The following commands are available: help, login, register, exit" << endl;
} }
void print_flag()
{
PROFILER_RECORD;
ifstream file("flag.txt");
string flag;
getline(file, flag);
cout << flag << endl;
exit(0);
}
void login() void login()
{ {
PROFILER_RECORD; PROFILER_RECORD;
@@ -38,20 +48,35 @@ void login()
string username = prompt(':'); string username = prompt(':');
cout << "Password"; cout << "Password";
string password = prompt(':'); string password = prompt(':');
uint8_t encrypted_password[16]; if (username != "admin")
{
cout << "Unknown user '" << username << "'" << endl;
return;
}
if (password.length() != 16) if (password.length() != 16)
{ {
cout << "Password format error" << endl; cout << "Password format error" << endl;
return; return;
} }
uint8_t encrypted_password[16];
for (int i = 0;i < 16;i++) for (int i = 0;i < 16;i++)
{ {
encrypted_password[i] = password[i]; encrypted_password[i] = password[i];
} }
AES::encrypt_ecb(encrypted_password, key); AES::encrypt_ecb(encrypted_password, key);
// TODO Validate encrypted password uint8_t rootpw[16] = {0xe3, 0x07, 0x2e, 0x9f, 0x5b, 0xe8, 0xed, 0xd6, 0x02, 0xab, 0x89, 0xb8, 0xeb, 0x49, 0xcc, 0x56};
for (int i = 0;i < 16;i++)
{
if (encrypted_password[i] != rootpw[i])
{
cout << "Invalid password" << endl;
return;
}
}
print_flag();
} }
#include <iomanip>
void register_user() void register_user()
{ {
PROFILER_RECORD; PROFILER_RECORD;
@@ -86,7 +111,10 @@ bool execute_command(const string &input)
{ {
profiler.reset(); profiler.reset();
} }
else
{
cout << "Invalid command '" << input << "'" << endl; cout << "Invalid command '" << input << "'" << endl;
}
return true; return true;
} }