Hello and welcome back.
In this video we are going to try C4.
So let's run it first and see what it does.
Right-click here and open terminal.
And then type C4 without any parameters.
So it asks you to provide the secret password.
So now we will provide a password.
Three A's.
And it says, "Come on now.
You should expect better from us."
So let's give it a longer password, maybe five A's or more.
Still not long enough.
So let's give even longer password.
And now we know that it is quite a long password,
more than five characters.
But it's still a wrong password.
So if you want to give this a try, please pause the video first.
All right.
So this is how I will solve it.
I will load this into, import this into Ghidra.
Sorry, C4.
It's an ELF file,
64-bit.
Okay.
Drag it to the code browser to start the analysis process.
Click on
Yes.
And click on Analyze.
Watch the lower right and it has finished analyzing.
So let's go to the Functions folder and look for the main function and click on it.
This is the main function, but with the wrong signature.
So let us edit it.
Change the first parameter to argc and the second one
to char star star argv.
Now you will see it expects at least one parameter,
is exactly one parameter.
So when we supply no parameter, this test failed because argc is one, and it showed this message
from here.
And if we supply one parameter, then argc is exactly two.
And so it went in here and extracted the length of our password.
Argv[1] is referring to this password.
iVar2, that means iVar2 is the length, so let's rename it.
And then now we see if the length is less than ten, then it will show this bad message, which is this
one,
"Come on now," and so on.
So this suggests that the length of the password is ten characters or more.
So if we supply ten characters now,
one, two, three, four, five, six, seven, eight, nine, ten, it will say "wrong password" because
of this "wrong password."
So in here it's going to do a while loop, and it's going to use a variable.
In this variable,
local_18 is set to zero before it enters the while loop, and this variable, click on it,
it will highlight all the places where it is being used.
And if you look down here, we can see that this variable is incremented by one at the end of the loop,
and then it goes back up here to check again.
If it's less than the length, then it will continue to loop.
And inside the loop, the first line does is it checks whether this array element
plus two is not equal to this array element which you entered from the password.
So this suggests that local_18 is an array index.
So we can rename it.
Array index.
An array index is the way in which you access each of the characters in the string.
So for example, here, "hexadecimal" is a string.
So in C programming, you can create a string like this.
And then to access each of the array elements, you can do,
for example, you can give a name.
You can do things like this.
String[0] is referring to character 'H', and then string[1] is referring to character 'A', and so on.
You can also do things like this.
String zero.
So string[0] is also referring to character 'H', and that is what you are seeing here.
Array index.
So array index when it first enters the loop is zero.
So because it is zero, it is comparing 'H' with something.
But before it does that, it plus two.
So it is actually taking 'H' and incrementing it by two.
So 'H' becomes 'J'.
Remember, it is ASCII code.
If you go to the ASCII tables and look at 'H',
'H' is 104.
If you plus two, it becomes 106, which is 'J'.
It's the same way.
If you are comparing one, that means you're taking 'A' and plus two.
As you can see,
so 'A' plus two is just 'C', then 'C' plus two is 'E', 'K' plus two is 'M', 'A' plus two is 'C', 'D' plus two is 'F',
'A' plus two is 'C', 'Y' plus two.
What is 'Y' plus two?
If you compare the character 'Y' in the ASCII table and look for its ASCII code, it is 121.
When you plus two, it becomes 123, which is a left curly brace, this character.
Similarly, what is dash plus two?
Dash plus two is, this dash plus two gives you forward slash.
And finally, 'U' plus two is 'W'.
So this algorithm, algorithm is a method of solution to solve a problem.
So this algorithm is actually taking every character of this string and converting it, shifting it
by two.
So actually the string would actually become "JcemKfC{/W".
Curly brace, forward slash, W.
So this is the password.
So it is merely comparing every character with your password that you enter.
The moment it finds any character which is wrong, it will say "wrong password."
It will not proceed with the rest of the loop.
So this is what this loop is doing.
This argument one, argv[1], is your password that you enter.
So the array index here is also accessing every character of the password which you entered.
So this is how it works.
So let us try this and see if it's correct.
So let us open this and type in the password, which is C4.
C4.
J
C
E
M
K F C
Left bracket,
forward slash, and W.
Correct.
You entered the right password.
So this is how you solve this challenge.
This challenge requires you to understand array indexing.
Array indexing.
How you access each of the elements of a string using its index.
So once you understand this, you can understand this line of code.
It also requires you to understand ASCII code, which we have covered in the previous lesson.
So that's how we solve it.
Thank you for watching.
I'll see you in the next one.