Back

Cyber Security: เรียนรู้ Brute Force AttackBlur image

1. ขอนแนะนำ Brute Force Attack#

ยินดีต้อนรับสู่ ห้องปฏิบัติการ Brute Force Attack! ต่อยอดจากพื้นฐาน Linux Security Lab ตอนนี้จะได้เรียนรู้หนึ่งในเทคนิคการโจมตี web application ที่พื้นฐานที่สุด

ข้อกำหนดเบื้องต้น#

ก่อนเริ่มห้องปฏิบัติการนี้ ควรมี:

  • ติดตั้ง Ubuntu VM - VirtualBox ที่ติดตั้ง Ubuntu แล้ว
  • พื้นฐานคำสั่ง Linux - ความเข้าใจเกี่ยวกับคำสั่ง terminal
  • ความรู้เรื่อง SSH - วิธีการเชื่อมต่อไปยัง VM จากระยะไกล

📚 ใหม่กับ Linux? หากยังไม่ได้ติดตั้ง Ubuntu VM หรือต้องการทบทวนคำสั่ง Linux ดู Linux Security Lab Tutorial สำหรับคำแนะนำการติดตั้ง Ubuntu และพื้นฐาน command-line อย่างครอบคลุม

Brute Force Attack คืออะไร?#

Brute Force Attack คือวิธีการลองผิดลองถูกที่ใช้เพื่อรับข้อมูล เช่น รหัสผ่านผู้ใช้ หรือ personal identification number (PIN) แฮกเกอร์ตรวจสอบรหัสผ่านและ passphrase ที่เป็นไปได้ทั้งหมดอย่างเป็นระบบจนกว่าจะพบรหัสที่ถูกต้อง

Password attempts in a brute force attack:
password1 ผิด
password123 ผิด
admin123 ผิด
letmein ผิด
password สำเร็จ
bash

Brute Force Attack ทำงานอย่างไร#

Brute Force Attack Flow

ตัวอย่างเวลาในการถอดรหัส#

ความซับซ้อนของรหัสผ่านจำนวนตัวอักษรเวลาในการถอดรหัส (1000 ครั้ง/วินาที)
12344 ตัวเลข~10 วินาที
password8 ตัวพิมพ์เล็ก~2 ชั่วโมง
Password18 ผสม~3 วัน
P@ssw0rd!8 พร้อมสัญลักษณ์~5 เดือน
MySecur3P@ss!14 พร้อมสัญลักษณ์~400 ล้านปี

ข้อควรรู้: ความยาวและความซับซ้อนของรหัสผ่านจะเพิ่มเวลาในการถอดรหัสอย่างมหาศาล!


2. ประเภทของ Brute Force Attack#

Simple Brute Force#

ผู้โจมตีลองการผสมที่เป็นไปได้ทั้งหมดอย่างเป็นระบบ

a, b, c, ..., z
aa, ab, ac, ..., zz
aaa, aab, aac, ...
bash

ข้อดี: รับประกันว่าจะพบรหัสผ่านในท้ายที่สุด
ข้อเสีย: ใช้เวลานานมากสำหรับรหัสผ่านที่ซับซ้อน

Dictionary Attack#

ใช้รายการรหัสผ่านที่ใช้บ่อย (wordlist)

# ตัวอย่างรายการรหัสผ่านทั่วไป:
password
123456
admin
qwerty
letmein
welcome
bash

ข้อดี: เร็วกว่า simple brute force
ข้อเสีย: มีประสิทธิภาพเฉพาะกับรหัสผ่านที่อ่อนแอ

Hybrid Attack#

ผสมคำใน dictionary กับรูปแบบ

password password1, password123, password!
admin admin1, Admin2024, admin@2024
bash

ข้อดี: มีประสิทธิภาพกับรหัสผ่านที่มีรูปแบบ
ข้อเสีย: ยังคงต้องการเวลาและพลังการประมวลผล

Credential Stuffing#

ใช้คู่ username/password ที่รั่วไหลจาก data breach

ข้อดี: อัตราความสำเร็จสูงเนื่องจากการนำรหัสผ่านกลับมาใช้ใหม่
ข้อเสีย: ต้องมีการเข้าถึงฐานข้อมูล breach


3. การป้องกัน Brute Force Attack#

กลยุทธ์การป้องกัน#

Brute Force Defense Flow

เทคนิคการป้องกัน#

1. ใช้รหัสผ่านที่แข็งแกร่งและซับซ้อน#

สร้างรหัสผ่านที่:

  • ยาว: อย่างน้อย 12-16 ตัวอักษร
  • ผสม: ตัวพิมพ์ใหญ่ ตัวพิมพ์เล็ก ตัวเลข สัญลักษณ์
  • ไม่ซ้ำ: ต่างกันสำหรับแต่ละบัญชี
  • คาดเดาไม่ได้: ไม่มีคำใน dictionary หรือรูปแบบ
 ไม่ดี:     password123
 ไม่ดี:     admin2024
 ไม่ดี:     qwerty123

 ดี:    Tr0ub4dor&3Horse!
 ดีกว่า:  correct-horse-battery-staple (passphrase)
 ดีที่สุด:    ใช้ password manager!
