Exploit database

GH-7d1759469adaacd6cb6ef41c6fb3d109

repobor/ghostlock-cve-2026-43499-4.19-thyme

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

168 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files12

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

exploit/prep_magisk.ps1

PowerShell · 8,832 bytes
# Local-first Magisk installer: takes the APK that is already on this machine
# (exploit/.magisk-cache/Magisk-v*.apk), extracts everything setup_magisk.sh and
# the Magisk app need, pushes it, and optionally starts magiskd and installs the
# manager app.  No network access is required once the APK is cached.
#
#   pwsh -File exploit\prep_magisk.ps1                 # push local assets only
#   pwsh -File exploit\prep_magisk.ps1 -Setup          # + start magiskd + install app
#   pwsh -File exploit\prep_magisk.ps1 -InstallApp     # + install the manager app only
#   pwsh -File exploit\prep_magisk.ps1 -Force          # re-push even if identical
#   pwsh -File exploit\prep_magisk.ps1 -Apk D:\x.apk   # use another local APK
#   pwsh -File exploit\prep_magisk.ps1 -Download       # fetch the release APK first
#
# Extracted from the APK (all of it lands under /data/local/tmp/.magisk-w, which a
# reboot clears - no system partition is touched):
#   lib/arm64-v8a/libmagisk.so        -> magisk          (the daemon / su binary)
#   lib/arm64-v8a/libmagiskpolicy.so  -> magiskpolicy
#   lib/arm64-v8a/libmagiskinit.so    -> magiskinit
#   lib/arm64-v8a/libmagiskboot.so    -> magiskboot
#   lib/arm64-v8a/libbusybox.so       -> busybox
#   assets/util_functions.sh etc.     -> MAGISKBIN assets the app's env_check wants
param(
    [string]$Apk,
    [string]$Version,      # release tag, only used with -Download
    [string]$Device,       # defaults to the attached Xiaomi 10S (ro.product.device=thyme)
    [string]$Remote = '/data/local/tmp/magisk.apk',
    [switch]$Force,        # re-push even when the device already has the same bytes
    [switch]$Download,     # ignore the local cache and fetch the release APK
    [switch]$InstallApp,   # install the Magisk manager app (launcher icon)
    [switch]$Setup         # push + start magiskd + install the app
)
$ErrorActionPreference = 'Stop'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$cache = Join-Path $here '.magisk-cache'
New-Item -ItemType Directory -Force -Path $cache | Out-Null
try { Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop } catch {
    try { Add-Type -AssemblyName System.IO.Compression -ErrorAction Stop } catch {}
}

function Get-Md5([string]$Path) {
    $md5 = New-Object System.Security.Cryptography.MD5CryptoServiceProvider
    ($md5.ComputeHash([System.IO.File]::ReadAllBytes($Path)) | ForEach-Object { $_.ToString('x2') }) -join ''
}

# Install the manager APK.  MIUI rejects adb installs from the shell uid with
# INSTALL_FAILED_USER_RESTRICTED, so fall back to installing as root through the
# magisk daemon (available once setup_magisk.sh has started it).
function Install-MagiskApp([string]$LocalApk, [string]$Dev, [string]$RemoteApk) {
    Write-Host "[*] installing the Magisk app ($(Split-Path -Leaf $LocalApk))"
    $out = "$(adb -s $Dev install -r -g $LocalApk 2>&1)"
    if ($out -match 'Success') {
        "[+] app installed - the launcher now shows the Magisk icon"
        return $true
    }
    Write-Host "[!] adb install: $($out.Trim())"
    if ($out -match 'USER_RESTRICTED' -or $out -match 'INSTALL_FAILED') {
        Write-Host "[*] retrying as root via the magisk daemon"
        $out2 = "$(adb -s $Dev shell "/debug_ramdisk/magisk su -c 'pm install -r $RemoteApk'" 2>&1)"
        if ($out2 -match 'Success') {
            "[+] app installed as root - the launcher now shows the Magisk icon"
            return $true
        }
        Write-Host "[!] root install: $($out2.Trim())"
    }
    return $false
}

# Resolve the APK: explicit path > newest local cache entry > network (opt-in).
if (-not $Apk -and -not $Download) {
    $cached = Get-ChildItem -Path $cache -Filter 'Magisk-v*.apk' -File -ErrorAction SilentlyContinue |
              Sort-Object LastWriteTime -Descending | Select-Object -First 1
    if ($cached) {
        $Apk = $cached.FullName
        Write-Host "[*] using local APK: $Apk"
    }
}

if (-not $Apk) {
    $relUrl = if ($Version) {
        "https://api.github.com/repos/topjohnwu/Magisk/releases/tags/$Version"
    } else {
        'https://api.github.com/repos/topjohnwu/Magisk/releases/latest'
    }
    Write-Host "[*] no local APK; querying $relUrl"
    $rel = Invoke-RestMethod $relUrl
    $asset = $rel.assets | Where-Object { $_.name -match '^Magisk-v.*\.apk$' } | Select-Object -First 1
    if (-not $asset) { throw "no Magisk apk asset in release $($rel.tag_name) ($relUrl)" }
    $Apk = Join-Path $cache $asset.name
    if (-not (Test-Path $Apk)) {
        Write-Host "[*] downloading $($asset.browser_download_url)"
        Invoke-WebRequest $asset.browser_download_url -OutFile $Apk
    } else {
        Write-Host "[*] cached: $Apk"
    }
    Write-Host "[*] release: $($rel.tag_name)"
}

