Learn / Stage 1: Foundations / Lesson 1.3

$ lesson 1.3 --stage foundations

Windows Essentials for Security

Windows runs most office and college desktops in India, and attackers know it inside out. This lesson teaches you what normal looks like, where Windows keeps its secrets, and how to read the evidence an attacker leaves behind.

  • Stage 1 Foundations
  • Level Beginner
  • 60 min
  • 7 sections, quiz, lab

Start the lesson Jump to the lab

By the end of this lesson you can

  • Recognise the normal Windows process tree and spot impostors
  • Know which folders and registry keys malware uses to hide and persist
  • Explain SIDs, access tokens, integrity levels and what UAC really does
  • Read key Security and System event IDs and query them with PowerShell
  • Use cmd and PowerShell to answer basic incident response questions
1.3.01

Know normal: the Windows process family

Most Indian offices, colleges and government departments run Windows, so most incidents you investigate will touch it. The first skill is not a fancy tool; it is knowing what a healthy Windows machine looks like, so the odd thing jumps out.

Normal Windows startup process tree: System, smss.exe, then csrss.exe, wininit.exe and winlogon.exe; wininit starts services.exe and lsass.exe; services.exe starts svchost.exeSystemPID 4smss.exesession managercsrss.exeone per sessionwininit.exesession 0winlogon.exelogon sessionservices.exeservice controllsass.exelogins, secretsuserinit.exethen explorer.exesvchost.exe
smss.exe creates per session copies of itself that exit, so csrss.exe, wininit.exe and winlogon.exe normally show no living parent.
Normal Windows processes
ProcessNormal locationNormal parentHow manyNotes
Systemkernel, no filenone1always PID 4
smss.exeC:\Windows\System32System1 lasting copyfirst user mode process
csrss.exeC:\Windows\System32smss.exe (exited)2 or moreone per session
wininit.exeC:\Windows\System32smss.exe (exited)1starts services.exe and lsass.exe
services.exeC:\Windows\System32wininit.exe1Service Control Manager
lsass.exeC:\Windows\System32wininit.exe1checks passwords, holds credentials; never more than one
svchost.exeC:\Windows\System32services.exemanyhosts services; launched with -k group arguments
explorer.exeC:\Windowsuserinit.exe (exited)one per logged in userthe desktop and taskbar
1.3.02

The Windows file system and where malware likes to live

Windows uses NTFS with drive letters (C:, D:). A few folders matter far more than others:

Important Windows folders
FolderWhat it holdsWho can write
C:\Windows\System32the core 64-bit system files and toolsadministrators and the system only
C:\Windows\SysWOW6432-bit versions of system files on 64-bit Windows (yes, the names look backwards)administrators
C:\Program Files and Program Files (x86)installed softwareadministrators
C:\ProgramDatashared app data, hidden by defaultoften any user can create files
C:\Users\<name>\AppData\Roaming, Local, LocalLowper user app settings and cachesthat user
%TEMP% (usually AppData\Local\Temp)temporary filesthat user
C:\Users\Publicfiles shared with every userevery user

Permissions on NTFS are access control lists: a list of entries like "Users: Read and Execute" or "Administrators: Full control". View them in a file's Properties, Security tab, or with icacls.

C:\> icacls C:\ProgramData
C:\> icacls "C:\Program Files"
1.3.03

The registry: Windows' giant settings database

The registry is a tree database holding almost every setting: installed software, services, drivers, user preferences and security policy. Its building blocks are keys (like folders) and values (name, type, data). Common types are REG_SZ (text), REG_DWORD (32-bit number) and REG_BINARY.

Registry root keys
Root keyShortWhat it holds
HKEY_LOCAL_MACHINEHKLMmachine wide settings: software, services, drivers, security
HKEY_CURRENT_USERHKCUsettings for the logged in user (loaded from their NTUSER.DAT)
HKEY_USERSHKUevery loaded user profile
HKEY_CLASSES_ROOTHKCRfile associations and COM objects (a merged view of HKLM and HKCU)
HKEY_CURRENT_CONFIGHKCCcurrent hardware profile

On disk, the main hives are files in C:\Windows\System32\config: SAM (local accounts and password hashes), SECURITY, SOFTWARE and SYSTEM. Each user's HKCU is C:\Users\<name>\NTUSER.DAT.