bash

2. จำกัดการพยายาม Login#

จำกัดจำนวนการพยายาม login ที่อนุญาตในช่วงเวลาหนึ่ง

# ตัวอย่าง rate limiting logic
if failed_attempts > 5:
    block_ip_address()
    wait_time = 2^failed_attempts  # Exponential backoff
python

วิธีการนำไปใช้:

  • หน่วงเวลาระหว่างการพยายาม
  • บล็อก IP ชั่วคราวหลังจากล้มเหลว
  • CAPTCHA หลังจากล้มเหลวหลายครั้ง
  • หน่วงเวลาแบบก้าวหน้า (1s, 2s, 4s, 8s…)

3. เปิดใช้งาน Two-Factor Authentication (2FA)#

ต้องการการตรวจสอบเพิ่มเติมนอกเหนือจากรหัสผ่าน

ปัจจัยที่ 1: สิ่งที่รู้ รหัสผ่าน
ปัจจัยที่ 2: สิ่งที่มี โทรศัพท์/Token
ปัจจัยที่ 3: สิ่งที่เป็น Biometric
bash

วิธีการ 2FA:

  • SMS OTP (One-Time Password)
  • Authentication app (Google Authenticator, Authy)
  • Hardware token (YubiKey)
  • Biometric verification

4. นโยบายการล็อคบัญชี#

ล็อคบัญชีอัตโนมัติหลังจากพยายามล้มเหลวซ้ำๆ

การพยายามล้มเหลวการดำเนินการ
3-5เตือน + หน่วงเวลา
5-10ล็อคชั่วคราว (15-30 นาที)
10+ล็อคนานขึ้น + แจ้งผู้ดูแล

คำเตือน: การล็อคบัญชีอาจนำไปสู่ DoS หากผู้โจมตีล็อคผู้ใช้ทั้งหมด

5. ตรวจสอบและแจ้งเตือน#

บันทึกกิจกรรมที่น่าสงสัยและส่งการแจ้งเตือน

# เหตุการณ์ที่ต้องแจ้งเตือน
- การ login ล้มเหลวหลายครั้งจาก IP เดียวกัน
- การ login จากตำแหน่งภูมิศาสตร์ที่ผิดปกติ
- การ login ในเวลาที่ผิดปกติ
- การพยายาม login พร้อมกันจาก IP ต่างกัน
bash

4. Lab Setup - DVWA Installation#

ตอนนี้มาตั้งค่าห้องปฏิบัติการจริงโดยใช้ DVWA (Damn Vulnerable Web Application) - เว็บแอปพลิเคชันที่ออกแบบมาให้มีความปลอดภัยต่ำโดยเจตนา เพื่อใช้สำหรับการฝึกอบรมด้านความปลอดภัย

ข้อกำหนดเบื้องต้น#

  • Ubuntu Linux VM จากบทที่ 1
  • Firefox browser ที่ติดตั้งบน Ubuntu
  • การเชื่อมต่ออินเทอร์เน็ตบน VM

Exercise 4: เริ่มต้น Ubuntu VM#

ใน VirtualBox ดับเบิลคลิกที่ Ubuntu Linux VM เพื่อเริ่มต้น

SSH Access สำหรับการคัดลอกคำสั่งที่ง่ายขึ้น#

💡 Pro Tip: การใช้ SSH จาก host machine ทำให้คัดลอกคำสั่งจากบทความนี้ได้ง่ายขึ้นมาก!

ทำไมต้องใช้ SSH?

เมื่อทำงานกับบทความบนเว็บ การสลับระหว่าง browser (อ่าน) และ VM terminal (พิมพ์) เป็นเรื่องที่ยุ่งยาก SSH ช่วยให้อ่านบทความบน host machine และ execute คำสั่งใน Ubuntu VM ได้โดยตรง

Host Machine (Browser)          SSH Connection           Ubuntu VM
┌──────────────────┐            ┌──────────────┐         ┌──────────────┐
 Reading tutorial ─────────► Port 2222 ──────► Execute cmd
 Copy command
└──────────────────┘            └──────────────┘         └──────────────┘
bash

ข้อดี:

  • ✅ Copy-paste คำสั่งโดยตรงจาก browser
  • ✅ อ่านบทความบนหน้าจอ host machine ที่ใหญ่กว่า
  • ✅ เก็บ browser และ terminal ไว้ในหน้าต่างแยกกัน
  • ✅ ไม่ต้องสลับระหว่าง VM windows

ตรวจสอบ SSH Access#

จากบทที่ 1 ควรได้ตั้งค่า SSH แล้ว มาตรวจสอบว่าทำงานอยู่

ตรวจสอบว่า SSH กำลังทำงาน:

sudo service ssh status
bash

ผลลัพธ์ที่คาดหวัง:

 ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/usr/systemd/system/ssh.service; enabled)
     Active: active (running)
