‫Instructor: Hi, within this lecture,
‫we're going to see how data is saved
‫for our applications in Android operating system,
‫and we're going to see how we can encrypt the cryptology
‫in this application.
‫So I'm going to open my terminal
‫and we're going to use adb one more time,
‫like we have done before, okay?
‫So make sure you call adb shell
‫in order to have a shell session
‫with the current emulator over here.
‫And once it's opened,
‫you can run the commands that we have seen before,
‫like am command, remember, in order to fire an intent.
‫Rather than am, I'm gonna go for ls,
‫which will give us to actually opportunity
‫to browse the data inside of our Android device.
‫So right now, I can go over to the data folder
‫where I can find another data folder.
‫As you can see, there are a lot of folders
‫in our data folder.
‫So Android operating system saves a lot
‫of data, as you might guess,
‫but this app-specific data is stored
‫under the data folder under data folder.
‫So you're gonna have to go for data, data.
‫And as you can see, if you run ls -la,
‫it will give you a look like this
‫and you can see the folders with a list.
‫So if you go over here to data
‫by typing cd data,
‫now you're inside of the folder
‫where you can find the application's data.
‫So if you run ls like this,
‫you will see all the folders
‫that are available to you
‫and these are all my applications running
‫on my emulator
‫and all the data that are actually saved
‫by those applications.
‫So if we just browse into our own application,
‫which is insecure banking,
‫I can run ls
‫and I can see the databases like that, right?
‫So I have three folders over here like cache,
‫code_cache, and databases.
‫So let me run this it this way
‫so that we can see it in a clear way.
‫So cache, code_cache and databases.
‫Over here, we generally have sharedPreferences.
‫I'm gonna show you what it is.
‫Let me go to databases
‫and as you can see, I have some databases over here.
‫So there isn't much to see in the databases folder right now
‫because we don't, I believe,
‫have kind of an SQLite thing going on here
‫but we're gonna have to look for sharedPreferences as well.
‫So sharedPreferences is a simple database
‫or a database-like object
‫that we can store simply values.
‫Like if you want to store the username
‫or if you want to store like a score of a game
‫or a high score of a game in your database,
‫you don't have to use a big structure like SQL or SQL.
‫And you can actually use sharedPreferences for that purpose.
‫For example, if I come over here
‫and log in with a standard user like this,
‫and I'm gonna have to give my server IP again.
‫Click Submit and log in.
‫Okay, now most probably, it will store some data
‫in the sharedPreferences.
‫It's very useful tool.
‫We use it a lot in the Android development.
‫And once I do that, it's actually being saved
‫in this folder, in this very folder, cd/data/data
‫package name and under over here,
‫we're gonna have to see some sharedPreferences thing.
‫So maybe if you actually browse into this sharedPreferences,
‫so if you run ls, now we see the sharedPreferences folder,
‫as you can see, okay?
‫It hasn't been created before for me.
‫Now I see this.
‫So most probably,
‫it actually saved the username and password.
‫So let me try to find the username and password.
‫So there is an XML over here.
‫So SharedPreferences is stored in the XML file.
‫Okay?
‫And if we want to have a look at to this XML file,
‫let me try if we have nano over here.
‫So there isn't any nano.
‫Yeah, nano is a text editor
‫but I believe I don't have it on my Mac.
‫So let's try vim.
‫And yeah, I believe we don't have vim.
‫So it's another text editor
‫and I don't have it either.
‫So let's just do cat.
‫Cat mySharedPreferences.xml.
‫And yeah, here you go, we see the content.
‫As you can see, I can see the username and password,
‫but they're actually encrypted.
‫So there are two things to learn in this lecture.
‫First, we have learnt how to see the data
‫that is stored by our own application
‫so that you can gather information
‫about your application and how it works,
‫and what kind of data it stores.
‫And the second thing that we're going to learn
‫is to how to look for encryptions
‫and how to try and decrypt them.
‫So as you can see,
‫it actually does a good job encrypting the data
‫so that it cannot be seen by other applications
‫or the user itself.
‫So it's encrypted over here.
‫However, we can always try to decrypt it.
‫So as you can see, this is the data
‫and it looks like a standard encryption.
‫It looks like an AES-256 encryption
‫because it ends with these two equal signs most of the time.
‫However, I'm not very sure of it,
‫so I'm going to have a look at JDX.
‫Okay, even if I'm sure of it,
‫it isn't a very easy thing to decrypt that kind of thing.
‫So I'm gonna go over to CryptoClass
‫because that's where it's going to be most probably, right?
‫So I'm going to have a look at
‫and I will see that it's actually indeed
‫an AES-256 encryption.
‫And the actual developer is doing a good job
‫to encrypt those values
‫when they store it in the sharedPreferences.
‫However, if we come over here,
‫we can see all the source code,
‫which is not very good for the developer.
‫For example, we see the encrypt method
‫and we see the decrypt method over here.
‫And we see this key
‫and it says that this is the super secret key 123.
‫So the thing about the AES encryption
‫is that we have to give a key
‫and it uses that key
‫in order to create an encryption algorithm
‫or encryption mechanism.
‫Okay, and if we have that key,
‫it would be very easy for us to decrypt it as well.
‫So since we can actually see the key over here,
‫we can try to decrypt the values.
‫So in order to do that,
‫we can just use an online tool.
‫We don't have to open Kali Linux for that reason only.
‫So I'm gonna search for Decrypt AES-256 with key online.
‫And it will take me to some online service most probably.
‫There are a lot of online services for this,
‫like one million results over here.
‫And I'm just gonna go for the first one.
‫You can choose another one if you want.
‫And as you can see,
‫it also does encryption
‫but we're interested in the decryption side of this.
‫So let me just copy and paste the values
‫and try to find the related specifications
‫over here like the input.
‫So let me just come over here
‫and just copy this.
‫I know that this ends with two equal signs
‫but in real time, if you don't know,
‫you can just take the whole thing
‫and try with that as well.
‫So I'm gonna do that.
‫I'm going to take the whole things over here
‫and if it doesn't work,
‫I'm just going to change it a little bit.
‫I'm going to paste it.
‫And let's see if this will cause any problem.
‫So over here, for the mode,
‫we're gonna go for CBC as we can see over here.
‫So it's AES, CBC and it's 256.
‫And we have to give a secret key.
‫So this is why this is not secure.
‫Since we can get this key over here,
‫we can actually decrypt it.
‫If we couldn't have that,
‫it would be very actually hard for us to do.
‫So as you can see,
‫we have already decrypted it.
‫We can see the username,
‫like the #@123$.
‫So let me try to just delete this and try one more time.
‫Yeah, as you can see,
‫we still get the same result over here.
‫So I believe the things at the end
‫are very not very vital to the encryption itself.
‫But eventually, we get the username.
‫So as you can see, if we try to dig deeper,
‫if you try to understand every code
‫in the application.
‫We can find some vulnerabilities.
‫And we can gather much more data using those vulnerabilities
‫and we can eventually hack into the application
‫using different techniques.
‫So if you're gonna use AES encryption,
‫make sure that you don't just give the key over here.
‫Try to encrypt it
‫or try to get it from the server itself
‫so that users won't be able to see it,
‫and they won't be able to hack it anyway.
‫So here you go, that's it, it's it for this lecture.
‫We're going to stop here
‫and within the next lecture,
‫we're going to have a look at another vulnerability.