Welcome back, guys.
This will be now an speedrun regarding to the AZ crypto function.
So here we will do the solution.
We will print out those parameters, the initialization vector, the secret key and also the return
value.
And then we will use this information to encrypt and decrypt the text to see if everything is working
properly.
All right, let's do this.
Okay, so back to the Ubuntu VM.
Let's have a look.
And the application is within as one challenge to recap all.
And now let's make a solution directory and let's let's move this application into solution.
All right.
And then let's have a look with the trade.
Excuse me once again.
All right.
So we've got let's see.
Com app hacking as a as crypto.
Yes.
So we've got the method encrypt message and you want to get this plaintext parameter, this key.
So we have to insert the code key, get encoded to get out the key and then initialization vector and
ciphertext.
All right, let's do this.
So we we could do this on our own.
But I mean, it's way faster to do this in Android studio and then compile this application.
So we write our code in there, compile this application and simply have look into this Marley path.
So tools, Android, Studio Bin and then bash Studio Dot Assange.
Okay.
So here we have an old project.
This is our our smiley support the hard way.
This was an it was an amazing job.
We did well now.
But now we we can close this.
So it's not longer required right now.
Okay.
If we close this, then we've got our main overview and we create now a new project, Empty Activity,
and let's call it a as in solution helper.
All right.
We have to wait until the great bill has been finished.
We can observe this over here, and I will see you in just a moment.
All right.
The great bill has been finished.
So now let's create a new class.
Right click, new Java class as.
Okay, so we create a method.
Public void.
Encrypt message.
So we want to have.
Maybe let's code.
Let's get the first part over here.
In this part.
All right, so let's hit enter.
So we are importing those classes and let's add this as exception signature.
Okay, so now our code contains no key dot get encoded.
Okay.
And then, let's see.
We also want to have this base64 system out approach in here.
So we have to assign this to to invite array
my array, let's assign this and then we want to print it out and we can do it in the following way.
Our system got out print line and we call base64 encode two string and then my array.
Yes.
Oh, the flags are missing.
There we go.
Yes.
So this should work?
Yes.
This is perfectly fine right now.
So we take this line also to to print out those parameters over here and also to get the initialization
vector and also the return value.
But this is our important line.
And this is our this is the line we are going to copy, paste into the necessary parts and simply just
adjust those parameters.
Yes.
So let's call this method in the main activity.
So here we have to create a new as instance.
Yes.
Equals new items.
We don't have a parameter.
And now we can call as dot encrypt message.
All right.
And enter to surround it with try and catch and let's see if this works.
So we run this application.
Our smartphone is not being connected and therefore the emulator starts.
I do not want to wait until this this emulator has been booted up.
So let's put the smartphone in.
Okay.
Here we have the smartphone because this is a speedrun and we do not want to waste two or 3 minutes
on the emulator.
All right, Logcat let's see the system out there.
We have it perfect.
We can also make some adjustments maybe that this one over here is let's say this is the key.
Okay.
Yes.
Perfect.
This looks absolutely perfect right now.
So let's build this application.
Then we've got our initial code path and we can modify this in any way, in any way we like.
So we click locate every K to any.
We decoding this application and then we are having a look into this with Visual Studio code.
So code app debug.
Yes.
I trust the other.
Smiley come up hacking a smiley.
There we go.
Let's enable Java
and let's see our code got a little bit blown up right now.
So this is our code right now, but I guess it's okay.
To get encoded.
We also need to include this one over here.
So we start at line 22 and begin.
And this one over here is the end.
All righty.
Yes.
So let's take this part and let's insert it into the original application at those points over here
at the beginning to print out this plaintext after this one, to generate this key, to print out the
key, this one, the initialization vector and ciphertext.
So this is a lot of stuff, but we can handle this easily.
So one challenge was not this one apps one challenge to recap all.
And here we have solution epic tool D as a BC.
And then let's open this a directory.
Com app hacking as crypto.
There we go.
We enabled Java and now lets see encrypt message.
So this is the first part and we have to insert it over here.
There we have it.
Okay.
In the last video we have, we have to examine this pretty intensively.
So therefore we can skip this right now.
We can remove those line numbers.
And now let's see if the transition is working.
We're having p one as our parameter OC.
So P one needs to be adjusted in our code.
Let's see where this one over here is our key.
So in v two is holding our secret key.
And then we've got this array print screen.
We print out this key.
So this is now our parameter.
Now this means the first part is not necessary right now.
Yes.
This is not required right now.
Sorry for this, because we want to print out this this parameter here.
Okay.
Here we have parameter.
Then we've got a bunch of stuff and code to string by 64.
And let's see, we need to apply this over here.
This is our encode to string our binary.
So we two.
Yes, we two needs to be replaced with p zero.
And that's all we need to do right now.
We do not have to take care about anything else because we are at the beginning of this function.
Everything else will be overwritten beside the fact that we are having two less registers.
So we need to increase this.
Let's let's go up to ten.
Then we can be sure that this works perfectly.
Okay.
This would be fine right now.
Good.
So parameter has been successfully printed out.
Normally I would go and try to build this application.
Maybe.
Let's.
Let's see if it's.
If it builds.
If it builds, then we can move on.
Otherwise, we might have to fix something.
Solution.
Yes.
All right.
It does build.
So for me, it's fine right now.
Now, let's see.
Now we are inserting after this line 21, this key we are calling this get encoded method, and then
we are also going to call this one.
So let's get into our code.
Where do we have it?
Over here.
Let's get back into the original code over here.
And now let's see.
Line 21.
Here we have it.
Okay.
And now let's see.
Secret key will be moved into V one.
And this is matching perfectly to.
We are setting up something else.
We are setting up.
We want this.
We want further being used.
Secret key.
This is fine.
Is do we have something else?
We.
Zero zero.
We are moving key generator into the zero.
How we using we zero on our own code.
No.
In not using vs zero.
So therefore we are not touching the zero and we are going to go and I guess that's it.
So the only thing we want to have look into is the spider ray.
The spider ray should be now our secret key.
Let's see.
Despite array as parameter b five.
No, that's the integer value.
Sorry, these are our flags and we choose our byte array move recent object into.
Yes, this.
This works perfectly.
So let's see.
Me too.
And this is our bite array and this one will be used over here.
Okay, this is our byte array over here.
This is.
This is perfectly fine.
Let's see where we're initializing v two over here.
So we call the method get encoded.
So V to get encoded will be assigned the spidering, the return type into our v two and we can see we
are using encode to string on our v two over here or byte array is v two and this one is also the return
value from get encoded.
Everything seems to be fine right now.
Okay, let's clear this up.
This should also work so nice.
We we already got this one.
Also this key.
Now let's have look into this initialization vector.
Maybe a quick look if it builds.
One application back.
Oh, that's the.
That's the wrong project.
Let's see.
And there we have it.
Let's go into the solution directory.
Here we have it apk to be as let's make sure that we have saved this file.
So, I mean, if you mess up registers, this might not be recognized right now, but we can see we
are not having some really bad smiley mistakes in here.
Okay.
Once again, we take our sorry, our own application code, this one copy.
And now let's have look into the initialization vector.
Here we have get initialization backdoor by the rate this will be moved into before we have to insert
our code in between.
Now we want to print out before.
So let's see.
And before, yes, this will be it will be overwritten.
So this is not working in this way right now.
Let's see.
Okay.
Let's take this part really quick to the graphic tablet and have a quick look into this one, because
here we have to make a little bit more adjustments.
Okay.
So let's see, we for this one over here, this is our byte array we want to print out.
This one can be once again ignored.
I shouldn't move this all the time into this code right now.
So this gets this gets ignored.
And then we've got my array.
So this one is the original value.
Me too.
Maybe.
Let's write this down.
We choose the original byte array value.
Then we are using string builder on before.
So we are overwriting before at this point right now.
Okay.
And then let's see, we give.
We also need to replace this one with initialization vector IV.
Then we've got string builder and here we've got encode two string and we're using this of course on
v two because v two.
Yeah, this is our original title, right.
What we can do?
I guess so.
Let's have look into this one.
So what we can do.
Let's see.
Yes.
Here's the end of our local variables.
So this means.
We could simply move this object.
In the skit initialization back the object into v two afterwards.
So then we do not have to adjust anything.
Let's first delete this part.
Also, those line numbers.
I hope I have deleted it before, but we will figure out if not.
Okay then we've got local V to write this despite the rain.
So this is now the code.
Let's see.
Our cipher object will not be used down further.
Right.
Let's see.
No.
Here's the end of our cipher.
Object B to OC.
So what we are going to do right now is the following.
We we go into our code and we have this.
Over here.
So we are moving this object into V two.
So we are overwriting the cipher instance and v two is holding our byte array.
But the cipher object, this instance over here is not longer required anymore.
We are not using it in our code right now, so therefore we can simply override this register and now
we can see this is now holding our byte array.
Let's enable this one.
So v two is holding our byte array and it was being used over here as and byte array and this is working
perfectly fine right now.
So yeah, this is the only adjustment we have to make everything else.
Let's see.
I mean, B5 has not been known to this application at all.
Therefore, this is no problem.
And here we just have to make sure that we're not overwriting an important register.
So let's get back to this one.
Here we are returning out and we are returning v three.
So at this point we are overriding with three and this would be not good.
OC Yes, so here we've got V three and we can see we are returning the three.
There's two final method, there's two final method and returned it to be three as this one over here.
And this will override our our ciphertext, which may be returned.
This is not good.
Therefore, what we are doing is in our code we are replacing B three with V six,
doing this in this way we are not overwriting B three, and then we are done at this part.
So the only thing we need to do is we need to print it out the return value over here and then we are
done.
So this part is now regarding to the initialization vector.
Let's also write it in this way, initialization vector and then let's see.
Yes, we, we only need to insert it once again.
So let's copy this part.
Let's insert it over here.
Okay.
Here we have now v six.
It's okay because we have already printed out over here system.out.println with b six and on v six.
Sorry, with v4 which is our string.
But this system out is not longer required afterwards.
Yes.
Okay.
And then let's see.
So over here.
Yes, we need to we need to adjust this part over here.
We five we need to adjust we five so we two we need to adjust the two to be three.
Yes.
This is our byte array which comes from.
Here.
So this is our ciphertext and we are not using the ciphertext in our code so we can see on the highlight
it's not being used and the only place we are using it is over here.
So we three will not be overwritten and we will use encode to string on the spider spidering and then
we are returning it.
Okay.
One last check.
Did I miss something?
Not everything looks fine for me right now, so let's see.
Okay.
It does build so a s and then this.
We zip align this, we sign this, and then we have to uninstall and screen copy.
We have to uninstall the existing version.
Little bit messy.
Well, this was the wrong one.
If you take one of the of the above line, then you're not uninstalling it.
You're just saying you do not want to have it as an suggestion.
So let's take it here and install it.
And now let's install it.
Yes, that's correct.
Because I need to install out epic.
It's test only and let's make this laptop.
Okay.
And that's it.
And we look at
let's search for system out.
So this was regarding to the last or our example to our own application.
Now let's see if this works out and the way we have patched it.
So let's see.
We are calling as in 3 to 1.
Nice.
Besides the fact that I didn't change the initialization vector at the end.
Okay, so my bet on this.
Let's clear the logcat output.
ADB loc head there.
See?
So we have to adjust this one.
Why do we have it here?
And this one is the return value.
Yes.
So here we are creating the string regarding to the return value.
All right.
This should work right now, so let's do it once again.
I will speed up the process and then you will directly jump into this.
All right, well, come back.
So let's see it.
We look at crap.
This eye system got out, and now let's start this application.
Three, two, one.
There we go.
Here we have everything.
Also, the text matches perfectly right now.
All right, now let's use those parameters in our in our cyber function to see if we can decode and
if we can encrypt and decrypt this this text right now.
So let's do this.
So we are searching for cyber chef.
And here we have this.
And now let's see.
First this hour, let's take the return value.
Let's try to decrypt this text.
So this is our encrypted text.
Okay.
So this is our input over here.
And we now say this is from base 64 and we want an ace decryption as decrypt.
So our input is raw because we are encoding.
Sorry, we are decoding this the string this by 64 string.
We can leave the output to raw.
And I do not want to have this auto back right now.
Okay, now let's see what is the key?
The key is this one over here.
Key.
The format is base64 and the initialization vector is this one over here.
The format is also base64 and this is all okay, now we should get back if we hit the back button over
here, our decrypted text, so our plaintext.
So let's see.
Back in 3 to 1.
Perfect secret one time message.
All right.
So this is freaking awesome right now.
So we could also do it, vice versa.
So, for example, we can use our our text over here and we can encrypt it with the AZ function.
So let's pause this.
This is decrypt and let's take this text and now let's see as encrypt we are having to use right now
the key is the same format base64 initialization vector C same format base64.
Our input is now raw.
It's neither raw nor hex.
So yes, the easiest way would be to base64 encode it because this is what we are doing over here.
We are decoding it.
So echo dash pn base 64.
So this is our text we want to encrypt
and our output is, let's say, raw.
Okay, let's do this in 3 to 1.
All right.
Now we've got the raw output over here.
And to make sure that this fits perfectly with our screen, we are going to base64 encoded right now.
So base64 to base64.
Okay, so what's happening is the following right now this is our text and this text will be base64
decoded.
Base64 next to this is this block over here.
Okay.
And then we've got an input role format right now.
Then we take this input and we we perform our a crypto function over here.
Here we have this key as base64 format.
Sorry, initialization vector.
Here we have the key.
And then we get this out over here.
And this is not readable for us right now.
So what we have appended is this one, and this one is now taking this part, this output, and uses
Base64 to encode those bytes.
So out of this, we will get back some some base64 string with this equal sign maybe regarding to the
padding.
Okay.
So this is what's happening right now on the cyber shelf.
Let's do this.
And therefore, all we need to do is we need to hit this back.
Button 3 to 1.
Okay.
Looks perfect.
Let's see.
Yes, this is exactly the same text.
So now we can we can modify this text in any way we like.
And, for example, we could also create a new message.
And we have it.
Echo Desh rn your de mi smiley hacking is pretty awesome.
Let's end quote this to Bay 64.
Oops.
There is something missing.
Let's see.
Awesome.
They 64.
So this is now the new text and if you click back, this would be the result on our screen.
So we can now perfectly work with this encryption decryption methods over here.
Alrighty.
Okay.
This was right now super fast, but I do not want to bother you right now with the things we have already
seen on this one, for example, over here.
I mean, regarding to string builder appending things like this, this might be new, but it's, it's
simply just Molycorp.
We have reverse engineered this whole class or this function quite a lot right now and therefore I yeah,
I did go a little bit faster through this.
The most important points are at the beginning.
Check if these parameters matches with your with your parameter in the end cultural string function,
increase those parameters because this will be definitely required if we have look into this one we
five have not been it hasn't been used before.
So we only had four five registers before the last one.
So this would, this would cause problems and then simply just take this whole code and paste it everywhere
you want to have it and have a quick look into the transition.
If this object we want is, for example, secret key, if it stays secret key, if we B0 is being used
anywhere else afterwards, we can see not that's not the case.
So we can reassign this and things like this already.
Okay.
In case if this was too fast and you want to have an long explanation on this, absolutely no problem.
Drop me a message.
I will re upload an in more extensive version on this one.
So if you feel in Russian right now, then please drop me a message because this is something we do
not want to have in our course.
We want to take our time to analyze this.
But I do not want to bother you to go through this the third or fourth time in case until, of course,
if it's required.
Alrighty.
Okay.
Perfect.
So this is the end for our one challenge to recap.
All right, now.
And in the next one, we will have the introduction to our Black Bear challenge.
And this one, this will be freaking awesome because we will combine everything we have learned so far
in this challenge.
All right.
Let's have a look.