This should be a first proper version
This commit is contained in:
34
main.cpp
34
main.cpp
@@ -31,6 +31,16 @@ void print_help()
|
||||
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()
|
||||
{
|
||||
PROFILER_RECORD;
|
||||
@@ -38,20 +48,35 @@ void login()
|
||||
string username = prompt(':');
|
||||
cout << "Password";
|
||||
string password = prompt(':');
|
||||
uint8_t encrypted_password[16];
|
||||
if (username != "admin")
|
||||
{
|
||||
cout << "Unknown user '" << username << "'" << endl;
|
||||
return;
|
||||
}
|
||||
if (password.length() != 16)
|
||||
{
|
||||
cout << "Password format error" << endl;
|
||||
return;
|
||||
}
|
||||
uint8_t encrypted_password[16];
|
||||
for (int i = 0;i < 16;i++)
|
||||
{
|
||||
encrypted_password[i] = password[i];
|
||||
}
|
||||
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()
|
||||
{
|
||||
PROFILER_RECORD;
|
||||
@@ -86,7 +111,10 @@ bool execute_command(const string &input)
|
||||
{
|
||||
profiler.reset();
|
||||
}
|
||||
cout << "Invalid command '" << input << "'" << endl;
|
||||
else
|
||||
{
|
||||
cout << "Invalid command '" << input << "'" << endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user