Exploiting Debuggable Android Applications

本文展示了如何通过注入自定义代码来利用可调试的Android应用程序,包括检查应用是否可调试、设置断点、注入代码以及修改应用行为等步骤。重点在于通过远程调试在运行时修改应用的输出。

In the previous article, we have seen how to debug Java applications using a little tool called JDB. In this article, we will apply the same logic to exploit Android apps, if they are flagged as debuggable. If an application is flagged as debuggable, we can inject our own code to execute it in the context of the vulnerable application process.

Background

To make this article more interesting, I have developed a vulnerable application for demonstration purposes, which has a “button” and a “textview“.

Fill out the form below to download the code associated with this article.

InfoSec File Download

If we launch the application, it shows the message “Crack Me“.

Figure 1

If we click the button, it says “Try Again“. Now, our goal is to change the message “Try Again” to “Hacked” without modifying the application’s source code. To be precise, we have to change it at runtime.

Required Tools

  • Emulator
  • adb – Android Debug Bridge
  • jdb – Java Debugger

    In my case, to make the installations easier, I am using Android Tamer since all the above required tools are pre-installed.

    Topics Involved

    • Checking for Vulnerability.
    • Getting Ready with the Setup.
    • Runtime Code Injection.

    Let’s begin the game.

    Checking for Vulnerability

    In fact, this is the easiest part of the entire article.

    1. Decompile the application using APKTOOL to get the AndroidManifest.xml file using the following command.

    apktool d <vulnerableapp>.apk

    2. Inspect Androidmanifest.xml file for the following line.

    android:debuggable=”true”

    If you find the above line in the AndroidManifest.xml file, the application is debuggable and it can be exploited.

    Note: We used APKTOOL to see whether the app is debuggable or not. We won’t touch or modify any piece of code as mentioned earlier.

    Getting Ready with the Setup

    In this step, we will set up all the required things to inject code in to the app during its execution. As mentioned in the previous article, we will use remote debugging in this article.

  1. Start Your Emulator
  2. Install the vulnerable application
  3. Open up your terminal and run the following command to see the Dalvik VM ports listening on the emulator.

    adb jdwp

    The above command displays all the ports on which we can connect and debug as shown below.

    Figure 2

    Note: JDWP stands for Java Debug Wire Protocol. If an application running in its VM is debuggable, it exposes a unique port on which we can connect to it using JDB. This is possible in Dalvik Virtual Machines with the support of JDWP.

  4. Now, launch our target application and run the same command to see the listening port associated with our target application. It looks as shown below.

    Figure 2

    If we observe the difference between Figure 2 and Figure 3, there is one extra port 543 listening after launching the target application in Figure 3. We will attach JDB to the application using this port, since this is our target.

  5. Before attaching to the application, we need to port forward using adb since we are using remote debugging. This is shown in Figure 4.

    Figure 4

  6. Now, let’s attach JDB to the application as shown in the following figure.

    Figure 5

Runtime Code Injection

In this step, we will actually exploit the vulnerable application by modifying its behavior at runtime.

To modify the application’s behavior at runtime, we need to set up breakpoints and control the flow. But, we don’t know what classes and methods are used in the application. So, let’s use the following commands to find out the classes and methods used in the application.

To find the classes: “classes

Figure 6.1

Since I have too many classes listed, I am listing only a few classes. But if you still scroll down, you will see some interesting user defined classes as shown in the figure below.

Figure 6.2

Now, let us see the methods associated with MainActivity$1 class using the following command.

methods com.example.debug.MainActivity$1

This is shown in figure 7.

Figure 7

Now, let’s set up a breakpoint at onClick method and control the execution of the app as shown in Figure 8.

“stop in com.example.debug.MainActivity$1.onClick(android.view.View)”

Figure 8

To hit the breakpoint, we will have to manually click the button in the application. Once after clicking the button, the breakpoint will be hit and it appears as shown in Figure 9.

Figure 9

From here onwards, we will be able to control and see the sensitive values, method arguments, etc. using various commands.

Just to understand what’s happening in the background, I am following the code associated with the onClick method, which is shown in Figure 10.

Figure 10

Before proceeding further, let’s see if there are any local variables at this point in time using the command “locals“.

Figure 11

As we can see, there is no interesting information for us.

So, let’s execute the next line using the “next” command as shown below.

Figure 12

Let’s again try executing the command “locals” to see what happened in the previous command.

Figure 13

It’s pretty clear that TextView has been loaded into method arguments. If we look at the source code provided in Figure 10, the line associated with TextView instantiation has been executed.

Let’s now execute the next lines by executing the “next” command, and check the local variables as shown in the figure below.

Figure 14

As we can see, all the local variables have been displayed. The string “secret” looks interesting. The value “Try Again” is what is going to be printed when we click the button.

From Figure 10, it is very clear that the method setText is getting executed to print the value “Try Again“. So, let’s use the “step” command to get into the definition of the “setText” method and dynamically modify the text to be printed.

Figure 15

Let’s see the local variables inside the definition using “locals“.

Figure 16

Now, let’s change the value of “text” from “Try Again” to “Hacked” using “set” command.

Figure 17

We cannot see any changes in the application, since we haven’t executed the modified code.

So, let’s run the application using the “run” command as shown below, and see the application’s output on its screen.

Figure 18

Let’s look at the application running in the emulator.

Figure 19

We have successfully modified the output of the application at runtime. This is just an example to show how an application’s behavior can be modified if the application is debuggable. We can perform various other things including “Getting a shell” on the device in the context of the vulnerable application.

Conclusion

In this article, we have demonstrated how one can exploit an Android application if it is left debuggable when moving it to the production. Pentesters should always look for this vulnerability during their Android app pentests.


原文地址: http://resources.infosecinstitute.com/android-hacking-security-part-6-exploiting-debuggable-android-applications/#article

### 利用共享表示进行个性化联邦学习 在个性化联邦学习中,利用共享表示的方法旨在通过模型间的信息交换来提升各客户端本地模型的表现,同时保持一定程度的个性化。这种方法通常涉及两个主要方面:全局模型参数更新和个人化调整。 #### 全局模型训练与个人化调整 为了实现这一目标,在每轮迭代过程中,服务器会收集来自不同客户的梯度信息并计算平均值作为新的全局权重向量[^1]。随后,这些更新后的参数会被分发给各个客户机用于下一轮局部优化过程中的初始化设置。然而,由于数据分布差异较大以及隐私保护需求的存在,直接采用统一策略可能无法满足特定应用场景下的性能要求。 因此,研究者们提出了多种基于元学习框架下的解决方案,允许每个参与者根据自身特点自适应地微调其内部结构而不影响其他成员的学习进度。例如,可以通过引入额外的任务无关特征映射层或将某些神经网络组件设为固定不变等方式增强跨域泛化能力的同时保留个体特性。 #### 技术细节与算法设计 具体来说,一种常见的做法是在标准Federated Averaging (FedAvg)基础上加入正则项约束条件以鼓励相似样本之间形成更紧密关联;另一种则是借助于生成对抗网络(GANs),让多个代理机构共同构建一个虚拟空间内的公共表征库供后续迁移使用。此外还有些工作探索了如何结合强化学习机制动态调整参与方贡献比例从而达到更好的协作效果。 ```python def fed_avg_with_regularization(models, regularization_lambda=0.01): global_model = sum([model * (1 / len(models)) for model in models]) # Add L2 Regularization term to encourage similarity among local updates reg_term = sum([(global_model - m).norm() ** 2 for m in models]) * regularization_lambda optimized_global_model = global_model - reg_term return optimized_global_model ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值