bash

หากไม่ทำงาน ให้เริ่มต้น:

sudo service ssh start
bash

เปิดใช้งาน SSH ให้เริ่มต้นอัตโนมัติหลังจาก reboot:

sudo systemctl enable ssh
bash

ผลลัพธ์ที่คาดหวัง:

Synchronizing state of ssh.service with SysV service script...
Executing /lib/systemd/systemd-sysv-install enable ssh
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service /lib/systemd/system/ssh.service.
bash

เชื่อมต่อจาก Host Machine#

บน Windows (Command Prompt หรือ PowerShell):

ssh -p 2222 your_username@localhost
cmd

บน macOS หรือ Linux (Terminal):

ssh -p 2222 your_username@localhost
bash

แทนที่ your_username ด้วย Ubuntu username (เช่น u6090059)

ใส่ Ubuntu password เมื่อถูกถาม

ตัวบ่งชี้ความสำเร็จ: Prompt เปลี่ยนเป็น:

your_username@your_hostname:~$
bash

SSH Connection

Quick SSH Reference#

TaskCommand
Connect to VMssh -p 2222 user@localhost
Exit SSH sessionexit หรือ Ctrl + D
Copy from browserHighlight text, Ctrl + C
Paste in terminalCtrl + Shift + V (Linux) หรือ right-click paste

ทดสอบ SSH Connection#

เมื่อเชื่อมต่อผ่าน SSH แล้ว ลองคำสั่งเหล่านี้เพื่อตรวจสอบ:

pwd
whoami
uname -a
bash

ผลลัพธ์ที่คาดหวัง:

/home/your_username
your_username
Linux your_hostname 6.5.0-... #ubuntu SMP ...
bash

SSH Test Commands

🎯 จากนี้ไป คำสั่งทั้งหมดในบทความนี้จะถือว่าเชื่อมต่อผ่าน SSH! ช่วยให้ copy-paste คำสั่งจาก browser ไปยัง terminal ได้ง่าย

Exercise 5: ติดตั้ง DVWA#

อัปเดตระบบก่อน:

sudo apt update
sudo apt upgrade -y
bash

ติดตั้ง dependencies ที่จำเป็น:

sudo apt install -y apache2 mariadb-server php php-mysql php-gd libapache2-mod-php
bash

ตรวจสอบว่า Apache กำลังทำงาน:

sudo systemctl status apache2
bash

ผลลัพธ์ที่คาดหวัง:

 apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled)
     Active: active (running) since ...
bash

ทดสอบ Apache บน Firefox ใน VM:

เปิด Firefox ใน Ubuntu VM และไปที่: http://localhost

จะเห็น Apache2 Ubuntu Default Page ซึ่งบ่งชี้ว่า Apache ทำงานถูกต้อง

Apache Default Page

การเข้าใจ Apache Web Server#

Apache เป็น web server software ที่ให้บริการไฟล์ผ่าน HTTP เมื่อเข้าถึง http://localhost Apache จะมองหาไฟล์ใน /var/www/html/ และให้บริการไปยัง browser

วิธีการทำงานของ Apache:

Browser Request: http://localhost/test/

Apache receives request

Looks for: /var/www/html/test/index.html

Sends file back to browser
bash

Exercise: สร้าง Web Page แรก#

มาสร้าง HTML page แบบง่ายเพื่อเข้าใจวิธี Apache ให้บริการ content

สร้าง test directory:

sudo mkdir -p /var/www/html/test
bash

สร้าง HTML file โดยใช้ nano:

sudo nano /var/www/html/test/index.html
bash

เพิ่ม HTML content ดังนี้:

<!DOCTYPE html>
<html>
<head>
    <title>My Test Page</title>
</head>
<body>
    <h1>Hello World</h1>
    <p>This is my first web page on Apache!</p>
</body>
</html>
html

กด Ctrl + O, Enter จากนั้น Ctrl + X เพื่อบันทึกและออก

ตั้งค่า permissions ที่เหมาะสม:

sudo chown -R www-data:www-data /var/www/html/test
sudo chmod -R 755 /var/www/html/test
bash

ทดสอบ page ใน Firefox:

ใน Firefox (ใน Ubuntu VM) ไปที่: http://localhost/test/

จะเห็น page แบบง่ายที่มี “Hello World” heading และ text ด้านล่าง

Hello World Page

การเข้าใจสิ่งที่เกิดขึ้น:

  1. สร้าง /var/www/html/test/index.html
  2. Apache ให้บริการ index.html อัตโนมัติเมื่อเข้าถึง directory
  3. URL http://localhost/test/ map ไปยัง /var/www/html/test/
  4. Apache อ่าน HTML file และส่งไปยัง browser

💡 Key Concept: ใน web development URLs map ไปยัง file system เมื่อ deploy DVWA จะทำงานแบบเดียวกัน - http://10.0.2.15/dvwa/ map ไปยัง /var/www/html/dvwa/ แทนที่ 10.0.2.15 ด้วย IP address จริง

