Bekijk een demo×
×

Zie NinjaOne in actie!

Door dit formulier in te dienen geef ik aan akkoord te gaan met het privacybeleid van NinjaOne.

Hoe Wijzigingen in het BootConfig-bestand in Windows Bewaken [PowerShell Script]

In de ingewikkelde wereld van IT is het behoud van systeemintegriteit van het grootste belang. Een centraal onderdeel van het Windows-besturingssysteem is het BootConfig-bestand. Het controleren van wijzigingen in dit bestand is cruciaal voor systeembeheerders en IT-professionals om de veiligheid en stabiliteit van het systeem te garanderen. Deze handleiding gaat dieper in op een PowerShell-script dat controleert op wijzigingen in het BootConfig-bestand, waardoor een proactieve benadering van systeembeheer wordt geboden.

Achtergrond

Het BootConfig bestand in Windows is een basiselement dat opstartconfiguratiegegevens bevat. Het dicteert hoe het systeem opstart, welke OS-versies geladen moeten worden en andere opstartparameters. Gezien de rol in het opstartproces kunnen ongeautoriseerde of onverwachte wijzigingen leiden tot systeemstoringen of kwetsbaarheden. Dit maakt het een ideaal doelwit voor kwaadwillende actoren of malware. Voor IT-professionals en Managed Service Providers (MSP’s) is een tool die deze veranderingen kan detecteren van onschatbare waarde. Het helpt bij proactief systeembeheer en forensische analyse in geval van inbreuken op de beveiliging.

Het Script

#Requires -Version 5.1

<#
.SYNOPSIS
    Checks if the BootConfig file was modified from last run.
.DESCRIPTION
    Checks if the BootConfig file was modified from last run.
    On first run this will not produce an error, but will create a cache file for later comparison.
.EXAMPLE
    No parameters needed.
.OUTPUTS
    None
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    Release Notes:
    Initial Release
By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
    Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#>

[CmdletBinding()]
param (
    # Path and file where the cache file will be saved for comparison
    [string]
    $CachePath = "C:ProgramDataNinjaRMMAgentscriptingTest-BootConfig.clixml"
)

begin {
    function Test-IsElevated {
        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $p = New-Object System.Security.Principal.WindowsPrincipal($id)
        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
    }
}
process {
    if (-not (Test-IsElevated)) {
        Write-Error -Message "Access Denied. Please run with Administrator privileges."
        exit 1
    }

    # Get content and create hash of BootConfig file
    $BootConfigContent = bcdedit.exe /enum
    $Stream = [IO.MemoryStream]::new([byte[]][char[]]"$BootConfigContent")
    $BootConfigHash = Get-FileHash -InputStream $Stream -Algorithm SHA256

    $Current = [PSCustomObject]@{
        Content = $BootConfigContent
        Hash    = $BootConfigHash
    }

    # Check if this is first run or not
    if ($(Test-Path -Path $CachePath)) {
        # Compare last content and hash
        $Cache = Import-Clixml -Path $CachePath
        $ContentDifference = Compare-Object -ReferenceObject $Cache.Content -DifferenceObject $Current.Content -CaseSensitive
        $HashDifference = $Cache.Hash -like $Current.Hash
        $Current | Export-Clixml -Path $CachePath -Force -Confirm:$false
        if (-not $HashDifference) {
            Write-Host "BootConfig file has changed since last run!"
            Write-Host ""
            $ContentDifference | ForEach-Object {
                if ($_.SideIndicator -like '=>') {
                    Write-Host "Added: $($_.InputObject)"
                }
                elseif ($_.SideIndicator -like '<=') {
                    Write-Host "Removed: $($_.InputObject)"
                }
            }
            exit 1
        }
    }
    else {
        Write-Host "First run, saving comparison cache file."
        $Current | Export-Clixml -Path $CachePath -Force -Confirm:$false
    }
    exit 0
}
end {}

 

Toegang tot dit script en honderden andere in de NinjaOne Dojo

Toegang Krijgen

Gedetailleerd overzicht

