Search This Blog

Monday, December 19, 2022

Beginner Reversing


Reversing is a fundamental skill that requires understanding various low level concepts, both to uncover vulnerabilities as well as reverse algorithms. Within my time learning reversing, I've had to adapt my mindset to reading various patterns that assist me when playing CTFs or when doing my own independent security research. In this blog post, I will go over basic reverse engineering concepts and the methodology of what goes into it.

When reverse engineering is basically the process of tearing down software or hardware and analyzing its functions and information so that its functionality and behaviour can be better understood. To even begin looking at reverse engineering, we have to look at the various methods that can go into reverse engineering.  

I'm not gonna go through the details of what and how a computer handles an executed program. That will be covered in a future post or a future tutorial which I will compile and go through in detail. I will go into reverse engineering a "hello world" program, compiled in x64, on my linux machine. 

Take a look at the code below:


This is a simple "hello_world" program written in C. It simply prints out "Hello World!" on the command line using the puts() function. Looking at this program, it doesn't really do much. Let's start by first compiling this code into a working executable program that we will execute on our command line as well as debug. This tutorial is compatible on a linux system. You can apply the reverse engineering knowledge to a windows machine but for the sake of compilation, it is only linux based.

Copy this code and save it as "hello_world.c". After you do this, you can then use "gcc" which is a linux based compiler which will compile C programs in the terminal. To compile your "hello_world.c" program, the command is as follows:

gcc hello_world.c -o hello_world

Now that you have compiled the program, now its time to look at the assembly code of this program.


The code above is the assembly code of the hello_world program. Okay???? so what???? Well... with languages like C and C++, the code that we actually write is not the one being executed. The code we write is actually sent to a compiler, and that compiler will then translate our code into assembly code, which is essentially the "real" code that is being ran by the processor. It will serve you will to understand how assembly code really works so you can thrive and actually succeed in reversing. 
With assembly code, there are lots of other architectures available for them. This one that you see above is x64. There are others like x86-64, x32, ARM, MIPS and others.

To begin reversing, we have to understand what Registers are:

Registers are simply locations that the processor can store memory. They're quite similar to variables. 
Below are a list of registers available in x64.

rax
rbx
rcx
rdx
rsi
rdi
r8
r9

This blog post will end there for now. In a future post, I will expound more on the different x64 registers and how they can greatly impact your reverse engineering projects and hacks.

Happy Hacking.