brute force ssh หน้าตาเป็นอย่างไร จะตรวจจับอย่างไร

brute force ssh หน้าตาเป็นอย่างไร จะตรวจจับอย่างไร

หลังจากได้ลองสร้าง lab เพื่อเรียนรู้ cybersecurity ทั้งฝั่ง redteam และฝั่ง blue team ซึ่งได้ลองติดตั้งเครื่องเป้าหมาย (เหยื่อ) และได้ติดตั้งระบบเก็บ log (log management) โดยใช้ Graylog เพื่อรวบรวม log จากเครื่องต่างๆ เพื่อมาเรียนรู้เรื่องการวิเคราะห์ เฝ้าระวังภัยคุกคาม วันนี้เลยลองตั้งคำถามว่าการโจมตีแบบ brute force password ผ่านบริการ ssh จะหน้าตาเป็นอย่างไร เลยลองถาม Gemini ดู ได้คำตอบดังนี้

คำถาม "bruteforce ssh what is the system log look like"

คำตอบ
The specific details of SSH brute-force attempts in your system logs will depend on the SSH server software you're using (e.g., OpenSSH, Dropbear), but they will generally contain some common elements that indicate a potential attack. Here's what to look for:

Time: This will show you when the login attempt occurred.

IP Address: This identifies the IP address of the machine attempting to connect. If you see multiple attempts from the same IP in a short period, it's a strong sign of brute-forcing.

Username: The logs will usually show the username the attacker tried to use. Common usernames targeted in brute-force attacks include "root", "admin", and well-known user accounts.

Status: This will indicate whether the login attempt was successful or failed. Failed login attempts, especially for non-existent usernames, are a red flag.

Here are some examples of what SSH brute-force attempts might look like in your system logs:

OpenSSH (common):

sshd[PID]: pam_unix(sshd:session): Authentication failure for user [username] from [IP address]
sshd[PID]: Fatal: Invalid user [username] from [IP address]

Dropbear (example):

Dropbear[PID]: [IP address] SSH-2: Failed password for [username] from [IP address] port [port number] ssh2_dispatch_publickey: incorrect signature

These are just a few examples, and the format might vary slightly depending on your specific SSH server configuration. However, the key elements like timestamps, IP addresses, usernames, and failed login attempts should be present to indicate a potential brute-force attack.

Here are some additional things to look for:

  • Rapid succession of failed login attempts: If you see a large number of failed login attempts within a short timeframe, especially from the same IP address or for non-existent usernames, it's a strong sign of brute-forcing.
  • Attempts from unusual locations: If you see login attempts originating from countries or regions where you don't have legitimate users, it's more suspicious.
  • Targeting specific usernames: If you see repeated attempts for a specific username, particularly privileged accounts like "root" or "admin", it's a cause for concern.

If you suspect a brute-force attack on your SSH server, here are some steps you can take:

  • Change your SSH port: The default SSH port (22) is a common target for brute-force attacks. Consider changing it to a less common port number.
  • Enable strong password policies: Enforce complex passwords with minimum length requirements and regular password changes.
  • Implement SSH key-based authentication: This method uses cryptographic keys instead of passwords, making it much more difficult to crack.
  • Use fail2ban: This is a tool that can automatically ban IP addresses after a certain number of failed login attempts.
    Monitor your logs: Regularly review your system logs for suspicious activity.

By taking these steps, you can significantly reduce the risk of successful SSH brute-force attacks on your system.

พอทราบว่าหน้าตา log ที่เกี่ยวกับ brute force ssh เป็นยังไง เราก็มาเขียน log parser เพื่อเก็บข้อมูล ในที่นี้ใช้ graylog จึงถาม Gemini ต่อดังนี้:

คำถาม "parsing these logs to graylog"

คำตอบ

Here's a breakdown of how you can parse logs for Graylog, focusing on the two scenarios you mentioned earlier:

1. SSH Brute-Force Attempts:

There are two main approaches to parsing SSH brute-force attempt logs in Graylog:

A. Using Grok Patterns:

Grok patterns are a powerful tool in Graylog for parsing semi-structured log messages. Here's a sample Grok pattern for OpenSSH logs indicating failed login attempts:

%{TIMESTAMP_ISO8601} %{LOGLEVEL} sshd\[%{PID:pid}\]: pam_unix\(sshd:session\): Authentication failure for user %{USERNAME} from %{IP:source}

This pattern will extract specific fields like timestamp, log level, process ID, username, and source IP address. You can then define extractors in Graylog to map these fields to specific custom fields for easier analysis.

B. Using Pipelines:

Pipelines allow for more complex processing of log messages. You can define stages in the pipeline to perform tasks like filtering messages based on specific keywords (e.g., "Failed password") or extracting data using regular expressions.

ซึ่งเมื่อได้ parser ดังกล่าวแล้ว เราสามารถ สร้าง query ใน graylog เพื่อดึงข้อมูลมาแสดง และสามารถสร้างเป็น dashboard ได้

สิ่งที่ได้จากการทำครั้งนี้ ทำให้ทราบว่าการใช้ AI มาช่วย โดยตั้งคำถามที่เหมาะสม จะทำให้กระบวนการเรียนรู้ cybersecurity ทำได้รวดเร็วมาก และลดระยะเวลาการดำเนินการได้มากยิ่งขึ้น และทำให้เราสามารถเข้าใจหลักการเกี่ยวกับการโจมตีประเภทต่างๆ (ในที่นี้คือ brute force password ssh) และสิ่งที่ระบบจะเห็นและสามารถใช้ในการตรวจจับการโจมตีได้

อย่างไรก็ตาม คำตอบที่ได้จาก AI เราต้องมาตรวจสอบความถูกต้องอีกครั้ง