Download DVWA:

ติดตั้ง git ก่อน (หากยังไม่ได้ติดตั้ง):

sudo apt install git -y
bash

Clone DVWA repository:

cd /var/www/html
sudo git clone https://github.com/digininja/DVWA.git dvwa
sudo chown -R www-data:www-data /var/www/html/dvwa
bash

ตั้งค่า DVWA:

cd /var/www/html/dvwa/config
sudo cp config.inc.php.dist config.inc.php
sudo nano config.inc.php
bash

แก้ไขบรรทัดรหัสผ่าน database:

# หาบรรทัดนี้และแก้ไข:
$_DVWA[ 'db_password' ] = getenv('DB_PASSWORD') ?: 'p@ssw0rd';
php

กด Ctrl + O, Enter จากนั้น Ctrl + X เพื่อบันทึกและออก

ตั้งค่า permissions:

sudo chmod 666 /var/www/html/dvwa/hackable/uploads/
sudo chmod 666 /var/www/html/dvwa/config/config.inc.php
bash

เปิดใช้งาน PHP allow_url_include:

sudo nano /etc/php/8.3/apache2/php.ini
bash

ค้นหาการตั้งค่า:

กด Ctrl + W พิมพ์ allow_url_include และกด Enter เพื่อค้นหาบรรทัดนี้อย่างรวดเร็ว

เปลี่ยน:

allow_url_include = Off
ini

เป็น:

allow_url_include = On
ini

กด Ctrl + O, Enter จากนั้น Ctrl + X

รีสตาร์ท Apache:

sudo systemctl restart apache2
bash

สร้าง database และ user:

sudo mysql
bash

ใน MariaDB prompt:

CREATE DATABASE dvwa;
CREATE USER 'dvwa'@'localhost' IDENTIFIED BY 'p@ssw0rd';
GRANT ALL PRIVILEGES ON dvwa.* TO 'dvwa'@'localhost';
FLUSH PRIVILEGES;
EXIT;
sql

Note: MariaDB เป็น drop-in replacement สำหรับ MySQL ดังนั้น MySQL commands ทั้งหมดจะทำงานแบบเดียวกัน

Exercise 6: เข้าถึง DVWA#

หา IP address ของ VM:

ติดตั้ง net-tools ก่อน (สำหรับ ifconfig):

sudo apt install net-tools -y
bash

ตรวจสอบ IP address:

ifconfig
bash

จะเห็นบางอย่างเช่น 10.0.2.15 หรือ 192.168.56.x

ifconfig output

เปิด Firefox ใน Ubuntu และไปที่: http://10.0.2.15/dvwa/setup.php

Note: แทนที่ 10.0.2.15 ด้วย IP address จริง หากต่างออกไป สามารถใช้ http://localhost/dvwa/setup.php ได้หากทำงานภายใน VM

คลิกปุ่ม “Create / Reset Database” เพื่อเริ่มต้น DVWA ระบบจะสร้าง database tables ทั้งหมดและเติมข้อมูล demo อัตโนมัติ

DVWA Setup Page

Note: หากเห็น error ใดๆ ให้แน่ใจว่า database credentials ใน config.inc.php ตรงกับ MySQL user ที่สร้าง

Login เข้าสู่ DVWA:

URL: http://10.0.2.15/dvwa/login.php
Username: admin
Password: password
plaintext

Note: ใช้ IP address จริง สำหรับตัวอย่างนี้ใช้ 10.0.2.15

DVWA Dashboard

DVWA After Login


5. การเข้าใจ Brute Force Vulnerability#

Exercise 7: สำรวจ DVWA Brute Force Module#

ไปที่: http://10.0.2.15/dvwa/security.php → ตั้ง security level เป็น “Low” → คลิก Submit

DVWA Security Level Low

Note: DVWA มีหลาย security levels (Low, Medium, High, Impossible) ใช้ Low สำหรับการเรียนรู้เนื่องจากมี security controls น้อย ทำให้เข้าใจและฝึก brute force attacks ได้ง่ายขึ้น

จากนั้นไปที่: http://10.0.2.15/dvwa/vulnerabilities/brute/

Note: แทนที่ 10.0.2.15 ด้วย IP address จริง หากต่างออกไป

ลอง login ด้วย credentials ที่รู้จัก:

Username: admin
Password: password
bash

ควรเห็นข้อความ login สำเร็จ

จากนั้น logout และลองใช้รหัสผ่านที่ผิด:

Username: admin
Password: wrongpass
bash

สังเกตสิ่งที่เกิดขึ้นใน URL:

http://10.0.2.15/dvwa/vulnerabilities/brute/?username=admin&password=wrongpass&Login=Login
bash

Note: แทนที่ 10.0.2.15 ด้วย IP address จริง จะเห็น IP ใน URL แทน

ข้อสังเกตสำคัญ: Username และ password ถูกส่งผ่าน GET request ใน URL query parameters! ทำให้ intercept และ manipulate ได้ง่ายมาก

