Reverse Analysis under Linux - A First Look

Dive into the intricacies of reverse analysis on Linux with fairycn, mastering tools like gcc, edb-debugger, and ghidra in UOS Home Edition 21.3, while delving into command parsing, debugging, and decompilation techniques.

Reverse Analysis under Linux - A First Look
Jose Elgueta, a graphic designer, is deeply devoted to the arts of painting, illustration, and muralism. Continuously striving to hone his graphic and artistic expressions, he possesses a profound fascination with Latin-American shamanic themes. Through his journey, he has crafted a unique visual language, unveiling a world of forms and colors yet to be discovered by others.

Environment Information


System information: UOS Home Edition 21.3

Tools involved: gcc, edb-debugger, ghidra, radare2
Note: This is a translation of the article previously written into English version, if you cannot see the message, I will provide a better translation in this article.

edb-debugger installation
# Install the required dependencies for the build // Set developer mode to enable root privileges.
apt-get install git
apt-get install pkg-config
apt-get install cmake
apt-get install build-essential
apt-get install libboost-dev
apt-get install libqt5xmlpatterns5-dev
apt-get install qtbase5-dev
apt-get install qt5-default
apt-get install libgraphviz-dev
apt-get install libqt5svg5-dev
apt-get install libcapstone-dev
 
# Build and run // only intend to run edb-debugger in the build directory
git clone --recursive https://github.com/eteran/edb-debugger.git
cd edb-debugger
mkdir build
cd build
cmake ..
make
./edb
# All users install in the system
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ ..
make
make install
edb

Test code test.c
C:

#include <stdio.h>
#include <stdlib.h>
#include <sys/ptrace.h>
 
 
void main() {
    puts("test");
}
1664014798673.png


Basic information
You can use r2 -A . /helllo to open the file to be analyzed Parsing the command: Run the "aaa" command to analyze all referenced code

1664014825502.png


it //command parsing: calculate file hash information

1664014844053.png


iI //Command parsing: Display file binary information

1664014865632.png


ii //Command parsing: Display file import information

1664014889294.png


iz // command parsing: list the strings in the data segment

1664014912881.png


iE // Command resolution: Export (global symbols)

1664014934761.png


afl // Command resolution:Show functions

1664016050377.png


s main //jump to main function address Command Explanation: To move in the file we are checking, we need to change the offset with the s command.
px hex view
pdf disassembly

1664016073649.png


or use the pdf@main command to view //@ specify the function name

1664016094210.png


Or use agf to view the basic function view

1664016132770.png


View hex information for crucial addresses

1664016194046.png


Note: If you can't enter the command, you can enter the v command to enter the graphical operation interface.
Debugging

  • Run after loading

edb open the generated hello file and detect the function entry point to automatically pause
See the crucial code address - 0x402004

1664016321903.png

  • Jump to the corresponding address

Right click in the disassembly area and select Goto Expression... Enter the corresponding address

1664016370706.png


Right click to edit

1664017526857.png


See this area corresponding to te

1664017544529.png


The next line corresponds to st

1664017559672.png


Binary edit string to modify te to fe

1664017577877.png


Return to see the corresponding data has changed // Right click Goto Rip to return

1664017593121.png


Output Verification

1664017614373.png


Decompile check
Use Ghidra to load the hello file, find the main function in the Symbol Tree module's Functios folder, and click into it

The decompiled pseudo-code is found to be error-free and readable in crucial locations compared to the actual code

1664018761429.png


Modify file
Note: It is recommended to make a backup of the original files involved before modifying

Write mode for analysis

1664018798729.png


crucial code data corresponding address information: 0x402004

1664018813444.png


check address citations

1664018841641.png


Original

1664018858757.png


Modification

1664018876675.png


Testing

1664018930861.png


This is the end of the preliminary exploration section, we will meet again if we have the chance