> For the complete documentation index, see [llms.txt](https://bradsen.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bradsen.gitbook.io/docs/mobile-pentesting/androgoat.md).

# AndroGoat

## Installation and Setup

Download the latest APK file, then drag and drop it into the emulator to install it.

{% embed url="<https://github.com/satishpatnayak/AndroGoat>" %}

## Decompile APK file&#x20;

Use apktool to decode the apk file&#x20;

```
apktool d AndroGoat.apk
```

## Exported Activity Vulnerability

Open up AndroGoat folder and look for AndroidManifest.xml file. Search for exported="true"

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2Ffrx5bqkD47cTXbuJUPPj%2Funknown.png?alt=media&amp;token=f0f9709f-958d-4b89-a6f5-22f91acaa7e4" alt="" height="72" width="624">

Start remote terminal into an Android device.

```
adb shell
```

In Android, activities are usually written as:

```
<package_name>.<ActivityName>
```

Start the activity remotely. Refer to the **android:name** for the name of the acitivity.&#x20;

```
am start -n owasp.sat.agoat/.AccessControl1ViewActivity
```

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2F9urBBllS66m7Bms6MpSE%2Funknown.png?alt=media&amp;token=9fa89953-3e31-43ee-b9b4-23968b769b0b" alt="" width="563">

Expected output

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2Fkj6NmP1rSe6cKhCCodIm%2Fimage.png?alt=media&amp;token=4643a394-23d6-43ca-ad2f-0eb7bd29a8fc" alt="" width="375"><figcaption></figcaption></figure>

By right, the user needs to enter the PIN before being able to download the invoice.

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FcCZEMC3WC7QFeVn7CuTd%2Fimage.png?alt=media&amp;token=116e5889-4f88-49a8-92dd-9d317bb0a535" alt="" width="373"><figcaption></figcaption></figure>

**Impact**: Setting `exported=true` allows other applications to invoke the activity, which may lead to unauthorized access if proper permission checks are not implemented.

## Insecure application with Data Backup enabled

In AndroidManifest.xml, search for exported="true"

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2Fd9pmNh3KLQfoFDHgDaxN%2Funknown.png?alt=media&amp;token=effb46cc-8d37-4064-afe2-af1bb32496ab" alt="" width="563">

Start remote terminal into an Android device.

```
adb shell 
```

Check out the list of installed packages. Take note of the target application.

```
pm list packages
```

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FAPyHdl9eCUmIOclCBaNt%2Fimage.png?alt=media&amp;token=fc3f4009-eb83-44c5-9c6c-17490741c495" alt=""><figcaption></figcaption></figure>

Start backup

```
adb backup -apk -shared owasp.sat.agoat
```

Expected output. Choose "Back up my data"

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FToXKPws3B1ScieshVvUC%2Fimage.png?alt=media&amp;token=b68bb7fe-28f8-45b2-a67f-d42c5a4aabce" alt="" width="269"><figcaption></figcaption></figure>

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2F4SIPpQZ3qRyq0HY5Mxhf%2Fimage.png?alt=media&amp;token=ecd0127d-901c-43ba-90aa-0329744fec00" alt="" width="271"><figcaption></figcaption></figure>

Open Ubuntu (WSL), go to C drive&#x20;

```
cd /mnt/c
```

Extract an Android backup (`.ab`) file into a readable archive (`.tar`).

```
cat backup.ab | (dd bs=24 count=0 skip=1; cat) | zlib-flate -uncompress > backup_compressed.tar
```

Look for some interesting files.

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2F1XZKIwU3glyHoj3vzeSe%2Fimage.png?alt=media&amp;token=0e274a0d-257e-4c21-a697-64804b0f8555" alt=""><figcaption></figcaption></figure>

Found a sensitive file.&#x20;

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2Fju22KOr8vVGjN27aA836%2Fimage.png?alt=media&amp;token=065afe78-33d0-48ef-993b-93cba7dac059" alt=""><figcaption></figcaption></figure>

## Hardcoded credentials

After decoding, open with jadx-gui and open owasp.sat.agoat > databinding > AIChatActivity

<p align="center"><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2F2BxHZLSmxjS13GSKO9bS%2Fimage.png?alt=media&amp;token=53480407-43af-4da0-82d6-5a763b3582e0" alt=""><br></p>

<figure><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FNyahKkPvB5C8ZfB3Rt69%2Fimage.png?alt=media&amp;token=65d5ae5b-07d6-4a05-b4c8-02928feadbc1" alt=""><figcaption></figcaption></figure>

## Bypass SSL certificate pinning&#x20;

Install Objection tool

{% embed url="<https://github.com/sensepost/objection>" %}

Install Frida server

{% embed url="<https://github.com/frida/frida/releases>" %}

Choose the following

> frida-server-17.9.9-windows-x86.exe.xz

Copy the file `frida-server` from the computer to the Android device’s `/data/local/tmp/` directory.

```
adb push .\frida-server /data/local/tmp/
```

Show all installed applications on the connected Android device.

```
frida-ps -aiU
```

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2F8l1LCD9pv2d1KrojmmcH%2Funknown.png?alt=media&amp;token=73a640f0-8d1e-4234-86c6-239df54a97b1" alt="" height="63" width="624">

Verify if it is running (if the process is listed means it is running)

```
frida-ps -U
```

<p align="center"><img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FFkGXNeaL3XBldgT8Ko1f%2Fimage.png?alt=media&amp;token=876913b4-0636-489c-b492-0339a7c69277" alt=""><br></p>

Use objection to injects Frida gadget into it so that we can analyze and manipulate the app at runtime. After it is completed, it will output a app.objection.apk file. Drag it into the emulator.&#x20;

```
objection patchapk --source AndroGoat.apk
```

Start objection

```
objection -n owasp.sat.agoat start
```

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2FEQFfJnskUhRtAc8QJkbs%2Funknown.png?alt=media&amp;token=e04e3210-9070-48fb-bafb-27b5b40da22f" alt="" width="563">

Disable SSL pinning

```
android sslpinning disable
```

Expected result in Burp. Traffic has been successfully intercepted.

<img src="https://1174946829-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4K3GhEEELaFCyhvEQ0Wp%2Fuploads%2F00amxvjDQiWENIRJ3wKt%2Funknown.png?alt=media&amp;token=e089dca9-4b69-4deb-9c6e-4ac08869c1b3" alt="" width="563">
