# KrakenShield Java4Shell check for Windows (CVE-2026-114938), https://krakenshield.eu/java4shell-check/ # # Read-only. Lists the Java runtimes of this machine (PATH, JAVA_HOME, usual folders, registry, running # processes, Tomcat/procrun services such as Jira or Confluence), asks each one for its version and for the # CPU features it really uses, then reads the JVM options of running processes and services. Nothing is # installed, changed or sent anywhere. # # Usage: powershell -ExecutionPolicy Bypass -File .\java4shell-check.ps1 [-Deep] [-Lang fr|en] [C:\path\bin\java.exe ...] # or: irm https://krakenshield.eu/tools/java4shell-check.ps1 | iex (options: $env:KS_LANG, $env:KS_DEEP=1) # Exit codes (with -File): 0 nothing to fix, 1 exploitable runtime found, 2 update or manual check needed. # # Java4Shell is a heap overflow in the x86-64 Base64 decoding intrinsic of HotSpot. It needs an affected version # (17.0.6 to before 17.0.21.1, 21 before 21.0.13.1, 25 before 25.0.5.1, 27 before 27.0.1.1, every release of the # unsupported 18-20, 22-24 and 26 lines), an x86-64 CPU with AVX-512 F, BW, VBMI and BMI2 (Intel Ice Lake and # later, AMD Zen 4 and later) and the intrinsic enabled (UseAVX=3 and UseBASE64Intrinsics, the defaults there). # The file is kept ASCII so that "irm | iex" works on Windows PowerShell 5.1: French text uses \u escapes. $__ksRc = & { $Argv = @($args) $ErrorActionPreference = 'Continue' $KsVersion = '1.0.0' $Lang = if ($env:KS_LANG) { $env:KS_LANG } elseif ((Get-UICulture).TwoLetterISOLanguageName -eq 'fr') { 'fr' } else { 'en' } $Deep = $env:KS_DEEP -eq '1' $Extra = @() for ($i = 0; $i -lt $Argv.Count; $i++) { switch -Regex ($Argv[$i]) { '^-{1,2}deep$' { $Deep = $true } '^-{1,2}lang$' { $i++; if ($i -lt $Argv.Count) { $Lang = $Argv[$i] } } '^-{1,2}lang=' { $Lang = $Argv[$i] -replace '^-{1,2}lang=', '' } default { $Extra += $Argv[$i] } } } if ($Lang -notmatch '^fr') { $Lang = 'en' } else { $Lang = 'fr' } function M([string]$fr, [string]$en) { if ($Lang -eq 'fr') { [regex]::Unescape($fr) } else { $en } } function Out-Line([string]$text, [string]$color) { if ($color) { Write-Host $text -ForegroundColor $color } else { Write-Host $text } } function Detail([string]$text) { Write-Host (' ' + $text) } function Get-CpuStatus([string]$features) { if (-not $features) { return 'unknown' } $f = ' ' + (($features.ToLowerInvariant() -replace '[,;]', ' ') -replace '\s+', ' ') + ' ' foreach ($want in 'avx512f', 'avx512bw', 'bmi2') { if (-not $f.Contains(" $want ")) { return 'no' } } if ($f.Contains(' avx512vbmi ') -or $f.Contains(' avx512_vbmi ')) { return 'yes' } return 'no' } function Test-X86([string]$arch) { return $arch -match '^(x86_64|amd64|x64|x86|i[3-6]86)$' } $arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } $cpuModel = '' try { $cpuModel = ((Get-CimInstance Win32_Processor -ErrorAction Stop | Select-Object -First 1).Name).Trim() } catch { } $runtimes = New-Object System.Collections.Generic.List[string] function Add-Runtime([string]$path) { if (-not $path) { return } try { $full = (Resolve-Path -LiteralPath $path -ErrorAction Stop).ProviderPath } catch { return } if (-not (Test-Path -LiteralPath $full -PathType Leaf)) { return } foreach ($r in $runtimes) { if ($r -ieq $full) { return } } $runtimes.Add($full) } Get-Command java.exe -All -CommandType Application -ErrorAction SilentlyContinue | ForEach-Object { Add-Runtime $_.Source } if ($env:JAVA_HOME) { Add-Runtime (Join-Path $env:JAVA_HOME 'bin\java.exe') } $roots = @($env:ProgramFiles, ${env:ProgramFiles(x86)}, $env:ProgramW6432, 'C:\Java', 'C:\jdk', 'C:\tools', 'C:\Atlassian', 'C:\Jenkins', 'C:\keycloak') + @((Join-Path $env:USERPROFILE '.jdks'), (Join-Path $env:LOCALAPPDATA 'Programs')) | Where-Object { $_ -and (Test-Path -LiteralPath $_) } | Select-Object -Unique $vendors = '^(Java|JDK|JRE|OpenJDK|Eclipse Adoptium|Eclipse Foundation|Amazon Corretto|Corretto|Zulu|Azul|BellSoft|Semeru|IBM|RedHat|Red Hat|SapMachine|GraalVM|Atlassian|Jenkins|JetBrains|Keycloak|Apache Software Foundation|Tomcat|jdk.*|jre.*)' $patterns = 'bin\java.exe', 'jre\bin\java.exe', '*\bin\java.exe', '*\jre\bin\java.exe', '*\jbr\bin\java.exe', '*\*\bin\java.exe', '*\*\jre\bin\java.exe' foreach ($root in $roots) { $dirs = @(Get-ChildItem -LiteralPath $root -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -match $vendors -or $root -match '\\(Java|jdk|\.jdks)$' }) $dirs += @(Get-ChildItem -Path (Join-Path $root 'Microsoft\jdk*') -Directory -ErrorAction SilentlyContinue) foreach ($d in $dirs) { foreach ($pat in $patterns) { Get-Item -Path (Join-Path $d.FullName $pat) -ErrorAction SilentlyContinue | ForEach-Object { Add-Runtime $_.FullName } } } } foreach ($key in 'HKLM:\SOFTWARE\JavaSoft', 'HKLM:\SOFTWARE\WOW6432Node\JavaSoft', 'HKLM:\SOFTWARE\Eclipse Adoptium', 'HKLM:\SOFTWARE\Azul Systems', 'HKLM:\SOFTWARE\Amazon Corretto', 'HKLM:\SOFTWARE\Microsoft\JDK') { if (-not (Test-Path -LiteralPath $key)) { continue } Get-ChildItem -LiteralPath $key -Recurse -ErrorAction SilentlyContinue | ForEach-Object { $p = Get-ItemProperty -LiteralPath $_.PSPath -ErrorAction SilentlyContinue foreach ($name in 'JavaHome', 'Path') { if ($p.$name) { Add-Runtime (Join-Path $p.$name 'bin\java.exe') } } } } $procs = @() try { $procs = @(Get-CimInstance Win32_Process -Filter "Name='java.exe' OR Name='javaw.exe'" -ErrorAction Stop) } catch { } foreach ($p in $procs) { if ($p.ExecutablePath) { Add-Runtime $p.ExecutablePath } } $services = @() foreach ($base in 'HKLM:\SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0', 'HKLM:\SOFTWARE\Apache Software Foundation\Procrun 2.0') { if (-not (Test-Path -LiteralPath $base)) { continue } Get-ChildItem -LiteralPath $base -ErrorAction SilentlyContinue | ForEach-Object { $svc = $_.PSChildName $jk = Get-ItemProperty -LiteralPath (Join-Path $_.PSPath 'Parameters\Java') -ErrorAction SilentlyContinue if ($jk) { $jvm = [string]$jk.Jvm $javaExe = '' if ($jvm -and $jvm -ne 'auto' -and (Test-Path -LiteralPath $jvm)) { $javaExe = Join-Path (Split-Path (Split-Path $jvm -Parent) -Parent) 'java.exe' Add-Runtime $javaExe } $services += [pscustomobject]@{ Name = $svc; Java = $javaExe; Options = (@($jk.Options) + @($jk.Options9)) -join ' ' } } } } if ($Deep) { Get-PSDrive -PSProvider FileSystem -ErrorAction SilentlyContinue | Where-Object { $_.Root -match '^[A-Z]:\\$' } | ForEach-Object { Get-ChildItem -LiteralPath $_.Root -Filter java.exe -Recurse -File -ErrorAction SilentlyContinue | Where-Object { $_.Directory.Name -eq 'bin' } | ForEach-Object { Add-Runtime $_.FullName } } } foreach ($e in $Extra) { Add-Runtime $e } $javaEnv = 'JAVA_TOOL_OPTIONS', '_JAVA_OPTIONS', 'JDK_JAVA_OPTIONS' function Invoke-Java([string]$exe, [string[]]$javaArgs) { $saved = @{} foreach ($n in $javaEnv) { $saved[$n] = [Environment]::GetEnvironmentVariable($n, 'Process'); [Environment]::SetEnvironmentVariable($n, $null, 'Process') } try { return (& $exe @javaArgs 2>&1 | ForEach-Object { "$_" }) -join "`n" } catch { return '' } finally { foreach ($n in $javaEnv) { [Environment]::SetEnvironmentVariable($n, $saved[$n], 'Process') } } } function Get-Prop([string]$out, [string]$name) { $m = [regex]::Match($out, '(?m)^\s*' + [regex]::Escape($name) + ' = (.*)$') if ($m.Success) { return $m.Groups[1].Value.Trim() } else { return '' } } function Get-Flag([string]$out, [string]$name) { $m = [regex]::Match($out, '(?m)^\s*\S+\s+' + [regex]::Escape($name) + '\s+:?=\s+(\S+)') if ($m.Success) { return $m.Groups[1].Value } else { return '' } } function Get-VersionStatus([int]$maj, [int]$upd, [int]$pat, [string]$raw) { function Lt([int]$a, [int]$b, [int]$x, [int]$y) { return ($a -lt $x) -or ($a -eq $x -and $b -lt $y) } switch ($maj) { 0 { return 'unknown' } 17 { if ($upd -lt 6) { return 'unaffected' } elseif (Lt $upd $pat 21 1) { return 'affected' } else { return 'fixed' } } 21 { if (Lt $upd $pat 13 1) { return 'affected' } else { return 'fixed' } } 25 { if (Lt $upd $pat 5 1) { return 'affected' } else { return 'fixed' } } 27 { if (Lt $upd $pat 1 1) { return 'affected' } else { return 'fixed' } } 8 { if ($raw -match 'perf') { if ($upd -lt 513) { return 'affected' } else { return 'fixed' } } else { return 'unaffected' } } { $_ -in 18, 19, 20, 22, 23, 24, 26 } { return 'eol' } default { if ($maj -lt 17) { return 'unaffected' } else { return 'newer' } } } } $fixFor = @{ 17 = '17.0.21.1'; 21 = '21.0.13.1'; 25 = '25.0.5.1'; 27 = '27.0.1.1'; 8 = '8u513-perf' } Out-Line ("KrakenShield - " + (M 'Test Java4Shell' 'Java4Shell check') + " (CVE-2026-114938) v$KsVersion") 'White' $os = try { (Get-CimInstance Win32_OperatingSystem -ErrorAction Stop).Caption } catch { 'Windows' } Out-Line ("Machine : $os $arch" + $(if ($cpuModel) { ", $cpuModel" } else { '' })) if (-not (Test-X86 $arch)) { Out-Line ((M 'Processeur' 'CPU') + ' : ' + (M "architecture $arch, non concern\u00e9e (seul x86-64 l\u2019est)" "$arch architecture, not affected (only x86-64 is)")) 'Green' } else { Out-Line ((M 'Processeur' 'CPU') + ' : ' + (M 'chaque JVM va indiquer si elle utilise AVX-512 VBMI' 'each JVM will tell whether it uses AVX-512 VBMI')) } Write-Host '' $nVuln = 0; $nTodo = 0; $nOk = 0 $verdicts = @{} Out-Line ((M "Java trouv\u00e9s : " 'Java runtimes found: ') + $runtimes.Count) 'White' if ($runtimes.Count -eq 0) { Detail (M "Aucun Java dans les emplacements habituels. Relancez avec -Deep, ou donnez le chemin du java.exe en argument." 'No Java in the usual places. Run again with -Deep, or pass the path of java.exe as an argument.') } foreach ($j in $runtimes) { $out = Invoke-Java $j @('-XshowSettings:properties', '-version') $rtv = Get-Prop $out 'java.runtime.version'; if (-not $rtv) { $rtv = Get-Prop $out 'java.version' } $vendor = Get-Prop $out 'java.vendor.version'; if (-not $vendor) { $vendor = Get-Prop $out 'java.vendor' } $jarch = Get-Prop $out 'os.arch'; if (-not $jarch) { $jarch = $arch } $maj = 0; $upd = 0; $pat = 0 $vm = [regex]::Match($rtv, '^(\d+(?:[._]\d+)*)') if ($vm.Success) { $v = $vm.Groups[1].Value if ($v -match '^1\.(\d+)') { $maj = [int]$Matches[1]; if ($v -match '_(\d+)') { $upd = [int]$Matches[1] } } else { $parts = $v -split '\.' $maj = [int]$parts[0] if ($parts.Count -gt 2) { $upd = [int]($parts[2] -replace '_.*', '') } if ($parts.Count -gt 3) { $pat = [int]($parts[3] -replace '_.*', '') } } } $vs = Get-VersionStatus $maj $upd $pat "$rtv $vendor" $jcpu = 'unknown'; $uavx = ''; $ub64 = '' if (($vs -eq 'affected' -or $vs -eq 'eol') -and $maj -ge 9) { $fout = Invoke-Java $j @('-Xlog:os+cpu', '-XX:+PrintFlagsFinal', '-version') $cpuLine = ($fout -split "`n" | Where-Object { $_ -match 'CPU: total' } | Select-Object -First 1) $jcpu = Get-CpuStatus ([string]$cpuLine) $uavx = Get-Flag $fout 'UseAVX' $ub64 = Get-Flag $fout 'UseBASE64Intrinsics' } $info = (M 'Version' 'Version') + ' ' + $(if ($rtv) { $rtv } else { '?' }) + $(if ($vendor) { " ($vendor)" } else { '' }) $fix = if ($fixFor.ContainsKey($maj)) { $fixFor[$maj] } else { '21.0.13.1 / 25.0.5.1' } $verdict = 'OK' switch ($vs) { 'unknown' { $verdict = 'CHECK'; Out-Line ('[' + (M "\u00c0 V\u00c9RIFIER" 'CHECK') + "] $j") 'Yellow'; Detail (M 'Version illisible : lancez ce Java avec -version et comparez-la aux versions corrig\u00e9es.' 'Version not readable: run this Java with -version and compare it with the fixed releases.') } 'unaffected' { Out-Line "[OK] $j" 'Green'; Detail ("$info - " + (M "Java $maj n\u2019est pas concern\u00e9." "Java $maj is not affected.")) } 'newer' { Out-Line "[OK] $j" 'Green'; Detail ("$info - " + (M 'version post\u00e9rieure aux branches concern\u00e9es.' 'newer than the affected lines.')) } 'fixed' { Out-Line "[OK] $j" 'Green'; Detail ("$info - " + (M 'contient le correctif Java4Shell.' 'includes the Java4Shell fix.')) } default { $avxNum = 0; [void][int]::TryParse($uavx, [ref]$avxNum) if (-not (Test-X86 $jarch)) { $verdict = 'TODO'; $expo = M "architecture $jarch non concern\u00e9e" "$jarch architecture not affected" } elseif ($jcpu -eq 'yes' -and $avxNum -ge 3 -and $ub64 -eq 'true') { $verdict = 'VULN'; $expo = M "la JVM utilise AVX-512 VBMI (UseAVX=$uavx, UseBASE64Intrinsics=true)" "the JVM uses AVX-512 VBMI (UseAVX=$uavx, UseBASE64Intrinsics=true)" } elseif ($jcpu -eq 'yes') { $verdict = 'TODO'; $expo = M "intrins\u00e8que d\u00e9sactiv\u00e9 par d\u00e9faut ici (UseAVX=$uavx, UseBASE64Intrinsics=$ub64)" "intrinsic off by default here (UseAVX=$uavx, UseBASE64Intrinsics=$ub64)" } elseif ($jcpu -eq 'no') { $verdict = 'TODO'; $expo = M 'la JVM ne voit pas AVX-512 VBMI sur ce processeur' 'the JVM sees no AVX-512 VBMI on this CPU' } else { $verdict = 'CHECK'; $expo = M "jeu d\u2019instructions du processeur inconnu" 'CPU features unknown' } switch ($verdict) { 'VULN' { Out-Line ('[' + (M "VULN\u00c9RABLE" 'VULNERABLE') + "] $j") 'Red' } 'TODO' { Out-Line ('[' + (M "\u00c0 METTRE \u00c0 JOUR" 'UPDATE') + "] $j") 'Yellow' } default { Out-Line ('[' + (M "\u00c0 V\u00c9RIFIER" 'CHECK') + "] $j") 'Yellow' } } Detail ("$info - " + (M 'version concern\u00e9e' 'affected version') + ", $expo.") if ($vs -eq 'eol') { Detail (M "Java $maj n\u2019est plus maintenu et ne recevra pas de correctif : passez \u00e0 21.0.13.1 ou 25.0.5.1." "Java $maj is no longer maintained and gets no fix: move to 21.0.13.1 or 25.0.5.1.") } elseif ($verdict -eq 'VULN') { Detail (M "-> Mettez \u00e0 jour vers $fix ou plus, puis red\u00e9marrez les applications." "-> Update to $fix or later, then restart the applications.") } else { Detail (M "-> Mettez \u00e0 jour vers $fix quand m\u00eame : une VM peut \u00eatre d\u00e9plac\u00e9e sur un processeur r\u00e9cent." "-> Update to $fix anyway: a VM can be moved to a newer CPU.") } } } switch ($verdict) { 'VULN' { $nVuln++ } 'OK' { $nOk++ } default { $nTodo++ } } $verdicts[$j.ToLowerInvariant()] = $verdict } Write-Host '' $mitig = '-XX:-UseBASE64Intrinsics|-XX:UseAVX=[012](\D|$)' function Get-AppHint([string]$text) { $m = [regex]::Match($text, 'jira|confluence|bitbucket|bamboo|jenkins|keycloak|artifactory|pingfederate|gerrit|kafka|zookeeper|elasticsearch|opensearch|solr|tomcat|catalina|jetty|wildfly|jboss|spring|gradle|maven|sonar|nexus|minecraft', 'IgnoreCase') if ($m.Success) { return $m.Value.ToLowerInvariant() } else { return 'java' } } $machineEnv = ($javaEnv | ForEach-Object { [Environment]::GetEnvironmentVariable($_, 'Machine') }) -join ' ' $nMit = 0 Out-Line ((M 'Processus Java en cours : ' 'Running Java processes: ') + $procs.Count) 'White' foreach ($p in $procs) { $cmd = [string]$p.CommandLine $hint = Get-AppHint $cmd $rv = if ($p.ExecutablePath) { $verdicts[$p.ExecutablePath.ToLowerInvariant()] } else { $null } if (($cmd + ' ' + $machineEnv) -match $mitig) { $nMit++; $st = M 'option de protection pr\u00e9sente' 'mitigation option present'; $c = 'Green' } elseif ($rv -eq 'VULN') { $st = M "VULN\u00c9RABLE, aucune option de protection" 'VULNERABLE, no mitigation option'; $c = 'Red' } elseif ($rv -eq 'OK') { $st = M "Java non concern\u00e9 ou corrig\u00e9" 'Java not affected or fixed'; $c = 'Green' } else { $st = M 'voir le Java ci-dessus' 'see the runtime above'; $c = '' } Out-Line (" PID $($p.ProcessId) ($hint) : $st") $c if ($p.ExecutablePath) { Detail $p.ExecutablePath } } if ($procs.Count -gt 0 -and -not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Detail (M "Sans droits administrateur, la ligne de commande des services peut rester illisible." 'Without administrator rights, the command line of services may not be readable.') } if ($services.Count -gt 0) { Write-Host '' Out-Line ((M 'Services Tomcat (procrun) : ' 'Tomcat services (procrun): ') + $services.Count) 'White' foreach ($s in $services) { $rv = if ($s.Java) { $verdicts[$s.Java.ToLowerInvariant()] } else { $null } if (($s.Options + ' ' + $machineEnv) -match $mitig) { $nMit++; $st = M 'option de protection pr\u00e9sente' 'mitigation option present'; $c = 'Green' } elseif ($rv -eq 'VULN') { $st = M "VULN\u00c9RABLE, ajoutez -XX:-UseBASE64Intrinsics dans l\u2019onglet Java du service" 'VULNERABLE, add -XX:-UseBASE64Intrinsics in the Java tab of the service'; $c = 'Red' } elseif ($rv -eq 'OK') { $st = M "Java non concern\u00e9 ou corrig\u00e9" 'Java not affected or fixed'; $c = 'Green' } else { $st = M "JVM automatique : v\u00e9rifiez le Java utilis\u00e9 par ce service" 'automatic JVM: check the Java used by this service'; $c = 'Yellow' } Out-Line (" $($s.Name) ($(Get-AppHint $s.Name)) : $st") $c } } Write-Host '' if ($nVuln -gt 0) { if ($nVuln -gt 1) { Out-Line (M "R\u00e9sultat : VULN\u00c9RABLE ($nVuln Java exploitables sur ce processeur)." "Result: VULNERABLE ($nVuln runtimes exploitable on this CPU).") 'Red' } else { Out-Line (M "R\u00e9sultat : VULN\u00c9RABLE (1 Java exploitable sur ce processeur)." 'Result: VULNERABLE (1 runtime exploitable on this CPU).') 'Red' } Write-Host (M '1. Installez les mises \u00e0 jour Java du 17 novembre 2026 (17.0.21.1, 21.0.13.1, 25.0.5.1, 27.0.1.1) et red\u00e9marrez les applications.' '1. Install the 17 November 2026 Java updates (17.0.21.1, 21.0.13.1, 25.0.5.1, 27.0.1.1) and restart the applications.') Write-Host (M '2. En attendant, ajoutez cette option au lancement de chaque JVM (variable syst\u00e8me ou onglet Java du service), puis red\u00e9marrez :' '2. Meanwhile, add this option to every JVM launch (system variable or Java tab of the service), then restart:') Write-Host ' setx /M JAVA_TOOL_OPTIONS "-XX:-UseBASE64Intrinsics"' Write-Host (M "3. Commencez par les applications expos\u00e9es \u00e0 Internet : Jira, Confluence, Jenkins, Keycloak, Artifactory." '3. Start with the applications exposed to the Internet: Jira, Confluence, Jenkins, Keycloak, Artifactory.') if ($nMit -gt 1) { Write-Host (M " $nMit processus ou services ont d\u00e9j\u00e0 l\u2019option de protection." " $nMit processes or services already have the mitigation option.") } elseif ($nMit -eq 1) { Write-Host (M " 1 processus ou service a d\u00e9j\u00e0 l\u2019option de protection." ' 1 process or service already has the mitigation option.') } $rc = 1 } elseif ($nTodo -gt 0) { Out-Line (M "R\u00e9sultat : pas exploitable ici en l\u2019\u00e9tat, mais des mises \u00e0 jour ou v\u00e9rifications restent \u00e0 faire." 'Result: not exploitable here as things stand, but updates or checks remain.') 'Yellow' $rc = 2 } else { Out-Line (M "R\u00e9sultat : aucun Java vuln\u00e9rable \u00e0 Java4Shell trouv\u00e9 sur cette machine." 'Result: no Java vulnerable to Java4Shell found on this machine.') 'Green' $rc = 0 } Write-Host ('https://krakenshield.eu/' + $(if ($Lang -eq 'fr') { 'fr/' } else { '' }) + 'java4shell-check/') -ForegroundColor DarkGray $rc } @args if ($PSCommandPath -and $PSCommandPath -like '*java4shell-check*') { exit $__ksRc } Remove-Variable __ksRc -ErrorAction SilentlyContinue