Adding automatic patching for semi-corrupted APKs #2298
Merged
+211
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Threat actors are yet again exploiting another lenient-ism in the Android APK loader machinery. I've recently found two APKs whose AndroidManifest.xml ZIP headers was semi-corrupted in a way that prevents ordinary tools (including Jadx) from correctly processing them. Android was loading them just fine, though.
Corruption of the headers
The APKs are attached in the ZIP below (password:
infected
) and belongs to two (presumably) very different TAs: one comes from a campaign against Russians using OnlyFans as a bait, the other targets the user of an Italian bank. Thus, I'm inclined to believe this corruptions are intentional and will be used again in the future.Since APKs are just ZIPs, a little knowledge of the PKZIP format is required. These APKs have the following anomalies:
Jadx patch
This corruption can be undone, this PR attempts to introduce such undoing into Jadx. I'm not totally satisfied with the approach I took but it was the quickest.
Since the APK is visited everywhere with the standard
ZipFile
class, I opted for subclassing it, copying the original file into a temporary one and preprocessing it before calling thesuper
constructor with the path of the temporary file. This allows for a drop-in replacement ofjava.util.zip.ZipFile
withjadx.core.utils.files.ZipFile
. And that's just what the code in this PR does.The drawback is that a temporary file is created if the APK is detected as corrupted (if it is not, no temporary file is created). The temporary file is not deleted since it couldn't find a way to store the temporary filename in the instance without hacky code (it will be deleted by the OS, though).
Note however that the APK signature verification panel shows an exception because the original file is passed to the Android framework and this time it cannot correctly process it. I don't know if this is a show stopper.
I also forgot to comment the code 😳.
If somebody have suggestions they are welcome.
How the APK is patched
For the sake of completeness, the patching is done as follow when an invalid compression method is found:
Before
After
semi-corrupted-apks.zip