<# : Co-CISO Android phone check __CC_VERSION__ - READ-ONLY. Double-click to run on a Windows PC. @echo off title Co-CISO phone check set "CCDIR=%~dp0" set "CCSELF=%~f0" powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ([IO.File]::ReadAllText($env:CCSELF))" echo. pause exit /b #> # ------------------------------------------------------------------------------------------------ # Co-CISO Android phone check. READ-ONLY: lists the phone's system version, security patch, # screen-lock state and the apps installed outside the app store, with their risky permissions. # It reads no messages, photos, contacts or passwords and changes nothing on the phone. # It uses Google's official Android Platform Tools (downloaded once from dl.google.com if missing). # Published by Co-CISO ยท Template source: https://co-ciso.online/collectors/templates/ # ------------------------------------------------------------------------------------------------ $ErrorActionPreference = 'SilentlyContinue' $ProgressPreference = 'SilentlyContinue' Write-Host '' Write-Host ' Co-CISO - __CC_MSG_PHONE_INTRO__' -ForegroundColor Cyan Write-Host '' Write-Host ' 1. __CC_MSG_PHONE_1__' Write-Host ' 2. __CC_MSG_PHONE_2__' Write-Host ' 3. __CC_MSG_PHONE_3__' Write-Host '' $tools = Join-Path $env:LOCALAPPDATA 'Co-CISO\platform-tools' $adb = Join-Path $tools 'adb.exe' if (-not (Test-Path $adb)) { Write-Host ' __CC_MSG_PHONE_DL__' -ForegroundColor Yellow $zip = Join-Path $env:TEMP 'co-ciso-platform-tools.zip' Invoke-WebRequest -UseBasicParsing 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip' -OutFile $zip Expand-Archive -Force $zip (Split-Path $tools) Remove-Item $zip } if (-not (Test-Path $adb)) { Write-Host ' Android Platform Tools could not be downloaded.' -ForegroundColor Red; return } & $adb start-server *> $null $deadline = (Get-Date).AddMinutes(3) $state = '' while ((Get-Date) -lt $deadline) { $lines = & $adb devices | Select-Object -Skip 1 | Where-Object { $_ -match '\S' } if ($lines -match '\tdevice$') { $state = 'ok'; break } if ($lines -match 'unauthorized') { Write-Host ' __CC_MSG_PHONE_ALLOW__' -ForegroundColor Yellow } Start-Sleep -Seconds 3 } if ($state -ne 'ok') { Write-Host ' __CC_MSG_PHONE_NONE__' -ForegroundColor Red; return } function sh([string]$c) { (& $adb shell $c 2>$null | Out-String).Trim() } Write-Host ' __CC_MSG_RUNNING__' -ForegroundColor Cyan $cryptoState = sh 'getprop ro.crypto.state' $lockDisabled = sh 'locksettings get-disabled' $device = [ordered]@{ manufacturer = sh 'getprop ro.product.manufacturer'; model = sh 'getprop ro.product.model' android_version = sh 'getprop ro.build.version.release'; security_patch = sh 'getprop ro.build.version.security_patch' build_tags = sh 'getprop ro.build.tags'; encrypted = if ($cryptoState -eq 'encrypted') { $true } elseif ($cryptoState -eq 'unencrypted') { $false } else { $null } screen_lock = if ($lockDisabled -eq 'false') { $true } elseif ($lockDisabled -eq 'true') { $false } else { $null } play_protect = sh 'settings get global package_verifier_user_consent' } $acc = (sh 'settings get secure enabled_accessibility_services') -split ':' | Where-Object { $_ -and $_ -ne 'null' } $nls = (sh 'settings get secure enabled_notification_listeners') -split ':' | Where-Object { $_ -and $_ -ne 'null' } $sms = sh 'settings get secure sms_default_application' $dpm = sh 'dumpsys device_policy' $admins = [regex]::Matches($dpm, 'ComponentInfo\{([^/}]+)') | ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique $stores = 'com.android.vending','com.sec.android.app.samsungapps','com.huawei.appmarket','com.xiaomi.market','com.xiaomi.mipicks','com.oppo.market','com.heytap.market','com.vivo.appstore','com.amazon.venezia','com.google.android.feedback' $apps = @() $packageLines = (sh 'pm list packages -3 -i') -split "`n" $software = @($packageLines | Where-Object { $_ -match 'package:(\S+)\s+installer=(\S+)' } | Select-Object -First 600 | ForEach-Object { if ($_ -match 'package:(\S+)\s+installer=(\S+)') { [ordered]@{ name = $Matches[1]; publisher = $Matches[2] } } }) foreach ($l in $packageLines) { if ($l -notmatch 'package:(\S+)\s+installer=(\S+)') { continue } $pkg = $Matches[1]; $inst = $Matches[2] $side = -not ($stores -contains $inst) $flags = @() if ($acc | Where-Object { $_ -like "$pkg/*" }) { $flags += 'accessibility' } if ($nls | Where-Object { $_ -like "$pkg/*" }) { $flags += 'notifications' } if ($admins -contains $pkg) { $flags += 'device_admin' } if ($sms -eq $pkg) { $flags += 'default_sms' } if ($side) { $dump = sh "dumpsys package $pkg" if ($dump -match 'android.permission.(RECEIVE_SMS|READ_SMS): granted=true') { $flags += 'sms' } if ($dump -match 'android.permission.REQUEST_INSTALL_PACKAGES: granted=true') { $flags += 'installs_apps' } if ($dump -match 'android.permission.SYSTEM_ALERT_WINDOW: granted=true') { $flags += 'overlay' } } $risk = if ($side -and $flags.Count -gt 0) { 'high' } elseif ($side) { 'medium' } elseif ($flags -contains 'accessibility' -or $flags -contains 'device_admin') { 'review' } else { 'low' } if ($risk -ne 'low') { $apps += [ordered]@{ package = $pkg; installer = $inst; sideloaded = $side; flags = $flags; risk = $risk } } } $total = ((sh 'pm list packages -3') -split "`n" | Where-Object { $_ -match 'package:' }).Count $deviceId = (& $adb get-serialno 2>$null | Out-String).Trim() $sha = [System.Security.Cryptography.SHA256]::Create() $deviceHash = ([BitConverter]::ToString($sha.ComputeHash([Text.Encoding]::UTF8.GetBytes($deviceId))) -replace '-', '').Substring(0,12).ToLower() $deviceId = $null; $sha.Dispose() $out = [ordered]@{ co_ciso_collector = 'android'; version = '__CC_VERSION__'; collected_at = (Get-Date).ToUniversalTime().ToString('o') device = $device; host = [ordered]@{ name = "device-$deviceHash"; model = "$($device.manufacturer) $($device.model)"; os = "Android $($device.android_version)" } third_party_apps = $total; apps = $apps; software = $software; collection_scope = 'Device posture and installed-package observations; not a confirmed malware or clean verdict.'; accessibility_services = @($acc).Count; device_admins = @($admins).Count } $json = $out | ConvertTo-Json -Depth 6 -Compress $b64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($json)) $head = @' __CC_HEAD__ '@ $tail = @' __CC_TAIL__ '@ $dir = if ($env:CCDIR) { $env:CCDIR } else { [Environment]::GetFolderPath('Desktop') } $file = Join-Path $dir ("Co-CISO-Report-Phone-{0}-{1}.html" -f ($device.model -replace '[^\w-]', ''), (Get-Date -Format 'yyyyMMdd-HHmm')) [IO.File]::WriteAllText($file, $head + $b64 + $tail, (New-Object Text.UTF8Encoding $false)) & $adb kill-server *> $null Write-Host '' Write-Host ' __CC_MSG_DONE__' -ForegroundColor Green Write-Host " $file" Write-Host ' __CC_MSG_PHONE_OFF__' -ForegroundColor Yellow Write-Host ' __CC_MSG_UPLOAD__' -ForegroundColor Yellow Start-Process $file