bool isAuthenticated = false;
bool isRoot = false;
// Define usernames and passwords
const String regularUsername = "gatitos";
const String regularPassword = "123";
const String rootPassword = "rootpassword";
// Define firmware version
const String firmwareVersion = "1.0.0";
// Define chip data information
const String chipData = "ESP32, WiFi, BLE, Dual-core";
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Welcome to ESP32 Security Challenge");
Serial.println("Please enter your username:");
}
void loop() {
if (!isAuthenticated) {
authenticate();
} else {
if (!isRoot) {
displayPrompt(regularUsername);
} else {
displayPrompt("root");
}
processCommand();
}
}
void authenticate() {
String username = readInput();
if (username.equals(regularUsername)) {
Serial.println("Please enter your password:");
String password = readInput();
if (password.equals(regularPassword)) {
isAuthenticated = true;
Serial.println("Authentication successful. You're now in user mode.");
Serial.println("You can now access the challenges. Type 'help' for available commands.");
} else {
Serial.println("Authentication failed. Please try again.");
}
} else {
Serial.println("Unknown username. Please try again:");
}
}
void displayPrompt(String username) {
Serial.print(username);
Serial.println("@esp32:~$ ");
}
void processCommand() {
String input = readInput();
if (!isRoot && input.equals("sudo")) {
authenticateRoot();
} else if (input.equals("help")) {
displayHelp();
} else if (input.equals("challs")) {
displayChallengesList();
} else if (input.equals("version")) {
displayFirmwareVersion();
} else if (input.equals("chipinfo")) {
Serial.println("You've selected the Crypto challenge.");
displayChipData();
} else if (input.equals("exit")) {
isAuthenticated = false;
isRoot = false;
Serial.println("Logged out. Please enter your username:");
} else {
int choice = input.toInt();
switch (choice) {
case 1:
Serial.println("You've selected the Crypto challenge.");
// Call function to handle Crypto challenge
break;
case 2:
Serial.println("You've selected the Blenrf challenge.");
Serial.println("in a smart home where everything is connected we managed to read some data with nrf you just have to ask with the right command");
Serial.println("use nrf to get the data ");
// Call function to handle Reverse Engineering challenge
break;
case 3:
Serial.println("You've selected the Web Exploitation challenge.");
// Call function to handle Web Exploitation challenge
break;
default:
Serial.println("Unknown command.");
break;
}
}
}
void displayChallengesList() {
Serial.println("Challenge Categories:");
Serial.println("1. Crypto");
Serial.println("2. Blenrf");
Serial.println("3. ");
}
void displayHelp() {
Serial.println("Available Commands:");
Serial.println("1. help - Show available commands.");
Serial.println("2. challs - List available challenges.");
Serial.println("3. version - Check firmware version.");
Serial.println("4. chipinfo - Get chip data information.");
Serial.println("5. sudo - Enter root mode.");
Serial.println("6. 1 - Select Crypto challenge.");
Serial.println("7. 2 - Select Blenrf challenge.");
Serial.println("8. 3 - Select Web Exploitation challenge.");
Serial.println("9. exit - Log out.");
}
void displayFirmwareVersion() {
Serial.print("Firmware Version: ");
Serial.println(firmwareVersion);
}
void displayChipData() {
Serial.print("Chip Data: ");
Serial.println(chipData);
}
String readInput() {
String input = "";
while (!Serial.available()) {
// Wait for input
}
input = Serial.readStringUntil('\n');
input.trim();
return input;
}
void authenticateRoot() {
Serial.println("Please enter sudo password:");
String password = readInput();
if (password.equals(rootPassword)) {
isRoot = true;
Serial.println("Authentication successful. You're now in root mode.");
} else {
Serial.println("Authentication failed. Please try again.");
}
}