boylnwzav1/asitheboy / security-hardening.ps1
boylnwzav1's picture
download
raw
13.7 kB
# ============================================================
# 🔒 HARDENING SCRIPT - ป้องกันภัยจากอุปกรณ์ภายนอก
# ============================================================
# สคริปต์นี้จะ:
# 1. บล็อก USB Storage Devices
# 2. ปิด Autorun/AutoPlay
# 3. ตั้งค่า Firewall บล็อกการเชื่อมต่อที่ไม่จำเป็น
# 4. ปิด Bluetooth และอุปกรณ์ภายนอก
# 5. เปิด Windows Defender แบบสูงสุด
# ============================================================
# ตรวจสอบว่ารันเป็น Administrator
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "[ERROR] กรุณารันสคริปต์นี้เป็น Administrator (คลิกขวา -> Run as Administrator)" -ForegroundColor Red
exit 1
}
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host " 🔒 เริ่มตั้งค่าความปลอดภัย" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
# ============================================================
# 1. บล็อก USB Storage Devices
# ============================================================
Write-Host "[1/5] กำลังบล็อก USB Storage Devices..." -ForegroundColor Yellow
# บล็อก USB Storage ผ่าน Registry
$usbStoragePath = "HKLM:\SYSTEM\CurrentControlSet\Services\USBSTOR"
if (Test-Path $usbStoragePath) {
Set-ItemProperty -Path $usbStoragePath -Name "Start" -Value 4 -Force
Write-Host " [+] บล็อก USBSTOR driver สำเร็จ" -ForegroundColor Green
} else {
Write-Host " [-] ไม่พบ USBSTOR registry path" -ForegroundColor Gray
}
# บล็อกการติดตั้ง USB Storage ใหม่ผ่าน Group Policy
$removableStoragePath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\RemovableStorageDevices"
if (-not (Test-Path $removableStoragePath)) {
New-Item -Path $removableStoragePath -Force | Out-Null
}
Set-ItemProperty -Path $removableStoragePath -Name "Deny_Read" -Value 1 -Type DWord -Force
Set-ItemProperty -Path $removableStoragePath -Name "Deny_Write" -Value 1 -Type DWord -Force
Set-ItemProperty -Path $removableStoragePath -Name "Deny_Execute" -Value 1 -Type DWord -Force
Set-ItemProperty -Path $removableStoragePath -Name "Deny_All" -Value 1 -Type DWord -Force
Write-Host " [+] บล็อกการอ่าน/เขียน/รัน จาก removable storage สำเร็จ" -ForegroundColor Green
# ============================================================
# 2. ปิด Autorun / AutoPlay
# ============================================================
Write-Host "`n[2/5] กำลังปิด Autorun/AutoPlay..." -ForegroundColor Yellow
$autoplayPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer"
if (-not (Test-Path $autoplayPath)) {
New-Item -Path $autoplayPath -Force | Out-Null
}
Set-ItemProperty -Path $autoplayPath -Name "NoDriveTypeAutoRun" -Value 0xFF -Type DWord -Force
Set-ItemProperty -Path $autoplayPath -Name "NoAutorun" -Value 1 -Type DWord -Force
Write-Host " [+] ปิด AutoPlay สำเร็จ" -ForegroundColor Green
# ปิด AutoPlay สำหรับทุก drive
$autoplayPolicyPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer"
if (-not (Test-Path $autoplayPolicyPath)) {
New-Item -Path $autoplayPolicyPath -Force | Out-Null
}
Set-ItemProperty -Path $autoplayPolicyPath -Name "NoAutoplayfornonVolume" -Value 1 -Type DWord -Force
Write-Host " [+] ปิด AutoPlay สำหรับ non-volume devices สำเร็จ" -ForegroundColor Green
# ============================================================
# 3. ตั้งค่า Windows Firewall - บล็อกการเชื่อมต่อภายนอก
# ============================================================
Write-Host "`n[3/5] กำลังตั้งค่า Windows Firewall..." -ForegroundColor Yellow
# เปิด Windows Firewall ทุก profile
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True
Write-Host " [+] เปิด Firewall ทุก profile สำเร็จ" -ForegroundColor Green
# ตั้งค่า default policy: บล็อกขาเข้าทั้งหมด, อนุญาตขาออก (หรือบล็อกถ้าต้องการ)
Set-NetFirewallProfile -Profile Domain,Public,Private `
-DefaultInboundAction Block `
-DefaultOutboundAction Allow `
-AllowUnicastResponseToMulticast False `
-AllowInboundRules True `
-AllowLocalFirewallRules True `
-AllowLocalIPsecRules True
Write-Host " [+] ตั้งค่า Default Inbound = BLOCK สำเร็จ" -ForegroundColor Green
# ปิด ICMP (ป้องกัน ping scan)
New-NetFirewallRule -DisplayName "Block ICMPv4-In" -Direction Inbound -Protocol ICMPv4 -Action Block -Profile Any | Out-Null
New-NetFirewallRule -DisplayName "Block ICMPv6-In" -Direction Inbound -Protocol ICMPv6 -Action Block -Profile Any | Out-Null
Write-Host " [+] บล็อก ICMP (ป้องกัน ping scan) สำเร็จ" -ForegroundColor Green
# บล็อกพอร์ตที่มักถูกโจมตี
$dangerousPorts = @(
@{Port=135; Name="Block RPC/DCOM (135)"},
@{Port=137; Name="Block NetBIOS Name (137)"},
@{Port=138; Name="Block NetBIOS Datagram (138)"},
@{Port=139; Name="Block NetBIOS Session (139)"},
@{Port=445; Name="Block SMB (445)"},
@{Port=3389; Name="Block RDP (3389)"},
@{Port=5900; Name="Block VNC (5900)"},
@{Port=23; Name="Block Telnet (23)"},
@{Port=21; Name="Block FTP (21)"}
)
foreach ($port in $dangerousPorts) {
$existing = Get-NetFirewallRule -DisplayName $port.Name -ErrorAction SilentlyContinue
if (-not $existing) {
New-NetFirewallRule -DisplayName $port.Name -Direction Inbound -Protocol TCP -LocalPort $port.Port -Action Block -Profile Any | Out-Null
}
}
Write-Host " [+] บล็อกพอร์ตอันตราย (135,137-139,445,3389,5900,23,21) สำเร็จ" -ForegroundColor Green
# ============================================================
# 4. ปิด Bluetooth และอุปกรณ์ภายนอก
# ============================================================
Write-Host "`n[4/5] กำลังปิด Bluetooth และอุปกรณ์ภายนอก..." -ForegroundColor Yellow
# ปิด Bluetooth Service
$btServices = @("bthserv", "BluetoothUserService")
foreach ($svc in $btServices) {
$service = Get-Service -Name $svc -ErrorAction SilentlyContinue
if ($service) {
Stop-Service -Name $svc -Force -ErrorAction SilentlyContinue
Set-Service -Name $svc -StartupType Disabled -ErrorAction SilentlyContinue
Write-Host " [+] ปิด service: $svc สำเร็จ" -ForegroundColor Green
}
}
# ปิด Bluetooth ผ่าน Registry
$btPath = "HKLM:\SYSTEM\CurrentControlSet\Services\BTHUSB"
if (Test-Path $btPath) {
Set-ItemProperty -Path $btPath -Name "Start" -Value 4 -Force
Write-Host " [+] บล็อก Bluetooth USB driver สำเร็จ" -ForegroundColor Green
}
# ปิด Remote Registry
$remoteReg = Get-Service -Name "RemoteRegistry" -ErrorAction SilentlyContinue
if ($remoteReg) {
Stop-Service -Name "RemoteRegistry" -Force -ErrorAction SilentlyContinue
Set-Service -Name "RemoteRegistry" -StartupType Disabled
Write-Host " [+] ปิด Remote Registry สำเร็จ" -ForegroundColor Green
}
# ปิด Remote Desktop
$rdpPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server"
if (Test-Path $rdpPath) {
Set-ItemProperty -Path $rdpPath -Name "fDenyTSConnections" -Value 1 -Force
Write-Host " [+] ปิด Remote Desktop สำเร็จ" -ForegroundColor Green
}
# ปิด不必要的 network services
$disableServices = @(
"SSDPSRV", # SSDP Discovery (UPnP)
"upnphost", # UPnP Device Host
"lmhosts", # TCP/IP NetBIOS Helper
"Fax", # Fax Service
"TabletInputService", # Touch Keyboard (ถ้าไม่ใช้)
"WMPNetworkSvc" # Windows Media Player Network Sharing
)
foreach ($svc in $disableServices) {
$service = Get-Service -Name $svc -ErrorAction SilentlyContinue
if ($service -and $service.Status -eq "Running") {
Stop-Service -Name $svc -Force -ErrorAction SilentlyContinue
Set-Service -Name $svc -StartupType Disabled -ErrorAction SilentlyContinue
Write-Host " [+] ปิด service: $svc สำเร็จ" -ForegroundColor Green
}
}
# ============================================================
# 5. เปิด Windows Defender แบบสูงสุด
# ============================================================
Write-Host "`n[5/5] กำลังตั้งค่า Windows Defender..." -ForegroundColor Yellow
# เปิด Real-time Protection
Set-MpPreference -DisableRealtimeMonitoring $false
Write-Host " [+] เปิด Real-time Protection สำเร็จ" -ForegroundColor Green
# เปิด Cloud-delivered Protection
Set-MpPreference -MAPSReporting Advanced
Write-Host " [+] เปิด Cloud-delivered Protection สำเร็จ" -ForegroundColor Green
# เปิด Behavior Monitoring
Set-MpPreference -DisableBehaviorMonitoring $false
Write-Host " [+] เปิด Behavior Monitoring สำเร็จ" -ForegroundColor Green
# เปิด PUA Protection
Set-MpPreference -PUAProtection Enabled
Write-Host " [+] เปิด PUA (Potentially Unwanted App) Protection สำเร็จ" -ForegroundColor Green
# เปิด Controlled Folder Access (ป้องกัน ransomware)
Set-MpPreference -EnableControlledFolderAccess Enabled
Write-Host " [+] เปิด Controlled Folder Access (ป้องกัน ransomware) สำเร็จ" -ForegroundColor Green
# เปิด Network Protection
Set-MpPreference -EnableNetworkProtection Enabled
Write-Host " [+] เปิด Network Protection สำเร็จ" -ForegroundColor Green
# เปิด Scan Removable Drives
Set-MpPreference -DisableRemovableDriveScanning $false
Write-Host " [+] เปิดสแกน Removable Drives สำเร็จ" -ForegroundColor Green
# เปิด Scan Downloads
Set-MpPreference -DisableScanningMappedNetworkDrivesForFullScan $false
Set-MpPreference -DisableScanningNetworkFiles $false
Write-Host " [+] เปิดสแกน network files สำเร็จ" -ForegroundColor Green
# ตั้งค่าให้ update signature อัตโนมัติ
Set-MpPreference -SignatureDisableUpdateOnStartupWithoutEngine $false
Write-Host " [+] เปิด signature auto-update สำเร็จ" -ForegroundColor Green
# ============================================================
# สรุปผล
# ============================================================
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host " ✅ เสร็จสิ้นการตั้งค่าความปลอดภัย!" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
Write-Host "สรุปสิ่งที่ทำ:" -ForegroundColor White
Write-Host " ✅ บล็อก USB Storage Devices ทั้งหมด" -ForegroundColor Green
Write-Host " ✅ ปิด Autorun/AutoPlay ทุกประเภท" -ForegroundColor Green
Write-Host " ✅ Firewall: บล็อกขาเข้าทั้งหมด, บล็อกพอร์ตอันตราย" -ForegroundColor Green
Write-Host " ✅ ปิด Bluetooth, Remote Desktop, Remote Registry" -ForegroundColor Green
Write-Host " ✅ ปิด UPnP, SSDP, NetBIOS services" -ForegroundColor Green
Write-Host " ✅ Windows Defender: เปิดทุกฟีเจอร์ป้องกัน" -ForegroundColor Green
Write-Host " ✅ เปิดป้องกัน ransomware (Controlled Folder Access)" -ForegroundColor Green
Write-Host "`n⚠️ หมายเหตุ:" -ForegroundColor Yellow
Write-Host " - หากต้องการใช้ USB อีกครั้ง ให้เปลี่ยน USBSTOR 'Start' กลับเป็น 3" -ForegroundColor Gray
Write-Host " - หากต้องการเปิด Remote Desktop ให้เปลี่ยน fDenyTSConnections เป็น 0" -ForegroundColor Gray
Write-Host " - แนะนำให้รีสตาร์ทเครื่องเพื่อให้การตั้งค่ามีผลเต็มที่" -ForegroundColor Gray
Write-Host "`nต้องการรีสตาร์ทเครื่องตอนนี้หรือไม่? (Y/N): " -ForegroundColor Yellow -NoNewline
$response = Read-Host
if ($response -eq "Y" -or $response -eq "y") {
Write-Host "กำลังรีสตาร์ทใน 5 วินาที..." -ForegroundColor Yellow
Start-Sleep -Seconds 5
Restart-Computer
} else {
Write-Host "กรุณารีสตาร์ทเครื่องด้วยตัวเองเพื่อให้การตั้งค่ามีผลเต็มที่" -ForegroundColor Cyan
}

Xet Storage Details

Size:
13.7 kB
·
Xet hash:
df3538149808ee2458955621521b296952e647217149508d804bf2c1536afd77

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.