if (-not (Test-Path $Apk)) { throw "APK not found: $Apk (drop a Magisk-v*.apk into $cache)" }

if (-not $Device) {
    . (Join-Path $here '_device.ps1')
    $Device = Resolve-ThymeDevice
}

$state = "$(adb -s $Device get-state 2>&1)".Trim()
if ($state -ne 'device') { throw "device '$Device' not available (get-state returned: $state)" }
Write-Host "[*] APK: $Apk"

# Everything the daemon and the app's env_check need, in one pass.
# Explicit source -> device name table.  Magisk's installer renames the APK's
# lib*.so into bare tool names (libmagisk.so -> magisk); deriving that by
# stripping only ".so" would yield "libmagisk" and every lookup downstream
# (setup_magisk.sh, the app's env_check) would miss.
$payload = @(
    @{ Src = 'lib/arm64-v8a/libmagisk.so';       Dst = 'magisk' },
    @{ Src = 'lib/arm64-v8a/libmagiskpolicy.so'; Dst = 'magiskpolicy' },
    @{ Src = 'lib/arm64-v8a/libmagiskinit.so';   Dst = 'magiskinit' },
    @{ Src = 'lib/arm64-v8a/libmagiskboot.so';   Dst = 'magiskboot' },
    @{ Src = 'lib/arm64-v8a/libbusybox.so';      Dst = 'busybox' },
    @{ Src = 'assets/util_functions.sh';         Dst = 'util_functions.sh' },
    @{ Src = 'assets/boot_patch.sh';             Dst = 'boot_patch.sh' },
    @{ Src = 'assets/app_functions.sh';          Dst = 'app_functions.sh' },
    @{ Src = 'assets/addon.d.sh';                Dst = 'addon.d.sh' },
    @{ Src = 'assets/module_installer.sh';       Dst = 'module_installer.sh' },
    @{ Src = 'assets/uninstaller.sh';            Dst = 'uninstaller.sh' }
)

$zip = [System.IO.Compression.ZipFile]::OpenRead($Apk)
try {
    $pushed = @()
    foreach ($item in $payload) {
        $entry = $zip.Entries | Where-Object { $_.FullName -eq $item.Src }
        if (-not $entry) { throw "$($item.Src) not found in APK; this release layout may differ - check unzip -l" }
        $local = Join-Path $cache $item.Dst
        [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $local, $true)
        $pushed += @{ Dst = $item.Dst; Local = $local; Size = $entry.Length }
    }
    "ok: extracted $($pushed.Count) files from the APK"
} finally { $zip.Dispose() }

foreach ($p in $pushed) {
    $remote = "/data/local/tmp/.magisk-w/" + $p.Dst
    $localMd5 = Get-Md5 $p.Local
    $remoteMd5 = ("$(adb -s $Device shell "md5sum $remote 2>&1")".Trim().Split(' ')[0])
    if (-not $Force -and $localMd5 -eq $remoteMd5) {
        "[*] up to date: $remote"
    } else {
        adb -s $Device shell "mkdir -p /data/local/tmp/.magisk-w" | Out-Null
        adb -s $Device push $p.Local $remote | Out-Null
        adb -s $Device shell "chmod 0755 $remote" | Out-Null
        "[+] pushed: $($p.Dst) -> $remote ($([math]::Round($p.Size/1MB,1)) MB)"
    }
}

# keep the APK on the device for reference/reinstall (skip when identical)
$localApkMd5 = Get-Md5 $Apk
$remoteApkMd5 = ("$(adb -s $Device shell "md5sum $Remote 2>&1")".Trim().Split(' ')[0])
if ($localApkMd5 -eq $remoteApkMd5) {
    "[*] APK already on device: $Remote"
} else {
    adb -s $Device push $Apk $Remote | Out-Null
    "[+] pushed: $Apk -> $Remote"
}

if ($Setup) {
    # setup_magisk.sh needs an existing root daemon (pwsh -File r.ps1 -Exploit).
    # Spawn a fresh pwsh: r.ps1 calls `exit`, which would otherwise terminate
    # this script's own session.
    Write-Host "[*] starting magiskd via setup_magisk.sh (needs root daemon from 'r.ps1 -Exploit')"
    & pwsh -NoLogo -NoProfile -File (Join-Path $here 'r.ps1') -FromFile (Join-Path $here 'setup_magisk.sh')
    if ($LASTEXITCODE -ne 0) {
        Write-Host "[!] r.ps1 exited $LASTEXITCODE - is the root daemon running? (pwsh -File r.ps1 -Exploit)"
    } else {
        Write-Host "[*] setup_magisk.sh dispatched; look for '=== done ===' in the output above"
    }
}

if ($InstallApp -or $Setup) {
    if (-not (Install-MagiskApp $Apk $Device $Remote)) {
        Write-Host "[!] app install failed; on MIUI enable 'USB debugging (Security settings)' or run:"
        Write-Host "    adb -s $Device shell `"/debug_ramdisk/magisk su -c 'pm install -r $Remote'`""
    }
}