Windows Fundamentals
This is an introduction to Windows for penetration testers, covering key concepts like:
-
Windows Overview β Windows is one of the most common operating systems in IT environments, used in desktops and servers. Understanding Windows is crucial for both attacks and defense.
-
Windows Versions β Microsoft started Windows in 1985, evolving from MS-DOS to modern versions like Windows 11 and Windows Server. Different versions have unique features and vulnerabilities.
-
Finding OS Info β Use PowerShell's
Get-WmiObjectto check system details, processes, and services. Example: -
Accessing Windows β
-
Local Access β Directly using a device (keyboard, screen, etc.).
-
Remote Access β Connecting over a network using tools like:
-
RDP (Remote Desktop Protocol) β Windows' built-in remote access tool (port 3389).
-
SSH, VPN, FTP β Other remote access methods.
-
-
-
Using RDP for Pentesting β
-
On Windows: Use
mstsc.exe(Remote Desktop Connection). -
On Linux: Use
xfreerdpto connect to Windows targets. -
Saved
.rdpfiles may store credentials, useful in pentesting.
-
Key Takeaway: Understanding Windows, its versions, access methods, and remote tools is essential for penetration testing.
Windows Root Directory and File System Navigation¶
The Windows root directory (e.g., C:\) contains essential system folders and files. Key directories include:
-
Perflogs β Stores Windows performance logs (empty by default).
-
Program Files / Program Files (x86) β Stores installed applications (64-bit in
Program Files, 32-bit inProgram Files (x86)). -
ProgramData β Hidden folder storing essential program data accessible to all users.
-
Users β Contains user profiles, including the Default profile template and the Public folder for shared files.
-
AppData β Stores user-specific application data in three subfolders:
-
Roaming (syncs across devices),
-
Local (device-specific),
-
LocalLow (lower security level).
-
-
Windows β Contains core operating system files.
-
System, System32, SysWOW64 β Stores Windows API DLLs and essential system components.
-
WinSxS β Windows Component Store with copies of system files, updates, and service packs.
Command-Line Navigation¶
-
dirβ Lists directory contents (e.g.,dir C:\ /ashows all files, including hidden ones). -
treeβ Displays a graphical representation of the directory structure.-
Example:
tree "C:\Program Files (x86)\VMware"shows subfolders in VMware's installation. -
tree C:\ /f | morelists all files and folders inC:\one page at a time.
-
These commands help explore and manage the Windows file system efficiently.
Windows File Systems & NTFS Permissions¶
Windows File Systems Overview¶
Windows supports five file systems: FAT12, FAT16, FAT32, NTFS, and exFAT. However, modern Windows primarily uses NTFS, while FAT32 and exFAT are common for external storage.
FAT32 (File Allocation Table)¶
-
Pros: Compatible with most devices (PCs, gaming consoles, cameras, etc.), works across Windows, macOS, and Linux.
-
Cons: Cannot store files larger than 4GB, lacks built-in security and compression features.
NTFS (New Technology File System)¶
-
Pros: More reliable, supports large partitions, includes journaling, file compression, and permissions.
-
Cons: Not natively supported on some mobile devices and older media players.
NTFS File Permissions¶
NTFS allows setting granular access control on files and folders.
| Permission Type | Description |
|---|---|
| Full Control | Read, write, modify, delete files/folders. |
| Modify | Read, write, and delete files. |
| List Folder Contents | View and list folders/subfolders. |
| Read and Execute | Open and execute files. |
| Write | Add new files and write to existing ones. |
| Read | View file contents. |
-
Permissions are inherited from parent folders but can be explicitly set.
-
Traverse Folder allows moving through directories without listing contents.
Managing NTFS Permissions with icacls¶
The icacls command helps manage file/folder permissions via CLI.
View NTFS Permissions¶
πΉ Lists access levels for different users.
Grant Full Control to a User¶
πΉ Gives "joe" full control over the C:\Users folder.
Remove User Permissions¶
πΉ Revokes "joe"'s access.
Permission Codes¶
-
F β Full Access
-
D β Delete Access
-
M β Modify Access
-
RX β Read & Execute
-
R β Read-only
-
W β Write-only
πΉ icacls is useful for domain-wide access control, restricting user access, and managing file security.
Windows and Malware¶
-
Windows holds over 70% of the desktop OS market share, making it a prime target for malware.
-
The perception of Windows being less secure is due to its popularity rather than inherent flaws.
-
Malware can be written for any OS; no system is truly immune.
-
The EternalBlue vulnerability in SMBv1 is still exploited to spread ransomware.
Server Message Block (SMB) and NTFS Permissions¶
-
SMB is used for sharing files and printers in Windows environments.
-
NTFS permissions and share permissions are different but often apply to the same shared resource.
Permissions Overview¶
-
Share Permissions:
-
Full Control: All actions, including permission changes.
-
Change: Modify, add, and delete files.
-
Read: View contents only.
-
-
NTFS Permissions:
-
Full Control: Modify all files and permissions.
-
Modify: Read, write, and delete files.
-
Read & Execute: Open files and run programs.
-
List Folder Contents: View files and folders.
-
Write: Make changes to files.
-
Creating a Network Share¶
-
A shared folder can be created via Advanced Sharing.
-
SMB shares are commonly hosted on NAS/SAN devices in enterprises.
-
Access Control Lists (ACLs) manage permissions for shared resources.
Connecting to an SMB Share¶
-
smbclientcan list available shares and connect to them. -
Windows Defender Firewall might block external SMB connections.
-
Workgroup vs. Windows Domain authentication:
-
Workgroups use the local SAM database.
-
Domains use Active Directory for centralized authentication.
-
-
Firewall settings impact connectivity and may need rule adjustments.
Windows Services¶
Windows services are long-running processes that start automatically at boot and continue running in the background, even when users log out. They handle critical system functions such as networking, diagnostics, user authentication, and Windows updates. Services are managed via the Service Control Manager (SCM) through services.msc or the command line using sc.exe and PowerShell cmdlets like Get-Service.
Managing Windows Services via PowerShell¶
Example Output:
Name : AdobeARMservice
DisplayName : Adobe Acrobat Update Service
Status : Running
...
Name : Appinfo
DisplayName : Application Information
Status : Running
Services can have statuses like Running, Stopped, Paused, Starting, or Stopping and startup types like Manual, Automatic, or Delayed Start. Only users with administrative privileges can modify or delete services. Misconfigurations in service permissions can be used for privilege escalation in Windows systems.
Critical Windows System Services¶
Some system services cannot be restarted without a system reboot. Examples include:
-
smss.exe β Manages sessions
-
lsass.exe β Handles authentication and security
-
winlogon.exe β Manages user logins
-
services.exe β Controls Windows services
-
svchost.exe β Hosts services from DLLs
Processes in Windows¶
Processes in Windows run in the background and can be system-managed or application-started. Some are critical and cannot be terminated without affecting system stability, such as LSASS, System, and Windows Session Manager.
Local Security Authority Subsystem Service (LSASS)¶
lsass.exe enforces security policies, handles authentication, and generates access tokens for logged-in users. It is a high-value target for attackers because it stores credentials in memory.
SysInternals Tools¶
Microsoftβs SysInternals Suite provides powerful tools for system administration, available at \\live.sysinternals.com\tools.
Using ProcDump from SysInternals¶
ProcDump monitors and dumps process memory when specific criteria are met.
Task Manager and Process Monitoring¶
Windows Task Manager provides insights into running processes, resource usage, and startup programs. It can be accessed via:
-
Ctrl + Shift + Esc -
Ctrl + Alt + Del > Task Manager -
Running
taskmgrin CMD or PowerShell
Task Manager Tabs:¶
-
Processes: Lists applications and background processes with CPU, memory, and network usage.
-
Performance: Displays real-time CPU, RAM, and disk usage graphs.
-
App History: Tracks resource usage over time.
-
Startup: Lists programs set to launch at boot.
-
Users: Shows logged-in users and their process/resource usage.
-
Details: Provides detailed process information, including PID and user ownership.
-
Services: Displays installed services and their status.
Process Explorer¶
A SysInternals tool that provides an advanced view of running processes, DLLs, and memory usage. It helps analyze parent-child process relationships and troubleshoot orphaned processes.
These tools are widely used for system administration, security analysis, and penetration testing.
Windows Service Permissions¶
Understanding Service Permissions¶
Services in Windows operating systems manage long-running processes. However, misconfigurations in service permissions can introduce security risks such as privilege escalation, persistence, and executing unauthorized applications.
Importance of Service Accounts¶
When installing network services like DHCP or Active Directory Domain Services, the service runs using the credentials of the user performing the installation unless explicitly changed. Using personal accounts for services can lead to issues, such as service failures when the user account is disabled or removed. Best practices recommend using dedicated service accounts for running critical services.
Examining Windows Services¶
Using services.msc¶
-
services.mscallows viewing and managing all Windows services. -
The "Path to executable" field shows the program that runs when the service starts.
-
If NTFS permissions for the directory are weak, attackers can replace executables with malicious files.
-
Most services run under
LocalSystem, which has the highest privilege level. Services should use the least privilege principle when possible. -
The "Recovery" tab allows configuring actions upon service failures, which attackers might exploit to execute malicious programs.
Using sc Command¶
- The
sc(Service Control) command allows querying, configuring, and managing services.
Querying a Service¶
Output Example:
SERVICE_NAME: wuauserv
TYPE : 20 WIN32_SHARE_PROCESS
START_TYPE : 3 DEMAND_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\WINDOWS\system32\svchost.exe -k netsvcs -p
SERVICE_START_NAME : LocalSystem
Querying a Service on a Remote Device¶
Stopping a Service¶
If access is denied, the command must be executed with administrative privileges.
Changing the Service Executable Path¶
Verifying Changes:
Examining Service Permissions¶
Using sc sdshow¶
Output:
-
D: Represents Discretionary Access Control List (DACL) permissions.
-
AU: Authenticated Users.
-
BA: Built-in Administrators.
-
SY: Local System.
-
Access Rights:
-
CC: Query service configuration. -
LC: Query service status. -
RP: Start service. -
LO: Query service current status. -
RC: Read service security descriptor.
-
Using PowerShell to Examine Service Permissions¶
This retrieves the access control list (ACL) for the Windows Update service registry entry.
Security Best Practices¶
-
Use dedicated service accounts instead of user accounts.
-
Follow the principle of least privilege for service permissions.
-
Regularly audit service permissions using
scand PowerShell. -
Secure service executable directories to prevent unauthorized modifications.
-
Monitor for unauthorized service configuration changes.
By understanding and securing Windows service permissions, administrators can mitigate security risks associated with service misconfigurations.
Interactive vs. Non-Interactive Accounts in Windows¶
-
Interactive Logon: Requires user credentials to access a system locally, via
runas, or through Remote Desktop. -
Non-Interactive Accounts: Used by Windows to run services without user interaction. No passwords required.
Types of Non-Interactive Accounts:
-
Local System Account (NT AUTHORITY\SYSTEM): Most powerful, used for OS tasks and Windows services.
-
Local Service Account (NT AUTHORITY\LocalService): Limited privileges, similar to a local user.
-
Network Service Account (NT AUTHORITY\NetworkService): Similar to Local Service but can authenticate network sessions.
PowerShell Script Execution and Policies: A Complete Guide¶
1. Set-ExecutionPolicy¶
Overview¶
PowerShell has security policies to control the execution of scripts. The Set-ExecutionPolicy cmdlet allows users to modify these policies to define what scripts can run on a system.
Syntax¶
Common Execution Policies¶
| Policy Name | Description |
|---|---|
| Restricted | Default for Windows. Scripts cannot run. Only interactive commands allowed. |
| AllSigned | Only scripts signed by a trusted publisher can run. Prevents running untrusted scripts. |
| RemoteSigned | Local scripts can run without a signature, but downloaded scripts require a trusted signature. |
| Unrestricted | All scripts can run, but downloaded scripts show a security warning before execution. |
| Bypass | No restrictions. Any script can run without warnings or prompts. |
| Undefined | Removes the set policy and falls back to the default policy (Restricted). |
Example Commands¶
-
Check current execution policies across all scopes
Output:
-
Temporarily allow script execution in the current session
-
Changes policy only for the session.
-
Once the session is closed, the change is lost.
-
-
Permanently allow scripts for the current user
- This setting persists across sessions for the current user only.
-
Permanently allow scripts for all users on the machine
- Requires Administrator privileges.
-
Remove execution policy (reset to default)
2. Get-Module¶
Overview¶
Get-Module lists PowerShell modules that are loaded in memory or available for import.
Syntax¶
Get-Module [-Name <ModuleName>] [-ListAvailable] [-All] [-FullyQualifiedName <ModuleName>] [-PSEdition <Edition>]
Common Uses¶
-
List currently loaded modules
Output:
-
List all available modules (even if not loaded)
Output:
-
Show details of a specific module
Output:
-
Find what commands a module provides
3. Running Scripts & Command Execution¶
Overview¶
PowerShell allows executing scripts from local and remote locations. However, execution policies can block script execution for security reasons.
Example Script Execution¶
-
Running a PowerShell script from the current directory
-
.\means execute from the current directory. -
If execution is blocked, use:
-
-
Running a script and a command in sequence
Breakdown:
-
.\PowerView.ps1β Runs the script. -
;β Separates two commands in one line. -
Get-LocalGroupβ Lists local user groups. -
| fl(Format-List) β Displays output in a detailed list format.
Example Output:
-
-
Running a remote script
- Runs
MyScript.ps1onServer01remotely.
- Runs
-
Running a script with arguments
Security Considerations for Script Execution¶
-
Always verify the source of a script before running it.
-
Use
RemoteSignedinstead ofUnrestrictedfor better security. -
Avoid using
Bypassunless necessary for temporary sessions. -
Use
Get-ExecutionPolicy -Listto check the policy before running scripts.
Windows Management Instrumentation (WMI)¶
πΉ Key Points About WMI¶
-
Core Windows Component: Pre-installed since Windows 2000.
-
Manages System Components: Used to monitor hardware/software.
-
Components:
-
WMI Service: Manages communication.
-
WMI Providers: Gather system info.
-
Classes & Methods: Define operations.
-
WMI Repository: Stores static data.
-
CIM Object Manager: Handles queries.
-
WMI API: For external applications.
-
πΉ Uses of WMI¶
-
Monitor local/remote systems.
-
Configure security settings.
-
Modify system properties.
-
Schedule tasks and run commands.
πΉ WMIC (Deprecated)¶
-
Previously used via
wmiccommand. -
Example:
wmic os list brief(Quick system info).
πΉ PowerShell WMI Commands¶
-
Get System Info:
-
Invoke Methods (Example: Rename a File)
π PowerShell Replacements for WMIC¶
Since WMIC is deprecated, use PowerShell CIM Cmdlets instead:
-
Get-WmiObjectβ UseGet-CimInstance -
Invoke-WmiMethodβ UseInvoke-CimMethod
Windows Server Core vs. Desktop Experience¶
πΉ Windows Server Core
-
First Introduced: Windows Server 2008
-
Purpose: Minimalistic, command-line-based server installation
-
Benefits:
-
Smaller footprint (uses less disk space and memory)
-
Lower attack surface (fewer components exposed to threats)
-
Lower management requirements
-
Better performance for specific workloads
-
-
Management Methods:
-
PowerShell & Command Prompt
-
Remote Management (MMC, RSAT)
-
Limited GUI tools (Notepad, Task Manager, Registry Editor)
-
-
Common Use Cases:
-
Domain Controllers
-
Web Servers
-
DNS/DHCP Servers
-
Hyper-V Hosts
-
πΉ Windows Server (Desktop Experience)
-
Full GUI Version (Similar to Windows 10/11 interface)
-
Easier to Manage (For admins less comfortable with CLI)
-
Supports More Applications (e.g., Microsoft SCVMM, SharePoint)
-
More Resource-Intensive (Consumes more CPU, RAM, and disk space)
-
Best For:
-
Admins who need GUI-based management
-
Servers running applications requiring GUI
-
πΉ Key Differences
| Feature/Application | Server Core | Desktop Experience |
|---|---|---|
| Command Prompt | β Available | β Available |
| PowerShell | β Available | β Available |
| Registry Editor (Regedit) | β Available | β Available |
| Task Manager | β Available | β Available |
| Windows Explorer | β Not Available | β Available |
| Server Manager | β Not Available | β Available |
| Control Panel | β Not Available | β Available |
| MMC (Microsoft Management Console) | β Not Available | β Available |
| Event Viewer (Eventvwr) | β Not Available | β Available |
| Disk Management (diskmgmt.msc) | β Not Available | β Available |
| Internet Explorer/Edge | β Not Available | β Available |
| Remote Desktop Services | β Available | β Available |
When to Choose Server Core vs. Desktop Experience?¶
β Use Server Core if:
-
You need a lightweight, secure, and efficient server.
-
The server will run without requiring a GUI for daily tasks.
-
You are comfortable managing it via PowerShell or remote tools.
β Use Desktop Experience if:
-
You require GUI-based management.
-
The server must run applications that depend on GUI components.
-
You are administering it locally rather than remotely.
πΉ Important Note: Since Windows Server 2019, you must choose between Server Core or Desktop Experience at installation, and it cannot be changed later.
Summary of Windows Security¶
Windows security is essential due to its large attack surface, built-in features that can be abused, and historical vulnerabilities. Microsoft has continually improved Windows security by adding features that help system administrators harden systems and detect attacks.
Key Security Principles¶
-
Windows controls access and authentication using Security Identifiers (SIDs), which uniquely identify users, groups, or processes.
-
Security Accounts Manager (SAM) and Access Control Lists (ACLs) manage permissions, defining which users or processes can access files or execute tasks.
-
User Account Control (UAC) prevents unauthorized software installations by requiring user confirmation before executing administrative actions.
Windows Registry¶
-
A hierarchical database storing system and application settings, divided into HKEY root keys (e.g., HKLM, HKCU).
-
Registry values include REG_DWORD, REG_SZ, REG_BINARY, and others, defining different data types.
-
System-wide registry settings are stored in C:\Windows\System32\Config, while user-specific settings are in C:\Users
\Ntuser.dat .
Windows security relies on authentication mechanisms, access control, and system configurations to prevent unauthorized access and protect against cyber threats.