Compiled TryHackMe


1) Identify type of file, change the file permission, and execute

Here we need to use command  file "file name" to identify what the file made of 

In this example, it is ELF 64-bit

Next, we change the permission of the file to 777 with the command of chmod 777 "file name" which gives full permission for us to do anything with the file

Next, we try to execute the file with command ./"file name"

Here we can see that it prompted us with password:



2) Analyze ELF file using ghidra

Open the file in your ghidra


Scroll down until you find the "password" section.

Here we can see that there is a C code on the right which we can analyze to get our password



3) Code Analysis

#include <stdio.h>
#include <string.h>
int main(void) {
int iVar1;
char local_28[32];
fwrite("Password: ", 1, 10, stdout);
__isoc99_scanf("DoYouEven%sCTF", local_28);
iVar1 = strcmp(local_28, "__dso_handle");
if ((-1 < iVar1) && (iVar1 = strcmp(local_28, "__dso_handle"), iVar1 < 1)) {
printf("Try again!");
return 0;
}
iVar1 = strcmp(local_28, "_init");
if (iVar1 == 0) {
printf("Correct!");
} else {
printf("Try again!");
}
return 0;
}

Here the important part is this: 

__isoc99_scanf("DoYouEven%sCTF", local_28);

and

iVar1 = strcmp(local_28, "_init");


3.1) First Part

__isoc99_scanf("DoYouEven%sCTF", local_28); in this part the scanf will scan everything up until the %s

the %s means that it will scan right before a whitespace, in this case is a "space"

But, the "DoYouEven" part will not be stored in the variable, only the "%s"

this is due to how the scanf works

the "DoYouEven" act as a verifier, means that the password need to match the "DoYouEven" first.

so that the %s will be stored in the local_28

so the password pattern should be: DoYouEven<something>

and the <something> will be stored in local_28


3.2) Second Part

iVar1 = strcmp(local_28, "_init");

in this syntax, it will compare local_28 with _init, and if the password match,

it will return "correct" or else "please try again"


so from the first part, we know that <something> is stored in local_28

so in order the <something> to be equal to "_init"

We replace  <something>  with "_init" too


thus the strcmp will campare  "_init" and "_init"

and will return == 0 which is correct in the end. 



Comments

Popular posts from this blog

Data Exfiltrtation Detection (DNS, FTP, HTTP, ICMP)

Firewall, WAF, and VPN manual log Analysis using command line.

Reversing ELF TryHackMe