C:\> reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Run
C:\> reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run
PS> Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run'
1.3.04

Accounts, SIDs, tokens and UAC

Windows identifies every user and group by a security identifier (SID), not by name. A few are worth memorising:

Well known SIDs
SID or endingMeans
S-1-5-18Local System (NT AUTHORITY\SYSTEM), the most powerful local account
S-1-5-19 / S-1-5-20Local Service / Network Service, lower privilege service accounts
...-500the built in Administrator account (relative ID 500), disabled by default on modern Windows
...-501the built in Guest account
S-1-5-32-544the local Administrators group
...-1001 and upordinary user accounts you create

When you log in, Windows builds an access token listing your SID, groups and privileges. Every process you start carries a copy, and the kernel checks it against each object's ACL.

User Account Control

If you are an administrator, Windows actually gives you two tokens: a filtered standard user token used for normal work and a full admin token. UAC is the prompt that switches a program to the full token. Processes also get an integrity level (Low, Medium, High, System); a browser sandbox runs at Low so it cannot write to most of your files.

C:\> whoami /user
C:\> whoami /groups
C:\> whoami /priv
C:\> net localgroup administrators
1.3.05

Services and scheduled tasks

A service is a background program managed by the Service Control Manager (services.exe). It can start at boot before anyone logs in and usually runs as LocalSystem, LocalService, NetworkService or a dedicated account. A scheduled task runs a program at a time or on a trigger such as logon or idle.

PS> Get-Service | Where-Object Status -eq 'Running'
C:\> sc qc Spooler
C:\> schtasks /query /fo LIST /v | more
PS> Get-ScheduledTask | Where-Object State -ne 'Disabled'
Service startup types
Startup typeMeaning
Automaticstarts at boot
Automatic (Delayed Start)starts shortly after boot to speed up login
Manualstarts when something asks for it
Disabledcannot start
1.3.06

Event Viewer: the machine's diary

Open eventvwr.msc. Under Windows Logs you find Application, Security, Setup, System and Forwarded Events, and under Applications and Services Logs hundreds of detailed channels such as PowerShell and Windows Defender. Each record has a time, source, event ID, level and details. Learn the IDs and you can read the story of an attack.

Event IDs every Windows defender should know

Pick an event ID. All except 7045 and 4104 are in the Security log.

4624: Successful logon

Check the Logon Type: 2 interactive at the keyboard, 3 network (file shares), 5 service, 7 unlock, 10 remote desktop (RDP), 11 cached credentials. An admin account logging on with type 10 from an unknown IP at 3 AM deserves attention.

4625: Failed logon

Many 4625s for one account means password guessing; one failure for many accounts means password spraying. The Status and Sub Status codes say why it failed, for example 0xC000006A wrong password and 0xC0000064 user does not exist.

4672: Special privileges assigned

Logged right after 4624 when an account with admin level privileges logs on. Useful to spot admin logons quickly.

4688: New process created

Only recorded if Audit Process Creation is enabled, and the command line is included only if you also enable Include command line in process creation events. Sysmon event 1 gives richer detail.

4720: User account created

Attackers create backdoor accounts. Any account created outside normal IT work should be checked.

4732: Member added to a local group

Look especially for additions to Administrators or Remote Desktop Users.

4740: Account locked out

Often the visible result of brute force. Logged on the domain controller for domain accounts.

1102: Security log cleared

Recorded in the Security log itself when someone clears it. Attackers clear logs to hide; legitimate admins rarely need to.

7045: Service installed

In the System log. Remote execution tools and some malware install services, so random names or paths in Temp are a red flag.

4104: PowerShell script block

In Microsoft-Windows-PowerShell/Operational when script block logging is on. It records the actual decoded script, which defeats much obfuscation.

PS> Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625} -MaxEvents 10
PS> Get-WinEvent -FilterHashtable @{LogName='System'; Id=7045} | Format-List TimeCreated, Message
1.3.07

cmd and PowerShell for defenders

cmd.exe is the old command prompt, still everywhere. PowerShell is far more powerful: commands (cmdlets) follow a Verb-Noun pattern and pass objects through the pipeline, not just text, so you can filter and sort on real properties.

