المختبر 6.1: تحليل شبكة ويندوز
الأهداف التعليمية
في نهاية هذا المختبر، ستكون قادرًا على:
- تحليل الاتصالات الشبكية النشطة
- تحديد العمليات التي تتواصل عبر الشبكة
- اكتشاف الاتصالات المشبوهة
- استخدام أدوات شبكة ويندوز
المدة المقدرة
45 دقيقة
المتطلبات المسبقة
- جهاز افتراضي ويندوز 10/11
- حقوق المسؤول
- معرفة أساسية بالشبكات
السياق المهني
تحليل الشبكة ضروري لـ:
- اكتشاف التسللات
- تحديد البرمجيات الخبيثة
- تدقيق الأمان
- استكشاف الأخطاء وإصلاحها
الجزء 1: الأوامر الأساسية
الخطوة 1.1: netstat
:: الاتصالات القائمة
netstat -an | findstr ESTABLISHED
:: مع معرف العملية
netstat -ano
:: مع أسماء العمليات (يتطلب صلاحيات المسؤول)
netstat -anob
:: إحصائيات حسب البروتوكول
netstat -s
الخطوة 1.2: PowerShell الحديث
# اتصالات TCP
Get-NetTCPConnection
# الاتصالات القائمة فقط
Get-NetTCPConnection -State Established
# مع تفاصيل العملية
Get-NetTCPConnection -State Established |
Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort,
@{N='Process';E={(Get-Process -Id $_.OwningProcess).Name}}, OwningProcess |
Format-Table -AutoSize
# اتصالات UDP
Get-NetUDPEndpoint
الخطوة 1.3: المنافذ المستمعة
# منافذ TCP المستمعة
Get-NetTCPConnection -State Listen |
Select-Object LocalAddress, LocalPort,
@{N='Process';E={(Get-Process -Id $_.OwningProcess).Name}} |
Sort-Object LocalPort
# التحقق من منفذ محدد
Get-NetTCPConnection -LocalPort 445
السؤال 1: ما هي المنافذ المستمعة على نظامك؟
الجزء 2: تحليل العمليات الشبكية
الخطوة 2.1: تحديد العمليات
# العمليات مع الاتصالات الشبكية
$connections = Get-NetTCPConnection -State Established
$processes = $connections | ForEach-Object {
$proc = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
[PSCustomObject]@{
Process = $proc.Name
PID = $_.OwningProcess
LocalPort = $_.LocalPort
RemoteAddress = $_.RemoteAddress
RemotePort = $_.RemotePort
Path = $proc.Path
}
}
$processes | Format-Table -AutoSize
الخطوة 2.2: التجميع حسب العملية
# عدد الاتصالات لكل عملية
Get-NetTCPConnection -State Established |
Group-Object OwningProcess |
ForEach-Object {
$proc = Get-Process -Id $_.Name -ErrorAction SilentlyContinue
[PSCustomObject]@{
Process = $proc.Name
Connections = $_.Count
Path = $proc.Path
}
} | Sort-Object Connections -Descending
الخطوة 2.3: العمليات المشبوهة
# العمليات غير النظامية مع الاتصالات
$systemPaths = @("C:\Windows", "C:\Program Files", "C:\Program Files (x86)")
Get-NetTCPConnection -State Established | ForEach-Object {
$proc = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
if ($proc.Path) {
$isSystem = $false
foreach ($path in $systemPaths) {
if ($proc.Path -like "$path*") { $isSystem = $true; break }
}
if (-not $isSystem) {
[PSCustomObject]@{
Process = $proc.Name
Remote = "$($_.RemoteAddress):$($_.RemotePort)"
Path = $proc.Path
}
}
}
} | Format-Table -AutoSize
السؤال 2: هل هناك عمليات غير نظامية مع اتصالات شبكية؟
الجزء 3: اكتشاف الاتصالات المشبوهة
الخطوة 3.1: المنافذ المشبوهة
# المنافذ التي غالبًا ما تستخدمها البرمجيات الخبيثة/C2
$suspectPorts = @(4444, 5555, 6666, 1337, 31337, 8080, 8443, 9999)
$suspectConnections = Get-NetTCPConnection | Where-Object {
$_.RemotePort -in $suspectPorts -or $_.LocalPort -in $suspectPorts
}
if ($suspectConnections) {
Write-Host "[ALERTE] Connexions sur ports suspects:" -ForegroundColor Red
$suspectConnections | Select-Object LocalPort, RemoteAddress, RemotePort, State,
@{N='Process';E={(Get-Process -Id $_.OwningProcess).Name}} |
Format-Table -AutoSize
} else {
Write-Host "[OK] Aucune connexion sur ports suspects" -ForegroundColor Green
}
الخطوة 3.2: الاتصالات إلى دول ذات مخاطر
# ملاحظة: يتطلب قاعدة بيانات GeoIP ليكون دقيقًا
# هنا نكتشف عناوين IP غير RFC1918 (العامة)
$publicConnections = Get-NetTCPConnection -State Established | Where-Object {
$ip = $_.RemoteAddress
$ip -notmatch "^(10\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.|127\.|::1|0\.0\.0\.0)"
}
Write-Host "Connexions vers IPs publiques:" -ForegroundColor Yellow
$publicConnections | Select-Object RemoteAddress, RemotePort,
@{N='Process';E={(Get-Process -Id $_.OwningProcess).Name}} |
Format-Table -AutoSize
الخطوة 3.3: سكريبت الكشف الكامل
# سكريبت الكشف عن الاتصالات المشبوهة
Write-Host "=== ANALYSE RESEAU SECURITE ===" -ForegroundColor Cyan
$alerts = @()
# 1. المنافذ المشبوهة
$suspectPorts = @(4444, 5555, 6666, 1337, 31337, 8080, 8443, 9999, 1234)
Get-NetTCPConnection | Where-Object {
$_.RemotePort -in $suspectPorts -or $_.LocalPort -in $suspectPorts
} | ForEach-Object {
$alerts += [PSCustomObject]@{
Type = "Port Suspect"
Detail = "Port $($_.RemotePort) ou $($_.LocalPort)"
Remote = $_.RemoteAddress
Process = (Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue).Name
}
}
# 2. العمليات غير المعتادة مع الشبكة
$normalNetworkProcs = @("svchost", "System", "chrome", "firefox", "msedge",
"explorer", "OneDrive", "Teams", "Outlook", "Code")
Get-NetTCPConnection -State Established | ForEach-Object {
$proc = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue
if ($proc.Name -notin $normalNetworkProcs -and $proc.Name) {
$alerts += [PSCustomObject]@{
Type = "Processus Inhabituel"
Detail = $proc.Name
Remote = "$($_.RemoteAddress):$($_.RemotePort)"
Process = $proc.Name
}
}
}
# 3. PowerShell مع الاتصالات
Get-NetTCPConnection -State Established | Where-Object {
(Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue).Name -eq "powershell"
} | ForEach-Object {
$alerts += [PSCustomObject]@{
Type = "PowerShell Reseau"
Detail = "PowerShell a des connexions actives"
Remote = "$($_.RemoteAddress):$($_.RemotePort)"
Process = "powershell"
}
}
# تقرير
Write-Host "`n=== RESULTATS ===" -ForegroundColor Yellow
if ($alerts.Count -eq 0) {
Write-Host "[OK] Aucune anomalie detectee" -ForegroundColor Green
} else {
Write-Host "[!] $($alerts.Count) anomalie(s) detectee(s):" -ForegroundColor Red
$alerts | Format-Table -AutoSize
}
# ملخص
Write-Host "`n=== STATISTIQUES ===" -ForegroundColor Cyan
$established = (Get-NetTCPConnection -State Established).Count
$listening = (Get-NetTCPConnection -State Listen).Count
Write-Host "Connexions etablies: $established"
Write-Host "Ports en ecoute: $listening"
الجزء 4: إعداد الجدار الناري
الخطوة 4.1: حالة الجدار الناري
# حالة الملفات الشخصية
Get-NetFirewallProfile | Select-Object Name, Enabled
# القواعد النشطة (الواردة)
Get-NetFirewallRule -Direction Inbound -Enabled True |
Select-Object DisplayName, Action, Profile |
Format-Table -AutoSize
الخطوة 4.2: القواعد لمنفذ
# القواعد للمنفذ 445 (SMB)
Get-NetFirewallPortFilter -Protocol TCP | Where-Object LocalPort -eq 445 |
Get-NetFirewallRule |
Select-Object DisplayName, Enabled, Action
الخطوة 4.3: إنشاء قاعدة حظر
# حظر الاتصالات الصادرة على منفذ مشبوه
New-NetFirewallRule -DisplayName "Block Suspicious Port 4444" `
-Direction Outbound `
-LocalPort 4444 `
-Protocol TCP `
-Action Block
# التحقق
Get-NetFirewallRule -DisplayName "Block Suspicious*"
# الحذف (بعد المختبر)
# Remove-NetFirewallRule -DisplayName "Block Suspicious Port 4444"
الجزء 5: تمرين عملي
الخطوة 5.1: تدقيق شبكة كامل
قم بإنشاء سكريبت audit_reseau.ps1:
# تدقيق شبكة كامل
$report = @()
Write-Host "=== AUDIT RESEAU ===" -ForegroundColor Cyan
Write-Host "Date: $(Get-Date)"
Write-Host ""
# 1. واجهات الشبكة
Write-Host "[1/4] واجهات الشبكة..." -ForegroundColor Yellow
Get-NetAdapter | Where-Object Status -eq "Up" |
Select-Object Name, InterfaceDescription, LinkSpeed |
Format-Table -AutoSize
# 2. إعدادات IP
Write-Host "[2/4] إعدادات IP..." -ForegroundColor Yellow
Get-NetIPAddress -AddressFamily IPv4 |
Where-Object {$_.IPAddress -ne "127.0.0.1"} |
Select-Object InterfaceAlias, IPAddress, PrefixLength |
Format-Table -AutoSize
# 3. المنافذ المستمعة
Write-Host "[3/4] المنافذ المستمعة..." -ForegroundColor Yellow
Get-NetTCPConnection -State Listen |
Select-Object LocalPort, @{N='Process';E={(Get-Process -Id $_.OwningProcess).Name}} |
Sort-Object LocalPort -Unique |
Format-Table -AutoSize
# 4. الاتصالات القائمة
Write-Host "[4/4] أفضل 10 اتصالات..." -ForegroundColor Yellow
Get-NetTCPConnection -State Established |
Select-Object -First 10 LocalPort, RemoteAddress, RemotePort,
@{N='Process';E={(Get-Process -Id $_.OwningProcess).Name}} |
Format-Table -AutoSize
Write-Host "`n=== FIN AUDIT ===" -ForegroundColor Cyan
التسليمات
-
الإجابات على السؤالين
-
لقطات شاشة:
- قائمة الاتصالات القائمة
- المنافذ المستمعة
- تنفيذ سكريبت الكشف
-
سكريبت التدقيق المخصص
-
تقرير (صفحة واحدة):
- الاتصالات المحددة
- الشذوذات المكتشفة
- التوصيات
معايير التقييم
| المعيار | النقاط |
|---|---|
| الأوامر الأساسية | 20% |
| تحليل العمليات | 25% |
| اكتشاف المشبوهات | 30% |
| سكريبت التدقيق | 25% |
أوامر مرجعية
# الاتصالات
Get-NetTCPConnection
Get-NetUDPEndpoint
netstat -ano
# التصفية
-State Established, Listen
-LocalPort 443
-RemotePort 80
# الجدار الناري
Get-NetFirewallProfile
Get-NetFirewallRule
New-NetFirewallRule
تم تطوير المختبر في إطار دورة أنظمة التشغيل - الوحدة 6