การเข้าใจ GET vs POST#

Methodวิธีส่งข้อมูลความปลอดภัยการมองเห็น
GETIn URL query paramsปลอดภัยน้อยกว่ามองเห็นใน URL, history, logs
POSTIn request bodyปลอดภัยกว่าไม่มองเห็นใน URL
# GET Request (DVWA Low ใช้วิธีนี้)
GET /dvwa/vulnerabilities/brute/?username=admin&password=wrongpass HTTP/1.1

# POST Request (ปลอดภัยกว่า)
POST /dvwa/vulnerabilities/brute/ HTTP/1.1
Content-Type: application/x-www-form-urlencoded

username=admin&password=wrongpass
http

6. การติดตั้ง Burp Suite Community Edition#

Burp Suite เป็น interception proxy มาตรฐานอุตสาหกรรมสำหรับ web application security testing

Exercise 8: ดาวน์โหลด Burp Suite#

ใน Ubuntu Firefox ไปที่: https://portswigger.net/burp/communitydownload

ดาวน์โหลดเวอร์ชัน Linux (shell script)

Exercise 9: ติดตั้ง Burp Suite#

ไปที่ Downloads:

cd ~/Downloads
ls -l burp*
bash

ทำให้ installer สามารถ execute ได้:

sudo chmod +x burpsuite_community_*.sh
bash

รัน installer:

./burpsuite_community_*.sh
bash

ทำตาม prompts ผ่าน installation wizard

Exercise 10: เปิด Burp Suite#

เริ่ม Burp Suite:

วิธีที่ 1: ค้นหาใน Ubuntu Applications

  1. คลิกปุ่ม Show Applications (ไอคอน grid) ที่มุมซ้ายล่าง
  2. พิมพ์ Burp Suite ใน search bar
  3. คลิก Burp Suite เพื่อเปิด

Burp Suite Application

วิธีที่ 2: Command Line

cd /opt/BurpSuiteCommunity
./burpsuite
bash

Initial Setup Wizard:

  1. คลิก Next หรือ Start Burp
  2. เลือก “Use Burp defaults” หรือตั้งค่าตามต้องการ
  3. คลิก Start Burp เพื่อเปิด main interface

จะเห็น Burp Suite dashboard:

Burp Suite Interface

Exercise 11: ตั้งค่า Firefox Proxy#

เปิด Firefox ใน Ubuntu:

  1. คลิกปุ่ม menu (สามเส้น)
  2. ไปที่ SettingsNetwork Settings
  3. คลิก Settings
  4. เลือก Manual proxy configuration
  5. ตั้งค่า:
    • HTTP Proxy: 127.0.0.1
    • Port: 8080
  6. ติ๊ก “Use this proxy for all protocols”
  7. คลิก OK

Firefox Proxy Settings

ตรวจสอบ Burp Suite Proxy:

ใน Burp Suite ไปที่ ProxyProxy settingsProxy

ยืนยัน:

  • Interface: 127.0.0.1
  • Port: 8080
  • Running: ✓ (ควรแสดงเครื่องหมายถูกสีเขียว)

Burp Suite Proxy Settings

Exercise 12: ติดตั้ง Burp Suite CA Certificate#

ทำไม? Burp Suite ต้องการ intercept HTTPS traffic ซึ่งต้องการ trusted certificate

ใน Firefox ไปที่: http://burp

ดาวน์โหลด CA Certificate:

  1. คลิก “CA Certificate”
  2. บันทึกไฟล์เป็น cacert.der

Burp CA Certificate Download

นำเข้า Certificate:

  1. ใน Firefox ไปที่ SettingsPrivacy & Security
  2. เลื่อนลงไปที่ Certificates
  3. คลิก View Certificates
  4. ไปที่แท็บ Authorities
  5. คลิก Import
  6. เลือก cacert.der
  7. ติ๊ก “Trust this CA to identify websites”
  8. คลิก OK

Firefox Certificate Import


7. การ Intercept Requests ด้วย Burp Suite#

⚠️ ก่อนดำเนินการต่อ: ตรวจสอบให้แน่ใจว่า DVWA security level ตั้งเป็น Low ไปที่ http://10.0.2.15/dvwa/security.php และยืนยันว่า security level เป็น “Low” ก่อนดำเนินการ Burp Suite exercises

Exercise 13: เปิดใช้งาน Intercept Mode#

ใน Burp Suite:

  1. ไปที่แท็บ Proxy
  2. คลิกแท็บย่อย Intercept
  3. คลิกปุ่ม “Intercept is on” เพื่อเปิด

เมื่อ Intercept เปิดอยู่ Burp จะ capture requests ทั้งหมดจาก Firefox

Exercise 14: Intercept DVWA Login#

เมื่อเปิด Intercept ใน Burp:

  1. ใน Firefox ไปที่ DVWA Brute Force page
  2. ลอง login ด้วย:
    • Username: admin
    • Password: test123
  3. Firefox จะดูเหมือนหยุดทำงาน - นี่เป็นเรื่องปกติ!