Equivalent commands
QuestioncmdPowerShell
Who am I, what privileges?whoami /all[Security.Principal.WindowsIdentity]::GetCurrent()
Local usersnet userGet-LocalUser
Who is admin?net localgroup administratorsGet-LocalGroupMember Administrators
Running processestasklist /svcGet-Process | Sort-Object CPU -Descending
Network connectionsnetstat -anoGet-NetTCPConnection -State Established
IP configurationipconfig /allGet-NetIPConfiguration
File hashcertutil -hashfile file SHA256Get-FileHash file -Algorithm SHA256
Hidden files toodir /aGet-ChildItem -Force
System details and patchessysteminfoGet-HotFix
PS> Get-NetTCPConnection -State Established | Select-Object LocalPort, RemoteAddress, RemotePort, OwningProcess
PS> Get-Process -Id (Get-NetTCPConnection -State Established).OwningProcess | Select-Object Id, ProcessName, Path

Flashcards: do you remember?

Tap a card to flip it. Try to answer in your head first; recalling is what makes it stick.

Quick quiz

Instant feedback on every answer. Score 70% or more to pass this lesson's quiz.

Q1You find svchost.exe running from C:\Users\Public\svchost.exe. What do you conclude?

Q2Which registry location makes a program start each time the current user logs in?

Q3200 events with ID 4625 for the account admin in 10 minutes most likely means:

Q4Which event suggests someone tried to hide their tracks?

Q5A Word document launches powershell.exe -w hidden -enc SQBFAFgA.... Best description?

Q6What is the safest daily setup for a home PC?

0 / 6

Hands-on lab

lab45 to 60 minutesyour own machines only

Lab: create evidence on your own Windows VM, then find it

You need: A Windows VM in VirtualBox. Microsoft offers free time limited evaluation copies of Windows 11 Enterprise and Windows Server at microsoft.com/evalcenter. Use a VM, not your main PC, because you will create accounts and settings.

  1. Snapshot first

    Install Windows in the VM, then take a snapshot called clean. Everything below can be undone by restoring it.

  2. Turn on the useful logging

    C:\> auditpol /set /subcategory:"Process Creation" /success:enable
    C:\> reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Audit /v ProcessCreationIncludeCmdLine_Enabled /t REG_DWORD /d 1 /f
    C:\> auditpol /get /category:"Logon/Logoff"

    Run these in an administrator Command Prompt. The second line adds command lines to event 4688.

  3. Make some events

    PS> $p = Read-Host -AsSecureString 'Password for labuser'
    PS> New-LocalUser -Name labuser -Password $p
    PS> Add-LocalGroupMember -Group Administrators -Member labuser
    C:\> runas /user:labuser cmd

    Use an administrator PowerShell. At the runas prompt type a wrong password twice. You just created events 4720, 4732 and 4625.

  4. Find them in Event Viewer and PowerShell

    PS> Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4720,4732,4625} -MaxEvents 20 | Format-Table TimeCreated, Id, Message -Wrap

    Open eventvwr.msc, Windows Logs, Security, and use Filter Current Log with 4720,4732,4625. Read who did what and when.

  5. Plant and hunt a harmless persistence entry

    C:\> reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v LabNotepad /t REG_SZ /d notepad.exe /f
    C:\> reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Run

    Sign out and in: Notepad opens. Now download Autoruns from Microsoft Sysinternals and find LabNotepad in the Logon tab. Delete it there or with reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v LabNotepad /f.

  6. Clean up

    PS> Remove-LocalUser -Name labuser

    Or simply restore the clean snapshot.

You are done when: You created a user, an admin group change, failed logons and a Run key, and found every one of them in the logs or in Autoruns.

Download the lab checklist (.txt)

Key takeaways

  • Learn normal first: right name, right path, right parent, right count.
  • User writable folders (AppData, Temp, ProgramData, Public) are where payloads run from.
  • Run keys, services and scheduled tasks are the big three persistence spots; Autoruns shows them all.
  • 4624, 4625, 4672, 4688, 4720, 4732, 1102 and 7045 tell most attack stories.
  • PowerShell is a gift to admins and attackers alike. Log it.

Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.