.NET MAUI Jailbreak and root detection

banditoth.MAUI packages just got a new package: banditoth.MAUI.JailbreakDetector. 2022 was a great year for me in a software development perspective, my MAUI packages got downloaded over more than 1500 times, which is a great achievement for me. I’m keeping up the work, and having a new package on my palette: A lightweight root and jailbreak detection algorithm for Android and iOS with .NET MAUI.

What is jailbreaking?

Jailbreaking is the process of removing the limitations imposed on iOS devices by Apple. It allows users to install apps and tweaks that are not available on the App Store, customise the appearance of the operating system, and access features that are otherwise restricted. Jailbreaking an iOS device is considered to be a violation of Apple’s terms of service, and it can also make the device more vulnerable to security risks.

What is rooting?

Rooting is the process of allowing users of smartphones, tablets and other devices running the Android mobile operating system to attain privileged control (known as root access) over various Android subsystems. Rooting is often performed with the goal of removing limitations that hardware manufacturers or carriers place on some devices, thereby providing the latest versions of Android to devices that no longer receive official updates, or unlocking features which are otherwise unavailable to the user. Rooting is also often used to remove pre-installed apps, known as bloatware, that the manufacturer or carrier included on the device and which the user may not have wanted.

Why jailbreak and root protection is important?

When a device is jailbroken or rooted, it can become more vulnerable to security risks because the jailbreak process involves disabling certain security measures and exposing the device to potentially malicious software. This can compromise the security and stability of the operating system, and it can also make the device more susceptible to being hacked or compromised in other ways. By implementing jailbreak protection, software developers can help to ensure that their apps and systems are running on a secure and stable platform, which can help to protect the device and its users from various types of attacks and vulnerabilities.

Use jailbreak and root protection in .NET MAUI

Install the banditoth.MAUI.JailbreakDetector NuGet in order to protect your apps against vulnerabilities.

Initalize the library in the MauiApp.cs file within the CreateMauiApp method, like this:

public static MauiApp CreateMauiApp()
		{
			var builder = MauiApp.CreateBuilder()
				.UseMauiApp<App>()
				...
				.ConfigureJailbreakProtection(configuration =>
				{
					configuration.MaximumPossibilityPercentage = 20;
					configuration.MaximumWarningCount = 1;
					configuration.CanThrowException = true;
				});
			return builder.Build();
		}

You can dependency inject the jailbreak detector instance, by resolving an instance of IJailbreakDetector. Store the instance in a private readonly field in your class, or use it directly.

    public async Task CheckJailbreakOrRoot()
    {
        if(_jbDetector.IsSupported())
        {
            if(await _jbDetector.IsRootedOrJailbrokenAsync())
            {
                // Code when jailbroken or rooted
            }
            else
            {
                // Code when clear
            }
        }
    }

By calling ScanExploitsAsync you can process the discovered exploits and warnings during the scan – It returns a ScanResultScanResult has a property named PossibilityPercentage. This percentage tells you how confidently you can tell whether a device has been jailbroken or rooted. Different types of tests contribute different weights to the final result.

    public async Task CheckJailbreakOrRoot()
    {
        ScanResult scan = await _jbDetector.ScanExploitsAsync();
        
        if(scan == null)
            return;
            
        foreach(var exploit in scan.Exploits)
        {
            // Get detailed information about the exploits here
        }
        
        if(scan.PossibilityPercentage < 5)
        {
            // Custom code when only 5% possible that the device is rooted or jailbroken
        }
    }

Remarks

Please note that there are many different kinds of jailbreaks and roots. It is possible that this package does not properly support the detection of these different techniques. If you find that filtering does not work on your device, please help by expanding the code repository.

This content has 1 year. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.