Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Overhaul #19154

Open
h00die opened this issue May 2, 2024 · 27 comments
Open

Android Overhaul #19154

h00die opened this issue May 2, 2024 · 27 comments

Comments

@h00die
Copy link
Contributor

h00die commented May 2, 2024

I wanted to start documenting some issues/enhancements for Android, as per slack convo.

The android payload was amazing, but @timwr (and whoever else has been working on it) hasn't had time to keep it up to date. I haven't played around with it for a while either, but am using it now for a presentation to children.

Ideas

Compatibility

the payload seems to be losing newer compatibility while trying to maintain older compatibility. I have a ZTE android 6.0.1 I use for demos, and all the payload stuff works great on there. a Samsung galaxy a03s on android 13 installs and some things work, but many give unexpected permissions errors (I believe part of #16208 is related). Maybe let a user pick which SDK version(s) they want to use. It could even be simple like 'pre android 6' and 'post android 6' kind of thing. I think the new android permission model is actually better for what we want anyways since it wont list an entire screen of permissions, but pop them up as we call things that need them. Likely a better scenario.

Related Issues
  1. Lots of good info: android payload permissions not registered #16208
  2. About Android 14 Incompatibility Issue #19224
  3. App not installed as app isn't compatible with your phone #19203
  4. Android incompatible issue #18703
  5. Android meterpreter reverse tcp #18464
  6. (likely) after creating a simple payload for android it is not intaling in andrioid i dont know whats wronge I allowed instalation from unknow sources everthing is updated the payloads was installing before i used a tool called evil-droid and remove its apktool.jar file and replaced it with lastest one (i dont know) #19136
  7. (possibly) bypass Google Protection on Android  #18529
  8. We need update in android/meterpreter/reverse_tcp #17433
  9. Android 14 to block old API versions #17620
  10. [Enhancement Request] - Modern Android Meterpreter Payload for SDK 23 and Above metasploit-payloads#695
  11. Android android/meterpreter/reverse_tcp webcam_snap and webcam_stream not working on Android 11+ metasploit-payloads#717
  12. Android Overhaul #19154
  13. apk payload does not support new android versions #16870

Persistence

Add persistence (on rooted at least)?

  1. Idea 1 ref2 on android 14 (bash script to init.d)
Related Issues
  1. Android Persistence Techniques Help  #18502
  2. plzzz someone answer ;( how to auto connect android/metrerpreter/reverse_tcp even though the cellphone is off and then on again || and please find the solution for IP - Meterpreter session closed. Reason: Died #19164
  3. how do android/meterpreter/reverse_tcp auto connect to the session even after rebooting, so the target no longer needs to click on the payload app #19177
  4. Backdooring so Files (Android) #18382
  5. How to get permanent access after rebooting Android via payload or script #17954
  6. (somewhat) How to ( get | keep ) a session when the user connects to a VPN #18014
  7. How to keep android meterpreter shell script running in background after app is closed #16375
  8. How to get persistence on Android 11? #15529

Bugs

  1. android/local/su_exec: Does not work with su on modern Android #16362

New Modules

  1. check for new exploits, last one for an app was one I did but it was more web server backdoor than anything. prob some chrome ones out there? maybe? Can we get a priv esc?
Related Issues
  1. cve-2020-0041
  2. CVE-2023-48409
  3. A few more here: https://github.com/github/securitylab/tree/main/SecurityExploits/Android
  4. I started coding a new post module/payload feature to pop up a fake unlock screen if the user uses a pin/passcode. much easier to ask for the password than get a hash. I never finished it, mainly because I hate java. (https://github.com/h00die/metasploit-framework/tree/android_password_prompt , rapid7/metasploit-payloads@master...h00die:metasploit-payloads:phish_android)
  5. cve-2023-45779

Enhancements

  1. could we get a flag in msfvenom to change the name from mainActivity, and maybe set a custom icon?
  2. mic stream Android meterpreter (record mic ) (wlan geolocate error) metasploit-payloads#309

Etc

  1. right now it seems like a lot of the instructions talk about signing your apk, maybe that could be built in or auto chained?

Just throwing this out there as it seems like a neglected, but still often used feature of metasploit. happy to hear some thoughts, but I don't know java, and haven't messed around with android phone hacking much.

@bcoles
Copy link
Contributor

bcoles commented May 2, 2024

3. the payload seems to be losing newer compatibility while trying to maintain older compatibility. I have a ZTE android 6.0.1 I use for demos, and all the payload stuff works great on there. a Samsung galaxy a03s on android 13 installs and some things work, but many give unexpected permissions errors (I believe part of [android payload permissions not registered #16208](https://github.com/rapid7/metasploit-framework/issues/16208) is related). Maybe let a user pick which SDK version(s) they want to use. It could even be simple like 'pre android 6' and 'post android 6' kind of thing. I think the new android permission model is actually better for what we want anyways since it wont list an entire screen of permissions, but pop them up as we call things that need them. Likely a better scenario.

rapid7/metasploit-payloads#695 (comment)

@skid-bomberman
Copy link

i was also so frustrated in the 2018 that the metasploit stopped working for android , and now in 2024 when i thought i would give it a another try i found out no difference , it was the same! same issues, but seeing your posts increases our hope. Thanks

@EnderActually
Copy link

Nothing works on my newer devices, This really needs to be fixed.

@Morsmalleo
Copy link

The reason the Android Payloads built by the metasploit framework's msfvenom don't work is because they are only configured for Android 2.3.3 (SDK 10) upto Android 5.1 (SDK 22).

Android 6.0 (SDK 23) and above introduced numerous changes to the way things are handled in Android such as Permissions, Services, etc etc.

Here's a brief rundown of the changes made to Permissions and Service handling after SDK 22:

Changes after Android 5.1 (SDK 22)

Android 6.0 (Marshmallow, API 23)

  1. Runtime Permissions: Apps must request permissions at runtime, not at install time. Permissions are grouped into "dangerous" and "normal" categories, with dangerous ones requiring user approval. This deprecated the Android Payload's use of Install-Time permissions.
  2. Doze and App Standby: Introduced to save battery life. Doze mode restricts network access, jobs, syncs, and wakelocks when the device is idle.

Android 7.0 (Nougat, API 24)

  1. Background Optimizations: Restricted background services and broadcasts to improve battery life.
  2. File URI Restrictions: Apps cannot expose file:// URIs to other apps. Use content:// URIs instead.

Android 8.0 (Oreo, API 26)

  1. Background Execution Limits: Restrictions on background services to save battery.
  2. Foreground Services: Apps must use foreground services with a visible notification for long-running tasks.
  3. Notification Channels: Introduced to manage notifications with more granularity.

Android 9.0 (Pie, API 28)

  1. Restricted Non-SDK Interfaces: Limits the use of non-SDK interfaces (private APIs).
  2. Wi-Fi Scans: Apps need location permissions to perform Wi-Fi scans.
  3. JobScheduler Improvements: Enhanced job scheduling to improve power and performance.

Android 10 (Q, API 29)

  1. Scoped Storage: Apps have a sandboxed view of the file system, reducing the need for storage permissions.
  2. Background Location Access: Apps must request a new permission for background location access.
  3. Privacy Enhancements: Restrictions on accessing device identifiers (e.g., IMEI, serial number).

Android 11 (R, API 30)

  1. One-time Permissions: Users can grant temporary permissions for location, microphone, and camera.
  2. Background Location: Separate permission request for background location.
  3. Foreground Service Types: Apps must declare foreground service types (e.g., location, media playback).

Android 12 (S, API 31)

  1. Approximate Location: Option for users to grant approximate location instead of precise.
  2. Privacy Dashboard: Users can view permissions usage in the Privacy Dashboard.
  3. Hibernation: Unused apps are put in hibernation to save space and resources.

Android 13 (T, API 33)

  1. Runtime Permissions for Notifications: Apps need user permission to send notifications.
  2. Media Permissions: Split storage permissions into READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, and READ_MEDIA_AUDIO.
  3. Nearby Wi-Fi Devices: New permission for apps to find nearby devices without needing location permission.

Android 14 (API 34)

  1. Enhanced Security and Privacy: Stricter policies on data sharing and access.
  2. Dynamic Permissions: Fine-tuned control over permissions, enabling more precise management.
  3. Improved Background Tasks Handling: Further optimizations to background tasks to improve battery life and performance.

These changes reflect Android's ongoing efforts to enhance user privacy, security, and battery performance. Each major release has introduced stricter controls and optimizations, encouraging developers to adopt best practices for permission handling and service management.

@Heyholiday067
Copy link

Aside from fixing the compatibility,we can also consider add polymorphism to the payload.

By now,the payload have many part flagged by AV , like com.metasploit.satge or some words contain "metasploit".

@Admin9961
Copy link

There are any plans to release an update for the "android payload"? It needs a lot of code-level upgrade to work on recent APIs

@h00die
Copy link
Contributor Author

h00die commented Oct 9, 2024

As far as my understanding goes, there are no plans currently to update the payload. It will need to be a community effort, and no one has volunteered their services at this point.

@Admin9961
Copy link

We can link it against SDK +26 to make it work with A14 and maintain some compatibility with A8 at least. Losing support for A6 is not a problem, no one uses it anymore. The framework already dropped support for older Windows versions as well

@k41ed
Copy link

k41ed commented Oct 28, 2024

As far as my understanding goes, there are no plans currently to update the payload. It will need to be a community effort, and no one has volunteered their services at this point.

I have 15 years of experience in Android applications. I've created numerous trojans and backdoors for mobile, and I can help.

@Morsmalleo
Copy link

As far as my understanding goes, there are no plans currently to update the payload. It will need to be a community effort, and no one has volunteered their services at this point.

I have 15 years of experience in Android applications. I've created numerous trojans and backdoors for mobile, and I can help.

Let me guess we have to contact you privately through Telegram, Wikr or Email if we want your help?

@k41ed
Copy link

k41ed commented Oct 28, 2024

As far as my understanding goes, there are no plans currently to update the payload. It will need to be a community effort, and no one has volunteered their services at this point.

I have 15 years of experience in Android applications. I've created numerous trojans and backdoors for mobile, and I can help.

Let me guess we have to contact you privately through Telegram, Wikr or Email if we want your help?
Telegram
@k41ed

@Morsmalleo
Copy link

As far as my understanding goes, there are no plans currently to update the payload. It will need to be a community effort, and no one has volunteered their services at this point.

I have 15 years of experience in Android applications. I've created numerous trojans and backdoors for mobile, and I can help.

Let me guess we have to contact you privately through Telegram, Wikr or Email if we want your help?
Telegram
@k41ed

😂 No, just no! Bro this is GitHub and this is an open source repository, if you want to help like how you claim you can then Fork the repository and the Metasploit-Payloads repository as well, and start making and sharing your updates via Pull Requests!

Help on Open Source projects doesn't come from Private Telescam.... I mean Telegram interactions, it comes from hard work, collaboration and community efforts most of the time.

@soroshsabz
Copy link
Contributor

ITNOA

@Morsmalleo @h00die

Can you say some guide for starting this issue?

thanks

@h00die
Copy link
Contributor Author

h00die commented Nov 7, 2024

which issue were you wanting to tackle, I've outlined quite a bit

@soroshsabz
Copy link
Contributor

soroshsabz commented Nov 7, 2024

@h00die

If I understand your question correctly, I want to focused on resolving compatibility issues (Android 7 - 15 ).
but I do not know where can I start on this code base? and do you want to change any design level of current code or not? and I your answer is yes, what is your new design?

thanks

@h00die
Copy link
Contributor Author

h00die commented Nov 7, 2024

Being unfamiliar with Android development, and Java, I'm not a good helper on this. However the payload is located here: https://github.com/rapid7/metasploit-payloads/tree/master/java/androidpayload and I would agree that getting the combability updated would be a best first step.

If possible I'd avoid doing any design level changes, but its likely you'll need to in order to get the payload working correctly. I'd try to work on this in steps to avoid it become a huge snowball where every line of code has to be updated, but that may end up being the case anyways.

If you need help, I'd suggest joining the discord channel. I think you'll get quicker responses there for code level questions.

@k41ed
Copy link

k41ed commented Nov 12, 2024

😂 No, just no! Bro this is GitHub and this is an open source repository, if you want to help like how you claim you can then Fork the repository and the Metasploit-Payloads repository as well, and start making and sharing your updates via Pull Requests!

Help on Open Source projects doesn't come from Private Telescam.... I mean Telegram interactions, it comes from hard work, collaboration and community efforts most of the time.

I was just kidding around 😂 😂 😂 . I’ve now forked the repository and made the necessary updates as suggested. I’ve also pushed the changes to my fork and created a pull request for review.

Thanks for the guidance on contributing to open source projects. I appreciate the opportunity to help improve this project, and I'm looking forward to collaborating with the community!

(edited by h00die) rapid7/metasploit-payloads#734

@soroshsabz
Copy link
Contributor

soroshsabz commented Jan 10, 2025

@h00die Do you agree to Migrate android build system to gradle from maven?

android-maven-plugin does not update from 2019, and I think it is obsolete.

if you agree with me, I think I can try to migrate this

https://docs.gradle.org/current/userguide/migrating_from_maven.html

@h00die
Copy link
Contributor Author

h00die commented Jan 10, 2025

I have no opinions or authority for android stuff, just highlighting the issues

@soroshsabz
Copy link
Contributor

soroshsabz commented Jan 10, 2025

I have no opinions or authority for android stuff, just highlighting the issues

@h00die Who can I coordinate with for project changes?

I actually want to know who is responsible/accountable for the Android part of the project?

@h00die
Copy link
Contributor Author

h00die commented Jan 10, 2025

Likely someone at rapid7. They all have access to this issue and see these posts. However, it may not reach their threshold for addressing at the moment. You could try joining slack as well

@soroshsabz
Copy link
Contributor

@bwatters-r7 do you have any idea?

@bwatters-r7
Copy link
Contributor

Hi there; uh, OK.... I'll try and answer some questions. I am no Android/Java Dev, but I occasionally poke at the code as needed.

First, and I want to be as gentle as possible, but also blunt- Android is simply not one of our priorities; when we get research and feature cycles, our attention tends to go to things like supporting ADCS attacks, adding modules from the KEV list, or expanding the Linux Meterpreter architectures as we see increasing IoT running on lots of embedded platforms. That said, we will do our best to support anyone who takes this on as a project- No one here is going to complain if our android Meterpreter gets improved, but I think we need to determine a path before we start walking it, hence this issue by @h00die. We really do not have a resident in-house expert on Android, so even getting a strategic view can be difficult. To @soroshsabz's question about who is responsible/accountable for Android payloads: no one is, but then again, I would say no one is completely responsible/accountable for any one thing in Metasploit. Again, we will try. @h00die is right- please be patient. As you're asking for improvements, remember that we have 7 Android post modules, and if I recall correctly, several require the device to be rooted. Compare that to nearly 300 Windows post modules and 50 Linux post modules. When making requests and suggestions keep in mind that Android is simply not something that we see used nearly as much as Windows, Python, Java, or Linux Meterpreters, and we have no shortage of improvements we'd like to make to them, too 😓. Suggestions that are going to cause an explosion of code maintenance or testing surface for something we don't see used often are going to take longer to get landed/improved. Additions that streamline testing, building, and verification will make you lots of friends, though!

First- Compatibility; we are not keeping up with modern Android- no one's going to argue this point. Several times we've looked at the path forward here, and we never came away with something solid. As stated, we don't have a "supported" android list, or a clear roadmap for what we should support. @soroshsabz is absolutely right to ask the question "what is the goal for compatibility" before we start thinking about a solution. This is a great place for community to start- what versions of Android do people see out in the wild? How are red teams using Android targets? What are people using Android implants for? In my experience, Android for Red Teams has been a bit of a gray area- corporations don't really issue a lot of phones, and there are a lot of ethical considerations for attacking BYOD infrastructure as part of a red team exercise, so most seem to keep their distance. That means a lot of requests we get surrounding Android are less corporate red teaming and more about hacking an ex's facebook app, and while we want to support independent hackers and red teamers, people wanting to hack ex's phones can go do anatomically impossible things with themselves as far as we are concerned.

Laying out some definitive, professional workflows for red teaming Android would be really interesting and enlightening for us, and give us a much clearer understanding of the use case.

Supporting multiple payload bands is a really cool idea we have talked about, but that would explode testing. payload/android15/<etc> sounds super cool, but for each one, we're geometrically expanding the test surface and the build environment, so I'm not sure how feasible it is. Probably a better start is to map out what versions people would like to see supported, a relevant and predictable sunsetting roadmap, and how we can make that roadmap clear and predictable to users. Clear, reproduceable testing steps that don't require a phone would also be really useful, since we don't have the cash to go buy dozens of phones every year for testing. I worked a bit with Tim a few years ago on how to use x86_64 android VMs for testing- I think it is a viable option in many cases because of the JVM, but that kind of fell by the wayside. It might be interesting to see what github actions might support, since we've moved a lot of testing there recently.

Second, I'm going to caution about making huge changes off the bat- I'll chat with people about Maven, but we use Maven for our Java builds as well. I'll comment directly on some of the PRs, but remember that every change to the build needs to be checked, approved, and then we need to make changes to our docker image for building. Any changes to any Meterpreter also need to be determined if they are breaking changes or not- landing a change that causes a payload that worked yesterday to stop working today on the same hardware needs to have some documentation and a major release associated with it- calling that out in PRs would be very helpful, but it also means those changes need to wait for a larger release so we can make sure everyone knows that things might break. Prior to starting to make changes, it might be worthwhile to plan and provide a way to make testing easier, so we can have confidence changes will only affect the desired results (see earlier comment about not wanting to buy a dozen new phones every year).

Third, when you're updating builds or really anything, do not forget to update documentation. I see some changes in PRs listed here that change how we build things, but nothing is reflected in documentation changes. We've got to be very clear what is happening, what we're supporting, and how/what that changes.

Lastly, know that we really, really appreciate your involvement here, even if the pace sometimes appears glacial. These are conversations we've had internally, but no consensus has been reached, so community guidance is really appreciated.
Metasploit is amazing, I'm privileged to work on it, and community members like y'all are a huge chunk of why everyone compares themselves to us. It is wonderful problem to have so many good ideas and help that we fall behind sometimes accepting the help!

@bcoles
Copy link
Contributor

bcoles commented Jan 11, 2025

I believe Metasploit payloads for Android will still run on systems as recent as Android 10 (API 29). These payloads should successfully establish a session, but with diminished capabilities.

With the intention of supporting both old and new versions of Android, one comparatively quick win would be augmenting the payload generation such that the SDK version is user-controlled, as discussed here:

This will help support newer versions of Android without breaking the existing build infrastructure, although comes with an increased maintenance burden as this may require bumping the version every time there is a new SDK release (yearly). Reasonable defaults for the specified SDK version are up for debate.

This would also save a lot of confusion. If the operator specifies an unsupported SDK version (ie, new SDK), the payload generation will fail with an error - as opposed to the current workflow, which is to deliver the APK to the target device before discovering that it will not run.

@bcoles
Copy link
Contributor

bcoles commented Jan 11, 2025

This is a great place for community to start-
what versions of Android do people see out in the wild?

I still see old and unsupported versions of Android occasionally. Usually old embedded systems.

How are red teams using Android targets? What are people using Android implants for?

I suggest file system access and network access as a minimum requirement for supported capabilities.

In my experience, Android for Red Teams has been a bit of a gray area- corporations don't really issue a lot of phones, and there are a lot of ethical considerations for attacking BYOD infrastructure as part of a red team exercise, so most seem to keep their distance.

Excluding Android cell phones and BYOD Android devices (which are usually also cell phones), I commonly see:

  • Android tablets used by customer facing staff (support, sales) and mobile staff (field maintenance).
  • Android tablets shared by visitors in shared/public areas (such as, visitor check-in at reception).
  • Android TVs used in waiting rooms, meeting rooms, and break rooms.

I expect everyone has a similar experience.

I also commonly see many embedded devices that are likely to be running Android, such as:

  • Monitoring/telemetry systems
  • Telecommunications devices (intercoms, phones, etc)
  • Anything with a touchscreen interface

Less often, I see Android based devices for role-specific functions; ie, hand-held devices, such as barcode scanners.

We may already have a bunch of Android exploit modules targeting embedded Android devices. Although a search for "android" in modules/exploits reveals very few matches outside of the modules/exploits/android directory, it is possible that some of the ARM exploit modules in the linux category target Android systems.

@Admin9961
Copy link

@bwatters-r7 chill down bro, it's for the sake of completing a challenge so it's def worth working on the android payload

@Admin9961
Copy link

Admin9961 commented Jan 13, 2025

@h00die what there is so funny to laugh at?
Upon deploying the current payload I get
adb: failed to install payload.apk: Failure [INSTALL_FAILED_DEPRECATED_SDK_VERSION: App package must target at least SDK version 23, but found 17]

However, making a simple research I found that the key API to update may be those related to dynamic Dex in-memory loading method. If I'm not wrong the old payload is using DexClassLoader to dynamically load an artifact called payload.dex that contains the script-kiddiesh Meterpreter. We should consider upgrading SDK to 26 and find a way to use InMemoryDexClassLoader instead (introduced in SDK 26) to load arbitrary code.

Feedbacks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

10 participants