สลับไป Burp Suite:

จะเห็น intercepted request:

GET /dvwa/vulnerabilities/brute/?username=admin&password=test123&Login=Login HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 ...
Accept: text/html,application/xhtml+xml...
http

การเข้าใจ Burp Intercept Actions#

ActionKeyboard ShortcutResult
ForwardCtrl + Fส่ง request ไปยัง server
DropCtrl + Dยกเลิก request
InterceptCtrl + Iเปิด/ปิด intercept

ลอง: คลิก Forward เพื่อส่ง request ไปยัง DVWA

Burp Forward Action

Exercise 15: ตรวจสอบ HTTP History#

ใน Burp Suite:

  1. ไปที่ ProxyHTTP History tab
  2. หา DVWA login request ที่เพิ่งทำ
  3. คลิกเพื่อดูรายละเอียด

สังเกต request structure:

Request Line:
GET /dvwa/vulnerabilities/brute/?username=admin&password=test123&Login=Login

Headers:
Host: localhost
User-Agent: Mozilla/5.0...
Accept: text/html...

GET Parameters:
username = admin
password = test123
Login = Login
bash

ตอนนี้สังเกต response:

คลิกแท็บ Response จะเห็น:

<pre><br />
Username and/or password incorrect.<br /><br /></pre>
html

Burp Response View

นี่คือ response ของ server ต่อรหัสผ่านที่ผิด!


8. Automated Brute Force ด้วย Burp Intruder#

Exercise 16: ส่ง Request ไปยัง Intruder#

จาก HTTP History:

  1. คลิกขวาที่ DVWA login request
  2. เลือก Send to Intruder

สลับไปที่แท็บ Intruder ใน Burp Suite

Exercise 17: ตั้งค่า Attack Position#

ใน Intruder → Positions tab:

จะเห็น request ที่มี password field ถูก highlight

ล้าง default positions โดยคลิก Clear § (ปุ่ม Clear Section)

ตอนนี้ highlight เฉพาะ password value:

  1. เลือก password text (เช่น test123)
  2. คลิก Add § (ปุ่ม Add Section)

Burp Highlight Payload

💡 Note: สัญลักษณ์ § เรียกว่า “section sign” (ออกเสียงว่า “section symbol” หรือ “section mark”) ใน Burp Suite มัน标记 positions ที่ payload values จะถูกแทรกในระหว่าง attack

Request ควรมีลักษณะนี้:

...username=admin&password=§test123§&Login=Login
bash

สัญลักษณ์ § บ่งบอกตำแหน่งที่จะแทรก payloads

Exercise 18: ตั้งค่า Payloads#

ไปที่ Intruder → Payloads tab:

Payload type: เลือก Simple list

ใน Payload Options เพิ่ม test passwords:

password
admin
123456
qwerty
letmein
welcome
admin123
password123
bash

这些 เป็น weak passwords ทั่วไปสำหรับ testing

Burp Payload List

Exercise 19: ตั้งค่า Attack Settings#

ไปที่ Intruder → Settings tab:

Attack type: Sniper (หนึ่ง payload position ทดสอบตามลำดับ)

Grep - Extract (optional filtering):

  1. คลิก Add ภายใต้ Grep - Extract
  2. ใน response highlight “incorrect”
  3. ช่วยให้ Burp ระบุ failed login attempts

Burp Grep Extract

Grep - Match (response filtering):

  1. คลิก Add ภายใต้ Grep - Match
  2. ใส่: “incorrect”
  3. จะ标记 responses ที่มี “incorrect”

Burp Grep Match

Exercise 20: เริ่ม Attack#

คลิกปุ่ม “Start attack” ขนาดใหญ่ ที่มุมขวาบน

หน้าต่างใหม่จะเปิดขึ้นแสดง attack results:

Payload #PayloadStatusLengthError
1password2004874None
2admin2005120None
31234562004874None

Burp Attack Results

ข้อสังเกตสำคัญ:

  1. Status 200 = Request succeeded (server responded)
  2. Length differences = Different response content
  3. หา payload ที่มี different length - น่าจะเป็นรหัสผ่านที่ถูกต้อง!

Exercise 21: วิเคราะห์ Results#

ในหน้าต่าง attack results:

  1. คลิกส่วนหัวคอลัมน์ Length เพื่อเรียงลำดับ
  2. มองหารายการที่มี different response lengths
  3. Successful login มักมี page size ที่ต่างออกไป

หรือใช้ Grep results:

  1. คอลัมน์ทางขวาแสดง matched flags
  2. รายการที่ ไม่มี “incorrect” = successful login

ตรวจสอบรหัสผ่าน:

หาก “password” แสดง response length ที่ต่างออกไป ลอง login ด้วยตนเอง:

Username: admin
Password: password
bash

9. Dictionary Attack ด้วย Password Lists#

Exercise 22: ดาวน์โหลด Password Wordlist#

