mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-04-01 09:00:18 +02:00
6.2 KiB
6.2 KiB
Embedded Systems Reverse Engineering
Week 1
Introduction and Overview of Embedded Reverse Engineering: Ethics, Scoping, and Basic Concepts
Non-Credit Practice Exercise 2: Find Strings in Ghidra
Objective
Learn how to locate and analyze strings in a binary, understanding where they are stored in memory and how they're used.
Prerequisites
- Ghidra installed with
0x0001_hello-worldproject open - Basic familiarity with Ghidra's interface (from Exercise 1)
- CodeBrowser window open with the binary loaded
Task Description
In this exercise, you'll find the "hello, world" string in the binary and determine:
- Where it's located in memory (its address)
- How it's used by the program
- What format it's stored in
Step-by-Step Instructions
Step 1: Open the Defined Strings Window
- In the CodeBrowser menu, go to Window (top menu bar)
- Look for and click on Defined Strings
- A new window should appear showing all strings Ghidra found in the binary
Step 2: Understand the Strings Window
The Defined Strings window shows:
- Address: The memory location where the string starts
- String: The actual text content
- Length: How many bytes the string uses
- Defined: Whether Ghidra has marked it as data
Step 3: Search for "hello, world"
- In the Defined Strings window, look through the list to find
"hello, world" - Search method: If the window has a search box at the top, you can type to filter. Otherwise, use Ctrl+F to open the search function
- Once you find it, click on it to highlight the entry
Step 4: Record the Address
When you find "hello, world", note down:
String Address: ________________
Actual String Content: ________________
String Length: ________________ bytes
Step 5: Double-Click to Navigate
- Double-click on the
"hello, world"entry in the Defined Strings window - Ghidra will automatically navigate you to that address in the CodeBrowser
- You should see the string displayed in the Listing view (center panel)
Step 6: Examine the Listing View
Now that you're at the string's location:
- Look at the Listing view (center panel) where the string is shown
- You'll see the string in hex/ASCII format
- Notice how it appears in memory - each character takes one byte
- Look for the string content:
hello, world\r\n - What comes after the string? (Ghidra may show other data nearby)
Step 7: Look at the Cross-References
To see where this string is used:
- In the Listing view where the string is displayed, right-click on the string
- Select References ? Show References to
- A dialog should appear showing which functions/instructions reference this string
- This tells you which parts of the code use this string
Step 8: Answer These Questions
Based on what you found:
Question 1: Memory Location
- What is the address of the "hello, world" string? __________
- Is it in Flash memory (starts with
0x100...) or RAM (starts with0x200...)? __________
Question 2: String Storage
- How many bytes does the string take in memory? __________
- Can you count the characters? (h-e-l-l-o-,-space-w-o-r-l-d-\r-\n)
Question 3: References
- How many times is this string referenced in the code? __________
- Which function(s) reference it? (Hint: Look at the cross-references)
Question 4: ASCII Encoding
- How is the string encoded in memory?
- Is each character one byte or more? __________
- What does
\rand\nrepresent? (Hint:\r= carriage return,\n= newline)
Expected Output
You should be able to fill in a summary like:
String Found: "hello, world\r\n"
Address: 0x________
Located in: [Flash / RAM]
Total Size: ________ bytes
Referenced by: [Function names]
Used in: [How the program uses it]
Deeper Exploration (Optional Challenge)
Challenge 1: Follow the String Usage
- From the cross-references you found, click on the instruction that uses the string
- You should navigate to the
ldr(load) instruction that loads the string's address into registerr0 - This is how the
printffunction gets the pointer to the string!
Challenge 2: Find Other Strings
- Go back to the Defined Strings window
- Look for other strings in the binary
- Are there any other text strings besides "hello, world"?
- If yes, where are they and what are they used for?
Challenge 3: Understand Little-Endian
- When Ghidra shows the string address in the
ldrinstruction, it's showing a number - Look at the raw bytes of that address value
- Notice how the bytes are stored in "backwards" order? That's little-endian!
- Can you convert the hex bytes to the actual address?
Questions for Reflection
- Why is the string stored in Flash memory? Why not in RAM?
- How does
printf()know where to find the string? (Hint: The address is loaded intor0) - What would happen if we didn't have the
\r\nat the end? How would the output look? - Could we modify this string at runtime? Why or why not?
Tips and Hints
- Strings in compiled binaries are often stored in read-only memory (Flash) to save RAM
- The
\rand\ncharacters are special: they're single bytes (0x0D and 0x0A in hex) - When you see a string in Ghidra's listing, the ASCII representation is shown on the right side
- You can scroll left/right in the Listing view to see different representations (hex, ASCII, disassembly)
Real-World Application
Understanding where strings are stored is crucial for:
- Firmware modification: Finding text messages to modify
- Reverse engineering: Understanding what a program does by finding its strings
- Vulnerability analysis: Finding format string bugs or hardcoded credentials
- Localization: Finding where text needs to be translated
Summary
By completing this exercise, you've learned:
- How to find strings in a binary using Ghidra's Defined Strings window
- How to determine the memory address of a string
- How to follow cross-references to see where strings are used
- How strings are stored in memory and referenced in code
- The relationship between C code (
printf()) and assembly (ldr)