Het meegeleverde script is een PowerShell-script dat zorgvuldig is gemaakt om wijzigingen in het BootConfig-bestand te controleren sinds de laatste keer dat het is uitgevoerd. Hier is een meer gedetailleerd stap-voor-stap overzicht:

  1. Vereisten: Het script vereist PowerShell versie 5.1.
  2. Elevation Check: Voordat het script in zijn hoofdfunctie duikt, controleert het of het wordt uitgevoerd met beheerdersrechten, wat essentieel is voor toegang tot bepaalde systeembestanden en opdrachten.
  3. BootConfig Hashing: Met het commando bcdedit.exe /enum haalt het script de inhoud van BootConfig op. Vervolgens wordt er een SHA256 hash van deze inhoud gemaakt, die dient als unieke identificatie voor die specifieke inhoud.
  4. Cachevergelijking: Het script zoekt dan naar een eerder opgeslagen cachebestand. Als het bestaat, vergelijkt het script de huidige BootConfig inhoud en hash met de versie in de cache.
  5. Uitgang: Als er verschillen worden gedetecteerd, geeft het script een gedetailleerde uitvoer van de wijzigingen, waarbij wordt gespecificeerd wat er is toegevoegd of verwijderd. Als het script voor het eerst wordt uitgevoerd, worden de huidige BootConfig-gegevens opgeslagen voor toekomstige vergelijkingen.

Potentiële Gebruikssituaties

  • Routinematige Systeemcontroles: IT-professionals zoals Alex kunnen dit script inzetten op bedrijfsservers voor routinecontroles, om er zeker van te zijn dat er geen ongeautoriseerde wijzigingen hebben plaatsgevonden.
  • Post-Software Installatie: Na het installeren van nieuwe software of updates kan het script worden uitgevoerd om te controleren of het BootConfig bestand ongewijzigd blijft, om te verzekeren dat de software niet heeft geknoeid met kritieke opstartgegevens.
  • Systeemconfiguratiewijzigingen: Voor en na het maken van belangrijke wijzigingen in de systeemconfiguratie kan het script gebruikt worden om ervoor te zorgen dat de integriteit van het BootConfig bestand intact blijft.

Vergelijkingen

Hoewel er hulpprogramma’s en software van derden zijn die mogelijkheden voor systeembewaking bieden, ligt het voordeel van dit script in zijn eenvoud en specificiteit. Het is lichtgewicht, eenvoudig te implementeren en richt zich alleen op het BootConfig-bestand, wat zorgt voor een gerichte en efficiënte controle.

FAQs

  • Q: Kan dit script draaien op oudere versies van Windows?
    A: Het script ondersteunt Windows 10 en Windows Server 2016 en nieuwer.
  • Q: Wat gebeurt er als het BootConfig-bestand ongewijzigd is?
    A: Het script wordt gewoon afgesloten zonder waarschuwingen, wat aangeeft dat er geen wijzigingen zijn sinds de laatste run.

Implicaties voor de veiligheid

Het detecteren van wijzigingen in het BootConfig bestand heeft niet alleen te maken met systeemstabiliteit, maar ook met beveiliging. Ongeautoriseerde wijzigingen kunnen duiden op een mogelijke inbreuk of malware-activiteit. Door dit bestand te monitoren, kunnen IT-professionals een proactieve houding aannemen tegen potentiële bedreigingen.

Aanbevelingen

  • Voer het script altijd uit met beheerdersrechten voor nauwkeurige resultaten.
  • Plan het script om het op regelmatige intervallen uit te voeren voor continue bewaking.
  • Maak back-ups van het BootConfig bestand om snel te kunnen herstellen in geval van ongeautoriseerde wijzigingen.

Slotbeschouwingen:

Op het gebied van IT-beveiliging en systeembeheer bieden tools als NinjaOne uitgebreide oplossingen voor verschillende uitdagingen. Het bewaken van kritieke systeembestanden, zoals het BootConfig bestand in Windows, is een bewijs van het belang van proactief systeembeheer. Met scripts zoals het besprokene kunnen IT-professionals systeemintegriteit garanderen, beveiliging versterken en operationele efficiëntie behouden.

Hier zijn enkele aanvullende bronnen die je misschien nuttig vindt:

Volgende stappen

Het opbouwen van een efficiënt en effectief IT-team vereist een gecentraliseerde oplossing die fungeert als uw kerndienstleveringstool. NinjaOne stelt IT-teams in staat om al hun apparaten te monitoren, beheren, beveiligen en ondersteunen, waar ze ook zijn, zonder de noodzaak van complexe on-premises infrastructuur.

Leer meer over NinjaOne Endpoint Management, bekijk een live rondleiding, of start uw gratis trial van het NinjaOne-platform

Categorieën:

Dit vindt u misschien ook leuk

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).