Sikker Administrator konto opsætning
Best Practice: #
Som standard, med en ny installation af Windows 10/11 vil der være en skjult Administrator konto.
Denne konto kan aktiveres, foreksempel fra en “windows genoprettelses” cd/usb og bruges til at løse problemer med systemet.
Men som default er der ingen kode på denne bruger, og den kan derfor udgøre en potential sikkerheds risiko hvis nogen får fysisk adgang til computeren, eller på anden vis kan aktivere denne konto.
Derfor er det en god ide at ændre koden (Husk at have en backup af denne kode gemt et sikkert sted) og på denne måde have en backup konto i tilfælde af mistet adgang til den lokale administrator bruger.
Neden under ses hvordan det gøres i henholdsvis Powershel og Command Promt.
! Husk at komandoerne skal udføre fra en Administrator shell (åben som administrator)
!! Disclaimer: Kør aldrig script eller anden koden fra nettet som du ikke har tillid til, eller ikke ved hvad foretager på systemet. Check altid koden for uhensigtsmæssig resultat.
Powershell #
# Powershell
Enable-LocalUser -Name Administrator
# Creates a variable to hold the new password
$NewPassword = Read-Host -Prompt "Prompting you for a password" -AsSecureString
#setting the new password while promting for it.
Set-LocalUser -Name "Administrator" -Password $NewPassword
# This one liner could be used instead of th two lines above, but would result in writing the password in cleartext instead of wrinting ******.
# Set-LocalUser -Name "Administrator" -Password (ConvertTo-SecureString -String "NewPassword" -AsPlainText -Force)
Disable-LocalUser -Name Administrator
Command Prompt #
REM Comand Prompt
REM Activate the hidden admin account
net user Administrator /active:yes
REM Change the password for the admin account
net user Administrator *
REM Disable the admin account
net user Administrator /active:no
Test at det virker: #
Når der laves ny konfiguration er det vigtigt at teste om det ønskede resultat og så virker.
Brug kommandoen fra Powershell for at tjekke om kontoens status er aktiv.
# See a list of all users and their status
Get-LocalUser
For at teste koden bliver man nød til at logge ind på kontoen med den nye kode. og det kan kun gøres hvis kontoen er aktiv.
# Enable user
Enable-LocalUser -Name Administrator
! Husk at gøre kontoen inaktiv efter testen.
Massehandling ved flere computere: #
Disse scripts kan bruges til at gentage handlingen flere gange på forskellige maskiner.
Windows .bat script #
@echo off
REM !! save this file with the extension .bat
REM Change "newPassword" as needed.
REM ! Importen, remember to delete the file or password from this file,
REM ! and to have a backup of the password if ever nedded.
set "adminAccount=Administrator"
set "newPassword=YourNewPassword"
REM Activate the hidden admin account
net user %adminAccount% /active:yes
echo Hidden admin account activated
REM Change the password for the admin account
net user %adminAccount% %newPassword%
echo Password changed successfully
REM Disable the admin account
net user %adminAccount% /active:no
echo Hidden admin account disabled
Powershell .ps1 script #
# !! save this file with the extension .ps1
# Check if the current session is running with administrator privileges
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
# If not running as administrator, re-run the script with elevated privileges
if (-not $isAdmin) {
Start-Process powershell.exe -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
Exit
}
# Activate the hidden admin account
$adminAccount = Get-WmiObject -Class Win32_UserAccount | Where-Object { $_.Name -eq "Administrator" -and $_.LocalAccount -eq $true }
if ($adminAccount.Disabled) {
$adminAccount.Disabled = $false
$adminAccount.Put()
Write-Host "Hidden admin account activated"
}
# Change the password for the admin account
# ! Importen, remember to delete the file or password from this file,
# ! and to have a backup of the password if ever nedded.
$newPassword = "YourNewPassword"
$securePassword = ConvertTo-SecureString -String $newPassword -AsPlainText -Force
Set-LocalUser -Name "Administrator" -Password $securePassword
Write-Host "Password changed successfully"
# Disable the admin account
$adminAccount.Disabled = $true
$adminAccount.Put()
Write-Host "Hidden admin account disabled"
Scriptet skal køre som administrator, enten ved at kalde den fra en “elevate” powershell, eller ved at højre klikke på filen, og trykke på “åben som administrator”