Reverse Engineering
Reverse Engineering
Key Concepts
An ELF (Executable and Linkable Format) file is a common file format used for
executables, object code, shared libraries, and core dumps in Unix-like operating systems,
including Linux. It is a flexible and extensible format that provides a standard way to store
and execute code, making it widely used in various operating systems.
1. Header:
○ The ELF header contains metadata about the file, such as the file type
(executable, shared object, or object file), the architecture it's compiled for,
the entry point address, and the location of the program headers and section
headers.
2. Program Headers:
○ These headers describe the segments of the file that need to be loaded into
memory for execution. They contain information about the size and location
of each segment, and how it should be mapped in memory.
3. Sections:
○ Sections are logical divisions within the ELF file, each containing different
types of data. Common sections include:
■ .text: Contains the executable code.
■ .data: Contains initialized global and static variables.
■ .bss: Contains uninitialized global and static variables, which are
allocated in memory but don't take up space in the file.
■ .rodata: Contains read-only data, such as string literals.
■ .symtab and .strtab: Contain symbol tables and string tables
used for linking and debugging.
4. Section Headers:
○ The section headers describe each section's location, size, and attributes. They
are used during linking and when analyzing or debugging the file.
5. Dynamic Linking Information:
○ If the ELF file is a shared object or executable that uses dynamic linking, it
will contain a section for dynamic linking information, which includes
references to shared libraries and symbols.
6. Symbols and Relocations:
○ Symbols represent functions, variables, and other entities within the code.
Relocation entries help adjust addresses in the code when the file is loaded
into memory.
For eg: Try this Question: here (this is an ELF file) try to extract the flag from
this file.
4. Tools of the Trade:
○ Hex Editors: Allow you to view and edit the raw binary data of a file (e.g.,
HxD, Hex Fiend).
○ Disassemblers: Convert binary code into assembly language (e.g., IDA Pro,
Ghidra).
○ Debuggers: Enable you to run the program step by step, inspect memory, and
modify execution flow (e.g., GDB, OllyDbg, x64dbg).
○ Virtual Machines/Sandboxing: Isolate the environment to safely analyze
potentially malicious code.
PRACTICE QUESTIONS:
Q) A really easy one to begin with : here (Reverse engineer the provided code.)
Q) Can you figure out what is in the eax register at the end of the main function? Here (try
out GDB for this one).