Created
January 2, 2023 21:34
-
-
Save JamieMagee/a12ce294862eb96135c123381a6aa438 to your computer and use it in GitHub Desktop.
Scanning Windows container images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Registry; | |
var registryHive = new RegistryHive("/tmp/nanoserver/layer/Files/Windows/System32/config/SOFTWARE"); | |
registryHive.ParseHive(); | |
var currentVersion = registryHive.GetKey(@"Microsoft\Windows NT\CurrentVersion"); | |
var fullVersion = | |
$"{currentVersion.GetValue("CurrentMajorVersionNumber")}.{currentVersion.GetValue("CurrentMinorVersionNumber")}.{currentVersion.GetValue("CurrentBuildNumber")}.{currentVersion.GetValue("UBR")}"; | |
Console.WriteLine(fullVersion); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var packages = registryHive.GetKey(@"Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages"); | |
var updatePackageRegex = new Regex(@"^Package_\d+_for_(KB\d+)~\w{16}~\w+~~((?:\d+\.){3}\d+)$"); | |
var updates = new Dictionary<string, string>(); | |
foreach (var packageKey in packages.SubKeys) | |
{ | |
if (!updatePackageRegex.IsMatch(packageKey.KeyName)) | |
{ | |
continue; | |
} | |
var currentState = packageKey.Values.Find(v => v.ValueName == "CurrentState")?.ValueData; | |
// Installed | |
if (currentState == "112") | |
{ | |
var groups = updatePackageRegex.Match(packageKey.KeyName).Groups; | |
updates[groups[1].Value] = groups[2].Value; | |
} | |
} | |
foreach (var update in updates) | |
{ | |
Console.WriteLine($"{update.Key}: {update.Value}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment