# Insecure Shop Application

#### Table of Content

1. #### [Starting the Solution](#id-1-starting-the-solution)
2. #### [Hardcoded Credentials](#id-2-hardcoded-credentials)
3. #### [Hooking The Login page](#id-3-hooking-the-login-page)
4. #### [Insecure Logging](#id-4-insecure-logging)
5. #### [Deep Link Exploitation using WebView](#id-5-deep-link-exploitation-using-webview)
6. #### [Deep Link Exploitation using WebView2Activity](#id-6-deep-link-exploitation-using-webview2activity)
7. #### [Editing on Smali Code](#id-7-editing-on-smali-code)

***

#### 1- Starting the Solution

First start to use the application and found logging and try to test the creds and how it's react and try some SQL payloads and still the same "Invalid username and password"

\
![](https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2Fve8aACc1xaah1bD30n1p%2Fimage.png?alt=media\&token=0f75ae66-f205-4ba1-9e10-97ac75c3ad90)![](https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FByDdKvbjtwpnUkRKVnSI%2Fimage.png?alt=media\&token=9135353b-5096-48d3-ac60-c1621c0ab868)

So i try to reverse the code using Jadx-gui to search for username and saw Boolean Function called `"verifyUserNamePassword()"` and this is the function that verify the username and the password.

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FJOI6Y6ut6iqwkAv8iIgs%2Fimage.png?alt=media&#x26;token=aeb96c85-4da1-4e5e-aa32-c3cda2d3def6" alt=""><figcaption></figcaption></figure>

***

#### 2- Hardcoded Credentials

When opening it I found a `getUserCreds()` function that have the Hardcoded creds of the login page.&#x20;

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FtpuMfBPHNJ0G396Y9g2z%2Fimage.png?alt=media&#x26;token=2dfe2776-91dd-4a5a-bb84-1f35310a801d" alt=""><figcaption></figcaption></figure>

***

#### 3- Hooking The Login page

Now i can login but if i can't found Hardcoded creds there is also another way to bypass the login by using `Frida Script` by using the Package name(`com.insecureshop.util`) , Class name(`Util`), and the required function name (`verifyUserNamePassword()`) that appear in the Util File.

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2F9D8m8GNLnbp73T6hQkwy%2Fimage.png?alt=media&#x26;token=de42c445-301f-49ab-9e8e-30f8b6d7ef4d" alt=""><figcaption></figcaption></figure>

and this is the Script That we can use\
Java.perform(function () { console.log("\[\*] Hooking InsecureShop Login Bypass");

```ruby
Java.perform(function () {
    var LoginBypass = Java.use("com.insecureshop.util.Util");
    LoginBypass.verifyUserNamePassword.implementation = function (username, password) {
        return true; 
    };

    console.log("[*] Login Bypass Hook Injected Successfully.");
});

```

and save it like `file.js`  file then run the Frida sever on the emulator and run this command to Hook on the function.\
`frida -U -l file.js -f <Package_Name>`  \
and i can login without Creds in the login page.

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FRiI07P0RKjFgc8tVDEoz%2Fimage.png?alt=media&#x26;token=3c58f5c5-98be-439f-b409-7d86b34a259d" alt=""><figcaption></figcaption></figure>

#### 4- Insecure Logging

Using `Logcat` command in the to see if the app logged the data and it logged it in local file system

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FoYw87ejFKWUASVfTaSU4%2Fimage.png?alt=media&#x26;token=be42e6f3-83c2-4ba8-9540-8c0314893a24" alt=""><figcaption></figcaption></figure>

And see it in the file using\
&#x20;`cat /data/data/com.insecureshop/shared_prefs/Prefs.xml`  and found the Creds here.

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2Fqtw9UJGah9gbbzzeHmsu%2Fimage.png?alt=media&#x26;token=2fbcf532-722a-4020-8fda-c963c6b8c2a8" alt=""><figcaption></figcaption></figure>

***

#### 5- Deep Link Exploitation using WebView

I found `WebViewActivity`here with the host `com.insecureshop` and scheme `insecureshop` with and it open it when try to access `/web OR /webview` and the parameter `url`  so the final link will be something like this:\
`insecureshop://com.insecureshop/web?url=<URL_Link>`

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FmsAhQnuxu9zpoMsQUfKd%2Fimage.png?alt=media&#x26;token=0844400a-8017-4769-a3bc-3e9cec488ea3" alt=""><figcaption></figcaption></figure>

<div align="center"><figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FyX8DhFAat1xSswoBaDI3%2Fimage.png?alt=media&#x26;token=b13841fe-c44d-4d72-ad32-2bc6aaa4af59" alt="" width="355"><figcaption></figcaption></figure></div>

So i can use ADB Activity Manager so use it like this to open google website\
\
`adb shell am start -n com.insecureshop/.WebViewActivity -d "insecureshop://com.insecureshop/web?url=http://google.com"`&#x20;

and it worked and open google in the WebView of the application

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FzXDYw3Xuh9mHWo62ri5O%2Fimage.png?alt=media&#x26;token=d460f222-95b2-463c-acb4-f314c88b7962" alt=""><figcaption></figcaption></figure>

and also i can access file data using the `file://` schema like this\
`adb shell am start -n com.insecureshop/.WebViewActivity -d "insecureshop://com.insecureshop/web?url=file:///data/data/com.insecureshop/shared_prefs/Prefs.xml"`

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2F3Mg6ZIBiyOrS7rtX84h1%2Fimage.png?alt=media&#x26;token=2c6afac9-e3cb-4ee8-befb-5080a6a1d2e2" alt=""><figcaption></figcaption></figure>

***

#### 6- Deep Link Exploitation using WebView2Activity

I found `WebView2Activity`here with the same as the previous one but without host  and scheme, so i can open any file and any link without specific schema and host:

```bash
am start -n com.insecureshop/.WebView2Activity -d "file:///data/data/com.insecureshop/shared_prefs/Prefs.xml"

file:///data/data/com.insecureshop/shared_prefs/Prefs.xml
or 
https://google.com
```

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FxwtNVrjMAJ4oCDzvM6D5%2Fimage.png?alt=media&#x26;token=6b427deb-90df-42f2-b9dd-a37ffae4679e" alt="" width="563"><figcaption></figcaption></figure>

***

#### 7- Editing on Smali Code

I open the file.apk file in `APKLab Extension` in Visual Studio Code and edit the prices that stored in the `Smali Code` and then rebuild the app again and i able to buy all items with another prices.

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FF776mHEtrqP3Y51eX3cC%2Fimage.png?alt=media&#x26;token=1103bb6b-0a98-40d5-806b-4190a403569d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2Fpz8vRD4pjwXsvskzptTE%2Fimage.png?alt=media&#x26;token=7bbf51a5-5882-4417-8a0f-3cf64e3c281e" alt=""><figcaption></figcaption></figure>

<div align="center"><figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FtHr8U9Qc9bC6nHPA8NKq%2Fimage.png?alt=media&#x26;token=1761bef5-3047-451e-bb99-ebc6e9feb2fc" alt="" width="296"><figcaption></figcaption></figure></div>

<figure><img src="https://1695281020-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBkNGOCaSbgxYLnHH6RS%2Fuploads%2FWIN2jn4j0c81kFmt1ZpG%2Fimage.png?alt=media&#x26;token=08470cd5-cc94-464f-ac04-64abe7957b13" alt="" width="296"><figcaption></figcaption></figure>