ใน Ubuntu terminal:

cd ~/Downloads
bash

ดาวน์โหลด John the Ripper’s password list:

wget https://raw.githubusercontent.com/openwall/john/bleeding-jumbo/run/password.lst -O passwords.txt
bash

หรือใช้ SecLists (ครอบคลุมกว่า):

git clone https://github.com/danielmiessler/SecLists.git
bash

Password lists ทั่วไปใน SecLists:

  • Passwords/Common-Credentials/10-million-password-list-top-1000.txt
  • Passwords/Software/dragonfly41-top10k.txt

Exercise 23: โหลด Wordlist ลงใน Burp#

กลับไป Burp Suite Intruder:

  1. ไปที่แท็บ Payloads
  2. ภายใต้ Payload Options คลิก Load…
  3. ไปที่ ~/Downloads/passwords.txt
  4. คลิก Open

Preview payloads: จะเห็น passwords หลายร้อย/หลายพันรายการถูกโหลด

Exercise 24: รัน Dictionary Attack#

ก่อนเริ่ม ปรับ settings:

ใน Intruder → Settings:

  1. Request Engine: ตั้ง threads เป็น 1-5 (อย่า overload)
  2. Attack type: Sniper

เริ่ม attack และรอให้เสร็จสิ้น

Exercise 25: กรองและวิเคราะห์#

ใน attack results:

กรองตาม response length:

  1. คลิกคอลัมน์ Length เพื่อเรียงลำดับ
  2. ระบุ outliers

กรองตาม keyword:

  1. เพิ่ม Grep - Match rule สำหรับ: “Welcome”
  2. หรือค้นหา: “incorrect”
  3. Results ที่ ไม่มี “incorrect” คือสำเร็จ

ผลลัพธ์ที่คาดหวัง: รายการหนึ่งจะแสดง:

  • Different response length
  • ไม่มีข้อความ “incorrect”
  • อาจแสดง welcome message หรือ redirect

10. เทคนิคการวิเคราะห์ขั้นสูง#

Response Length Analysis#

Response lengths ที่ต่างกันบ่งบอกผลลัพธ์ที่ต่างกัน:

ResponseLengthความหมาย
~4800 bytesBase lengthFailed login
~5100 bytesDifferent lengthSuccessful login

Grep - Extract สำหรับ Precise Filtering#

Extract ข้อความเฉพาะจาก responses:

  1. SettingsGrep - ExtractAdd
  2. Highlight ข้อความที่ต้องการ extract (เช่น “incorrect”)
  3. กำหนด start และ end markers
  4. Results แสดง extracted values ในคอลัมน์ใหม่

ตัวอย่าง:

Extract: "incorrect"
Result: Flag ปรากฏในคอลัมน์ "incorrect"
bash

Burp Intruder Attack Types#

TypeคำอธิบายUse Case
SniperOne payload, multiple positionsSingle field brute force
Battering RamSame payload everywhereTesting one value everywhere
PitchforkMultiple payloads, paired positionsUsername + password combos
Cluster BombAll payload combinationsCartesian product testing

11. DVWA Security Levels Comparison#

Low Security (ทดสอบแล้ว)#

// No protection
if( isset( $_GET[ 'Login' ] ) ) {
    $user = $_GET[ 'username' ];
    $pass = $_GET[ 'password' ];
    // Check against database
    // No rate limiting
    // No lockout
}
php

ช่องโหว่:

  • ❌ No rate limiting
  • ❌ No account lockout
  • ❌ GET requests visible in URL/history
  • ❌ No CAPTCHA
  • ❌ No delay between attempts

Medium Security#

// Some protection implemented
$user = stripslashes( $user );
$pass = stripslashes( $pass );
$user = mysql_real_escape_string( $user );
$pass = mysql_real_escape_string( $pass );
// Still vulnerable to brute force
php

High Security#

// Token-based protection
checkToken( $user_token, $_SESSION[ 'session_token' ], 'index.php' );
// Anti-CSRF token required
php

Impossible Security#

// PDO with prepared statements
// Strong password hashing
// Comprehensive input validation
// Rate limiting
// Account lockout
// 2FA ready
php

12. Defenses in Practice#

Implementing Rate Limiting#

ตัวอย่าง PHP implementation:

<?php
session_start();

// Check for failed attempts
if (isset($_SESSION['failed_attempts']) && $_SESSION['failed_attempts'] > 5) {
    // Check if lockout period has passed
    if (time() < $_SESSION['lockout_time']) {
        die("Account locked. Try again later.");
    } else {
        // Reset attempts after lockout period
        unset($_SESSION['failed_attempts']);
        unset($_SESSION['lockout_time']);
    }
}

// Check login credentials
if (login_failed) {
    $_SESSION['failed_attempts'] = isset($_SESSION['failed_attempts'])
        ? $_SESSION['failed_attempts'] + 1
        : 1;

    if ($_SESSION['failed_attempts'] > 5) {
        $_SESSION['lockout_time'] = time() + 900; // 15 minutes
    }
}
?>
php

