This document explains how to create and solve a beginner-friendly embedded reverse engineering Capture The Flag (CTF) challenge using an Arduino Nano. The challenge teaches firmware extraction, reverse engineering with Ghidra, basic binary patching, and reflashing modified firmware.
1. Learning Objectives
· Extract firmware from an Arduino Nano
· Open and inspect firmware inside Ghidra
· Locate LED blink logic
· Identify timing and conditional instructions
· Patch firmware behavior
· Reflash modified firmware back to the board
· Recover a hidden flag
2. Hardware Requirements
· Arduino Nano (ATmega328P)
· USB cable
· LED connected to pin 13 (built-in LED also works)
· Optional ISP programmer or another Arduino board
3. Software Requirements
· Arduino IDE
· avrdude
· Ghidra
· Hex editor (optional)
4. Challenge Concept
The firmware continuously blinks an LED. The player must extract the firmware, reverse engineer the LED timing logic, modify the blink speed, reflash the patched firmware, and trigger the hidden flag.
5. Original Firmware Example
#define LED_PIN 13
int blinkDelay = 500;
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
Serial.println("SYSTEM
LOCKED");
}
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(blinkDelay);
digitalWrite(LED_PIN, LOW);
delay(blinkDelay);
if(blinkDelay == 100) {
Serial.println("FLAG{patched_the_firmware}");
while(1);
}
}
6. Challenge Behavior
· The LED blinks slowly at startup.
· The hidden flag only appears if blinkDelay becomes 100.
· Players do not initially know this condition exists.
· The firmware must be analyzed and patched.
7. Exporting the Firmware
1. Compile the Arduino sketch.
2. Locate the generated .hex firmware file.
3. Alternatively extract firmware using avrdude.
4. Save the firmware image for analysis.
avrdude -c arduino -p m328p -P COM3 -b 115200 -U flash:r:firmware.hex:i
8. Opening Firmware in Ghidra
5. Create a new Ghidra project.
6. Import the firmware HEX file.
7. Select AVR 8-bit architecture.
8. Run automatic analysis.
9. Inspect functions and strings.
9. Reverse Engineering Process
Step 1 — Locate Strings
Search for the string "SYSTEM LOCKED". This usually helps identify the main firmware logic.
Step 2 — Find LED Logic
Locate references to digitalWrite and delay functions. The delay value controls blink speed.
Step 3 — Identify the Condition
Inspect comparisons involving the blinkDelay variable. The firmware checks whether blinkDelay equals 100.
10. Beginner-Friendly Patching Methods
Method A — Modify the Delay Value
Players can patch the delay value from 500 to 100. This causes the LED to blink faster and triggers the hidden flag.
Method B — Patch the Conditional Jump
Instead of changing the delay, players can modify the comparison logic so the flag is always revealed.
11. Why Changing LED Speed Is Better Than Turning It Off
· The player gets visible physical feedback.
· Behavioral changes are easier to notice.
· It feels more realistic and interactive.
· Players can visually confirm their patch worked.
· It teaches timing analysis instead of only bypass logic.
12. Reflashing the Patched Firmware
10. Export the modified binary.
11. Use avrdude to upload the patched firmware.
12. Restart the Arduino Nano.
13. Observe the faster LED blinking.
14. Open the serial monitor to recover the flag.
avrdude -c arduino -p m328p -P COM3 -b 115200 -U flash:w:patched.hex
13. Expected Final Result
· LED blink speed changes from slow to fast.
· Serial monitor displays the hidden flag.
· Player successfully completes the challenge.
14. Additional Beginner Challenge Ideas
· Unlock hidden serial commands
· Extract EEPROM secrets
· Patch login attempt counters
· Reverse XOR-encoded flags
· Modify buzzer frequencies
· Enable hidden debug menus
15. Safety and Ethics
This project is intended for education and laboratory practice only. Use isolated hardware that you own or are authorized to analyze.
16. Conclusion
This challenge introduces real embedded reverse engineering concepts in a beginner-friendly way. Using an Arduino Nano keeps the firmware small and understandable while still teaching important concepts such as firmware extraction, analysis, binary patching, and reflashing.