Challenges
Search…
Arbitrary Code Execution
The Login Activity com.insecureshop.LoginActivity contains the following code. As per the code, the android application obtains all the package names from the android device and creates package context for each package name. If there is any app whose package begins with com.insecureshopapp, the app tries to find com.insecureshopapp.MainInterface and call its getInstance method.
1
for (android.content.pm.PackageInfo info : getPackageManager().getInstalledPackages(0)) {
2
java.lang.String packageName = info.packageName;
3
kotlin.jvm.internal.Intrinsics.checkExpressionValueIsNotNull(packageName, "packageName");
4
if (kotlin.text.StringsKt.startsWith$default(packageName, "com.insecureshopapp", false, 2, (java.lang.Object) null)) {
5
try {
6
android.content.Context packageContext = createPackageContext(packageName, 3);
7
kotlin.jvm.internal.Intrinsics.checkExpressionValueIsNotNull(packageContext, "packageContext");
8
java.lang.Object value = packageContext.getClassLoader().loadClass("com.insecureshopapp.MainInterface").getMethod("getInstance", new java.lang.Class[]{android.content.Context.class}).invoke((java.lang.Object) null, new java.lang.Object[]{this});
9
kotlin.jvm.internal.Intrinsics.checkExpressionValueIsNotNull(value, "packageContext.classLoad…€¦ .invoke(null, this)");
10
android.util.Log.d("object_value", value.toString());
11
} catch (java.lang.Exception e) {
12
throw new java.lang.RuntimeException(e);
13
}
14
}
15
}
16
Copied!
An attacker can create their own app with a package name that begins with the right prefix, create the specified class with this method, and include in that method code that will then be executed in the context of the victim app.
Exploiting this may be tricky and not really straightforward. Go through the code in LoginActivity well and identify at what point the code execution will take place.

References:

Android: arbitrary code execution via third-party package contexts
News, Techniques & Guides
Last modified 6mo ago
Copy link
Contents
References: