- In this note there are multiple IDEs and tools to perform reversing
- Check IDA ๐ notes
Analyzing functions
- Sometimes you can find flags inside a function in plain text just by observing the Decompiler (open in
Window >> Decompiler
):
- If you find a lot of variables predefined on a function as follows:
- You can see that the first one is a
char
whereas the last one is apointer
. If we look at the dis-assembler section, we can get an idea about how these variables are added to the stack. We can clearly see a reverse order.
- The last char pointer which isย local_8ย is the first one added to the stack as follows.
- We can see that each variable is assigned a value as follows. The first char variable which isย local_2cย is assigned to โFโ and all the undefined variables are assigned hex values.
- So now, we know that these hex values should be ASCII characters because each value is exactly one byte.
- If you remember, we found that the last variable defined which is local_8, is a character pointer. Now, it is assigned to be aย hash of the stringย starting at the memory address of the variableย char local_2c, as follows.
- This means that it will hash the entire string fromย bottom of the stackย toย top. Thus, we need toย convertย each hex character assigned for the variables afterย local_2cย into ASCII characters in order to obtain the string that is being hashed.
- You can useย hex-to-ascii converterย for this purpose. You will be given the flag in ASCII.
- As you can see, there are some external functions called such asย FindResourceA()ย andย LoadStringsA(). When we look at the assembly code, we can come across that FindResourceA() is from the Kernel32 Library and LoadStringsA() is from User32 Library.
- What LoadStringsA() does is that it loads the string from its reference and stores at the variableย local_4a4.ย So, let us find the reference.
- As shown in the above entry function, we know thatย 0x110ย hex value parameter is the identifier for the string in LoadStringsA() function call.
- Hex 0x110 = Decimalย 272
- Openย Defined Stringsย from Ghidra ribbon (Window >> Defined Strings). Scroll down and you will come across a FLAG table which contains many flags.
- Take a look at the equivalent code on dis-assembler and you will find-out theย string-IDย at the far right corner in decimal. So, scroll down until you find the string-ID 272.
Using gdb when finding strcmp() function
- We are interested in the
strcmp@plt
function - Set a breakpoint at the memory address of this function and run the binary in gdb with some test input:
- The binary is executed until it hits the breakpoint as seen in the image above. Next, I can view the current state of the registers with gdb:
- Looking at the output above I can see the names of the registers, the registers value in hexadecimal format and the registers value in the format gdb thinks most appropriate (hex for pointers, decimal for the others). I can see that the general purpose registers rax and rdx have memory address values. I can use gdb to print the strings at these addresses:
Not known file architecture
- If you perform
file whatever.whatever
and gives you this:
-
unknown arch 0x3e00
means that the file has no architecture -
MSB
refers to the endianness of the file. Most significant bit first means that the most significant byte (bit) of multi-byte data is stored at the lowest memory address. This endianness is commonly used in big-endian architectures. -
SYSV
, ABI (Application Binary Interface) used in the ELF file. โSYSVโ stands for System V, which is a standard Unix ABI used in many Linux/Unix systems. -
Open the file in a hex editor like:
hexeditor
or online hexeditor and follow this trick:
- Edit the sixth bit on the code:
- Change the
02
by01
:
- Now it can be detected:
Personal advices
- If you find a code (maybe encrypted), try to reverse it because sometimes thatโs the answer :D
Searching for env variables
- In this case, you can create an
admin
environment variable and set it to 1: