All right, guys may come back.
This is the final video in our installation process.
It depends on how much I'm talking, because I might have to split it up into two parts.
But after this video, we will receive our first pet.
And after all the patients, you absolutely deserve this.
So in this video, we finally want to talk about the Android Debug Bridge because this is maybe the
most important command line interface we are facing during this course.
All righty.
So let's have a look how it works and what we can do with this one.
All right, let's go.
Okay, so here we are having our smartphone and the laptop and the Android debug bridge itself consists
of three components.
I mean, it's not related that you know how the Android Patch Bridge works, but if you're using a tool,
I would like to have, at least in basic understanding, what's going on over there.
Okay.
So therefore, I would like to give you a really short introduction into the inner working right now.
So the first component is our ADB server and this one is running on our Ubuntu VM on the local host
on 5037 SD four.
So this has been already being installed during our installation process of the Android studio and setting
up the SDK.
If the server is not running, it will be automatically started when we are triggering and command,
for example, the ADB Shell command.
Alrighty.
Okay.
Next we've got the ADB daemon and this is in service running on the device.
Once again, we do not have to set up anything.
This is being done by the manufacturer and your operating system.
So this daemon is is running as default on your device, the ADB service handling the connection to
the device or also to an emulator or this virtual machine.
It could be one connection to another device or it could be also several connections.
For example, if you also have enabled or started an emulator and in virtual machine, the last component
is our ADB binary.
So the binary which is within the SDK directory.
And now if we start in this ADB binary and we are calling in command, for example, ADB Shell, this
one will make the connection to the ADB server and forwards this command to the ADB server.
The protocol, by the way, the ADB protocol is simply just in text based protocol so we can sniff this
and I guess we will also do this later on.
Yes, we will have a quick look into this one.
I mean, it's nice to see, but we we do not get much value out of this.
Okay.
All right.
So back to this one.
The ADB client has sent this command to the server.
The ADB server is then handling the connection to the device, for example, this device.
So it sends it there.
The device is executing this command and replies back this response to the server which forwards it
back to the client where it gets displayed.
In our case we're having an ADB shell running afterwards.
So this is the android debug bridge, their components and the inner working.
In a nutshell, I guess this is all we need to know right now.
Once again, we do not have to worry about installing something or setting it up.
It has been already been installed.
All right.
Next, I would like to talk about the connections to those devices, because this can be sometimes a
little bit tricky.
The easiest way to get in connection is using a device, plugging it in via USB and then executing ADB
shell.
Afterwards we get our prompt and we are good to go.
Perfect.
This also works for the emulator, so let's say it's using an emulated use V interface in there.
The point where it's getting problematic is if we're having multiple devices.
So if you have an emulator and re device being connected to the same system and we are triggering and
command, for example, ADB Shell, then the command or the ADB server does not know which device we
are targeting.
I mean, even I wouldn't know which device I would like to target.
I have to tell this to ADB and this can be easily done with the serial number so we can get the serial
number by running ADB devices.
This will fetch those serial numbers and then we can simply use the serial number to address this device.
So if we are having multiple devices connected, we need to call ADB as the serial number and then the
command we want to execute if we are getting the order wrong, for example, ADB, Shell and then the
serial number, we are getting an error in there so we have to take care about the order.
Last but not least, there's one connection type which is also possible and this is TCP IP.
So for example, on a device via wi fi or also if are using an virtual machine, not the emulator.
If we are using the Android x86 virtual machine, then we need to use the TCP IP connection.
And this is also not that hard.
So the thing we need is simply just the IP address of this device and then we can use ADB Connect and
entering the IP address.
So this will make the connection, the ADB connection based on TCP IP.
Okay.
And I would also claim that these are all use cases we could require right now.
So at this point, I mean, it seems like we have done so.
We know how the IP is working and how we can make a connection to this device.
But.
The app.
The Android package is capable of more and there are some really nice topic which I also want to include,
which is port forwarding.
So let's also dip into this topic right now.
So port forwarding comes super handy if you want to access a certain port on this device.
Let's assume we've got the device and we've got mobile application running on this device.
This mobile application is opening in port.
And for example, this one here, 31,515.
450.
This way.
My my counting is not that good.
So.
31,515.
Yes, this way.
Okay.
If you now want to connect to this port, it won't be possible because this port is only available on
the local interface of this device.
So if you try to connect to this port from our Ubuntu VM, then we're getting denied this port is not
available for us.
And this is the point where ADB forwarding comes super handy.
So let's say we've got the following use case.
We've got an application which performs some analysis on this device.
For example, draws on the rows as such and framework, which assists us in analysing mobile applications
and browser consists of two components an application which is running on the device and also in client
interface, which is running on our Ubuntu VM.
Right now.
We do not have the possibility to exchange those information, so browsers not able to connect to this
application to this certain port right now because it's just listening on the local interface to enable
this port to be accessible from our Ubuntu VM.
We could use the ADB Forward Command in the following way.
So by typing in ADB for what?
TCP 1337 TCP 31,415.
We are using the existing ADB connection to this device to make this port accessible.
So the command would do the following.
It would enable and port on our ubuntu VM.
So on local host the port one, three, three, seven and all the packages we are sending through this
port would be forwarded to the port 31,515 on the device.
By having this set up, it enables us to talk to this port, even if it's not generally open to the
outside world.
So we are enabling some kind of local proxy on our Ubuntu VM which has the ability to to talk to this
port.
And by having it in this way, we can now intact within the service on the device which is normally
not being exposed.
So this is pretty awesome.
And I mean we also required this during this course when we talk about roles of for example or generally
speaking, if you want to have an port accessible from the device to our local machine.
So this is the use case of ADB for what the first part is, therefore the port on the whole system.
So we've got a protocol TCP and then one, three, three, seven.
So this will be opened on the local interface.
And the second part is the port on the device where we want to forward this traffic to.
So in this case, 31,450.
Yes.
This time I counted correctly.
All right.
And then we could also have ADB reverse.
And this might be now a little bit confusing if it's not already being confusing, but if we are doing
some examples, I guess it will be more clear afterwards.
Okay, let's also dip into reverse.
So Reversibly just means the reverse process.
I mean, yes, as the name already suggests.
But what does this mean?
How does this work?
So this time we do not want to access in port on the device.
This time we want to access the port on our Ubuntu VM on our local system.
So let's say we are running a web server on the local interface on port 8080.
This web server is once again not reachable from the outside world because it has been bound to the
local host.
We can now make this port available to the smartphone based on the ADB reverse connection.
But to be honest, and this is something we are not going to use very often, so I guess I have used
it three or four times within my whole career.
So within the last eight years of Android app hacking, therefore you already get the feeling that this
one is it's not really required often, but nevertheless, let's have a dip into this one.
So now we want to make this port available on our smartphone.
And once again, we are using the existing ADB connection to this device to make this port available.
But this time it's it's in reverse connection.
So let's have a look into this one.
Okay.
If we are running ADB reverse TCP 80, TCP 88, what happens is the following.
And this time it's the reverse direction, which means if you are now accessing the local interface
on port 80 on our smartphone, then the web server will appear over here.
So ADB reverse will be used to enable and service which is running on our local system or on our ubuntu
VM to the smartphone.
So this is what.
Reverse means the enabling and service which is running on our Ubuntu VM or on our local host to the
smartphone.
If you think back or forward forwarding means, we are enabling and service on the smartphone to our
local host.
So yes, if you haven't been confused, you might be right now.
But if you're taking a look at, let's say, your reverse example, I guess the whole principle will
become clear.
Alrighty.
Okay.
And therefore, I would suggest let's have a look into and practical view into this whole topic because
theory it's it's okay but a little bit boring.
Therefore let's start playing around with this one on our point of view.
You ready for this?
Then let's switch back.