Modules / M1

FieldEmbedded systemsDelivered, surveyed

Binary reverse engineering

The topic

Binary reverse engineering recovers what a program does from the machine code when the C source is not available. Many embedded devices ship as a firmware binary only.

Where it belongs

Course: Embedded systems. At KU this was EECS 388.
Teach this after: compilation, the instruction set, addressing modes, and the difference between code memory and data memory. The last question also uses the stack pointer.

Files and how to use them

Use the two slide decks as the class lectures. Then assign the homework and the binary. Older lecture recordings are not posted here.

  • Lecture, part 1. Use in class before anyone opens the binary. Motivation, the 8051 instruction set and registers, and a Keil walkthrough.
  • Lecture, part 2. Use in class after part 1 and still before the homework. The memory map, addressing modes, and the disassembly and memory windows.
  • Homework handout. The graded assignment. Spring 2024 scored it at two points. Hand it out after both lectures.
  • unknown-1. The binary named in the handout. Students load it in Keil. Keep the source out of the student bundle.

Video lectures

These are links, not files stored with the module. Play one in class, or send the link to students.

Further reading

Optional papers for the instructor, or for a student who wants to read past the assignment.

  • Rostami, Koushanfar, and Karri, “A Primer on Hardware Security: Models, Methods, and Metrics,” Proceedings of the IEEE, vol. 102, no. 8, pp. 1283–1295, 2014.
  • Azriel, Speith, Albartus, Ginosar, Shamir, and Paar, “A Survey of Algorithmic Methods in IC Reverse Engineering,” Journal of Cryptographic Engineering, vol. 11, pp. 299–315, 2021. Chip imaging and netlist recovery. This module stops at a firmware binary.

The exercise

The program behind the binary keeps a hospital room at a stable temperature. It reads a sensor value from external memory six times an hour, folds each sample into a running average with the previous average, compares that average with a threshold, and drives a port pin from the result. Students receive the binary and the part number, the Microchip AT89C51. They do not receive the source.

Outcome

The student recovers the sampling rate, the stored temperatures and their addresses, the threshold, and the output port, and explains what happens if the conditional jump that returns to the start of the program is replaced by a call.

The ten questions

The Spring 2024 handout, worth two points, asks the student to work only from the disassembly window.

  1. Address of the START label.
  2. Initial return address of the first call.
  3. How many times the program reads external memory.
  4. Last hour’s temperature, in decimal, before averaging.
  5. The mean temperature after averaging.
  6. The threshold, in decimal.
  7. The temperature values stored in external memory, and their locations.
  8. Which port carries the output signal.
  9. Whether that signal is actually driven from the temperatures found in memory.
  10. At C:0x034D the program returns to START with JNZ. What happens if that opcode is replaced by ACALL.

The last question is about the stack. ACALL pushes a return address. This loop never executes a return, so return addresses accumulate in internal RAM until they overwrite other data. The module stops there. It does not teach a countermeasure.

Support

This work was supported in part by the U.S. National Science Foundation (NSF) Secure and Trustworthy Cyberspace (SaTC) program under Award No. 2114157.

Any opinions, findings, and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the U.S. National Science Foundation.

The project is a collaboration of the University of Kansas, the University of Florida, and Florida International University.