Web Application Firewall (WAF)#

WAF rules for brute force protection:

# Nginx example
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;

location /login {
    limit_req zone=login burst=3 nodelay;
    # ... rest of config
}
nginx

Apache mod_security example:

SecAction "id:1001,phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR}"
SecRule IP:FAILED_LOGINS "@gt 5" "phase:1,deny,status:429,msg:'Rate limit exceeded'"
apache

13. Detection and Monitoring#

Log Analysis#

Failed login attempt log entries:

[2024-04-23 10:15:23] FAILED LOGIN - user: admin, IP: 192.168.1.100
[2024-04-23 10:15:24] FAILED LOGIN - user: admin, IP: 192.168.1.100
[2024-04-23 10:15:25] FAILED LOGIN - user: admin, IP: 192.168.1.100
bash

Monitoring commands:

# Count failed logins by IP
grep "FAILED LOGIN" /var/log/auth.log | awk '{print $NF}' | sort | uniq -c

# Real-time monitoring
tail -f /var/log/apache2/access.log | grep "POST.*login"
bash

Alerting#

ตั้งค่า alerts สำหรับ:

# Multiple failed logins from same IP (5+ in 1 minute)
alert: auth_failures > 5 within 60 seconds

# Login attempts from unusual locations
alert: country NOT in ["US", "CA", "UK", "TH"]

# Login attempts outside business hours
alert: time NOT BETWEEN 09:00 AND 17:00
bash

14. Quick Reference#

Burp Suite Key Shortcuts#

ShortcutAction
Ctrl + IToggle intercept on/off
Ctrl + FForward intercepted request
Ctrl + DDrop intercepted request
Ctrl + Shift + ISend to Intruder
Ctrl + Shift + RSend to Repeater

Common Password Wordlists#

WordlistSizeSource
passwords.txt~3,000John the Ripper
rockyou.txt~14 millionBreach data
10k-most-common.txt10,000SecLists

Defense Checklist#

  • ✅ Strong password policy (12+ characters, complexity)
  • ✅ Rate limiting (5 attempts per minute)
  • ✅ Account lockout (15+ minutes)
  • ✅ 2FA/MFA enabled
  • ✅ CAPTCHA after failures
  • ✅ Logging and monitoring
  • ✅ WAF rules configured
  • ✅ HTTPS enforced
  • ✅ Secure password storage (bcrypt/argon2)

15. Next Steps#

Congratulations! ได้ทำ Brute Force Attack Lab เสร็จสิ้นแล้ว ตอนนี้มี:

  • ✅ ความเข้าใจเกี่ยวกับ brute force attack methods
  • ✅ ความรู้เกี่ยวกับ prevention techniques
  • ✅ ประสบการณ์จริงกับ DVWA
  • ✅ ทักษะทางปฏิบัติกับ Burp Suite
  • ✅ ความสามารถในการทำและวิเคราะห์ brute force attacks
  1. SQL Injection - เรียนรู้ database attacks
  2. Cross-Site Scripting (XSS) - Client-side attacks
  3. Session Hijacking - ขโมย user sessions
  4. Security Testing Methodologies - OWASP Testing Guide
  5. Secure Coding - เขียน code ที่ทนทานต่อการโจมตี

Practice Resources#

ResourceURL
OWASP Top 10https://owasp.org/www-project-top-ten/
Burp Suite Documentationhttps://portswigger.net/burp/documentation
DVWA Documentationhttps://github.com/digininja/DVWA
Web Security Academyhttps://portswigger.net/web-security
SecListshttps://github.com/danielmiessler/SecLists

Ethical Considerations#

⚠️ IMPORTANT:

  • Test เฉพาะ systems ที่เป็นเจ้าของหรือได้รับอนุญาตอย่างชัดเจน
  • Brute force attacks ผิดกฎหมายหากดำเนินการโดยไม่ได้รับอนุญาต
  • ใช้ทักษะเหล่านี้สำหรับ defensive purposes และ authorized security testing
  • รายงาน vulnerabilities อย่างมีความรับผิดชอบผ่าน proper disclosure channels
  • ขออนุญาตเป็นลายลักษณ์อักษรก่อน conducting การทดสอบ penetration testing

การเข้าถึง computer systems โดยไม่ได้รับอนุญาตเป็นความผิดทางอาญาในเขตอำนาจศาลส่วนใหญ่ บทความนี้มีไว้ เพื่อการศึกษาเท่านั้น และควรฝึกในสภาพแวดล้อม lab ที่แยกจากส่วนอื่น (เช่น DVWA setup)


Happy learning and stay ethical! 🔐

Cyber Security: เรียนรู้ Brute Force Attack
ผู้เขียน กานต์ ยงศิริวิทย์ / Karn Yongsiriwit
เผยแพร่เมื่อ April 23, 2026
ลิขสิทธิ์ CC BY-NC-SA 4.0

กำลังโหลดความคิดเห็น...

ความคิดเห็น 0