Showing posts with label log. Show all posts
Showing posts with label log. Show all posts

Saturday, March 28, 2026

Essential Linux Commands for Log Analysis

Essential Linux Commands for Log Analysis

Prepare Sample SSH Log Files

Log download  the log files contain relevant SSH events, including timestamps, source IP addresses, usernames, actions (login, logout), etc.

Essential Linux Commands for Log Analysis

Commands for Hashing Log Files

1. Generating a Hash (SHA-256)

The most common and secure standard for forensic imaging and log analysis is SHA-256.

  • Command: sha256sum ssh.log

    Essential Linux Commands for Log Analysis

  • Explanation: This command calculates the SHA-256 hash of the file ssh.log. It will output a 64-character hexadecimal string followed by the filename.

2. Saving the Hash to a Verification File

In a forensic investigation, you must save the hash immediately after collecting the evidence.

  • Command: sha256sum ssh.log > ssh.log.sha256

    Essential Linux Commands for Log Analysis

  • Explanation: The > operator redirects the output into a new file named ssh.log.sha256. This file acts as your "Evidence Reference".

3. Verifying the Integrity

To check if the log file has been tampered with or corrupted later:

  • Command: sha256sum -c ssh.log.sha256

  • Explanation: The -c (check) flag tells the system to read the hash from the .sha256 file and compare it with the current state of ssh.log.

    • Result OK: The file is identical to the original.

      Essential Linux Commands for Log Analysis

    • Result FAILED: The file has been modified or corrupted.


Essential Linux Commands for Log Analysis

1. grep (Global Regular Expression Print)

Used to search for specific text patterns within the log file.

  • Command: grep "success" ssh.log

  • Purpose: To filter and display only the lines where a login was successful.

  • Command: grep "failure" ssh.log | wc -l

  • Purpose: To count the total number of failed login attempts.

    Essential Linux Commands for Log Analysis

Steps to Analyze SSH Log Files

#cat Desktop/Web_Server_Logs/ssh.log 

Essential Linux Commands for Log Analysis

Analyze failed login attempts:

 #cat Desktop/Web_Server_Logs/ssh.log | grep failure 


Essential Linux Commands for Log Analysis

Investigate SSH sessions from unusual or suspicious source IP addresses: 

awk (Pattern Scanning and Processing)

Used to extract specific columns (fields) from the log.

  • Command: awk '{print $3}' ssh.log

  • Purpose: To extract the Source IP address (which is in the 3rd column)

    Essential Linux Commands for Log Analysis

  • Command: awk '{print $5}' ssh.log

  • Purpose: To extract the Destination IP address (which is in the 5th column).

    Essential Linux Commands for Log Analysis

If you want to find the Top 10 IP addresses trying to hack your server, use this combined

Step-by-step breakdown:

  1. awk '{print $3}': Get all Source IPs.

  2. sort: Group identical IPs together.

  3. uniq -c: Count how many attempts each IP made.

  4. sort -nr: Sort numerically in reverse (highest count at the top).

  5. head -n 10: Show only the top 10 results.

#awk '{print $3}' Desktop/Web_Server_Logs/ssh.log | sort | uniq -c | sort -nr | head -n 10

Essential Linux Commands for Log Analysis

Top Target (Destination) IPs:

  • 192.168.28.254 (High frequency of attempts)

    Essential Linux Commands for Log Analysis

  • 192.168.23.203 (High frequency of attempts)

  • Essential Linux Commands for Log Analysis

  • 192.168.27.203 (High frequency of attempts)

  • Essential Linux Commands for Log Analysis
  1. 1331904022.010000
    → Unix Timestamp (เวลาที่เกิดเหตุการณ์)

  2. CU46Bb2UypzdF4eTW
    → Session ID / Connection ID ของ SSH

  3. 192.168.202.110
    → Source IP (เครื่องที่พยายามเชื่อมต่อ)

  4. 36586
    → Source Port

  5. 192.168.27.203
    → Destination IP (เครื่องปลายทาง = SSH Server)

  6. 22
    → Destination Port (SSH)

  7. undetermined / failure
    → สถานะการเชื่อมต่อ

  • undetermined = ยังไม่ทราบผล (handshake)

  • failure = login ล้มเหลว

  1. INBOUND
    → เป็นการเชื่อมต่อขาเข้า (incoming connection)

  2. SSH-2.0-OpenSSH_5.8p1 Debian-ubuntu3
    → Banner ของ SSH 

  • The SSH log indicates repeated inbound connection attempts from IP address 192.168.202.110 targeting the SSH service on 192.168.27.203 over port 22.
    Multiple sessions resulted in authentication failures, which is consistent with a brute-force or unauthorized login attempt.

 Time Conversion Command

Since the log uses Unix Epoch Time, you can convert it to a human-readable format using the date command.

  • Command: date -d @1332017793.040000 

  • Purpose: Converts the timestamp 1332017793.040000  into a standard Date/Time format.

Essential Linux Commands for Log Analysis


อ่านเพิ่มเติม:

หมายเหตุ:เนื้อหาในเว็บไซต์นี้มีขึ้นเพื่อวัตถุประสงค์ในการให้ข้อมูลและเพื่อการศึกษาเท่านั้น ช่วยเตือนความจำ


* หากมีข้อมูลข้อผิดพลาดประการใด ขออภัยมา ณ ที่นี้ด้วย  รบกวนแจ้ง Admin เพื่อแก้ไขต่อไป
ขอบคุณครับ

#WindowsForensic #ComputerForensics #dfir #forensics #digitalforensics #computerforensic #investigation #cybercrime #fraud

Monday, April 28, 2025

Digital Forensics:การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ

Digital Forensics:การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ 

🔼Log File คือ หลักฐานสำคัญในโลกไซเบอร์ เก็บให้ถูก อย่าเสี่ยง!" มาตรวจสอบกันว่าการเก็บ Log file ที่ถูกต้องตามกฎหมาย พ.ร.บ. คอมพิวเตอร์ต้องดูอะไรบ้าง!

การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ
Photo Credit: KEN CAFE Facebook

🔼 CIA Triad : 

1. Confidentiality (การรักษาความลับ) การปกป้องข้อมูลหรือระบบให้สามารถเข้าถึงได้เฉพาะผู้ที่มีสิทธิ์เท่านั้น

2. Integrity (ความถูกต้องและความครบถ้วน) การป้องกันไม่ให้ข้อมูลหรือระบบถูกดัดแปลงแก้ไขโดยไม่ได้รับอนุญาต

3. Availability (ความพร้อมใช้งาน)การทำให้ข้อมูลต้องพร้อมใช้งานตลอดเวลา เพื่อบ่งบอกประสิทธิภาพและความน่าเชื่อถือ

การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ
Photo Credit: KEN CAFE Facebook

🔼 รายละเอียด และวิธีเก็บ log ตาม พ.ร.บ. คอมพิวเตอร์

1. AAA Server

2. Email Server

3. Web Server

4. Router & Firewall

5. Proxy

การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ
Photo Credit: KEN CAFE Facebook

🔼 Centralized Log Management 

คือ ระบบบริหารจัดการข้อมูล Log File แบบศูนย์กลาง ซึ่งรองรับการจัดเก็บข้อมูล Log File จากเครื่องคอมพิวเตอร์เซิร์ฟเวอร์หรืออุปกรณ์เครือข่ายต่าง ๆ ได้แก่ Firewall, Router, Switch, Window Server, Linux Server, Web Server, Application Server และอื่น ๆ อีกมากมาย

การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ
Photo Credit: KEN CAFE Facebook

🔼 ใครบ้างที่ต้องเก็บ Log File

 1. ผู้ให้บริการอินเทอร์เน็ตแก่บุคคลทั่วไป

2. ผู้ให้บริการในการเก็บข้อมูลเพื่อประโยชน์ของบุคคลอื่น


การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ
Photo Credit: KEN CAFE Facebook

การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ

Photo Credit: KEN CAFE Facebook

🔼 วิธีเก็บ Log File อะไรบ้าง

การเก็บ Log File อย่างถูกกฎหมาย ต้องสอดคล้องกับหลักเกณฑ์ของ พ.ร.บ. คอมพิวเตอร์ พ.ศ. 2560 (และประกาศกระทรวงดิจิทัลฯ ปี 2564) ซึ่งระบุประเภทของข้อมูลจราจรคอมพิวเตอร์ (Traffic Data) ที่ต้องจัดเก็บไว้เพื่อให้สามารถ ระบุตัวตนผู้ใช้งานได้อย่างชัดเจน

- IP Address (หมายเลขไอพี)

- วัน/เวลาเริ่มต้น และสิ้นสุดการใช้งาน

- User ID / Account ที่ใช้งาน

- หมายเลขโทรศัพท์ (ถ้ามี)

- ชื่อ-ที่อยู่ของผู้ใช้งาน (จากการลงทะเบียน)

- MAC Address / Device ID

- Status Indictor (ข้อมูลสถานะการใช้งาน)

- Log จากอุปกรณ์เครือข่าย

- URL (จุดที่ผู้ใช้เข้าถึง)

Photo Credit: KEN CAFE Facebook


การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ

🛑ลักการสำคัญในการจัดเก็บ Log File ตาม พ.ร.บ. คอมพิวเตอร์
เข้าใจหลักการสำคัญที่ พ.ร.บ. คอมพิวเตอร์กำหนดไว้ก่อน ซึ่งโปรแกรมที่ดีควรมีคุณสมบัติตรงตามหลักการเหล่านี้ :
1. ความถูกต้องและครบถ้วน : Log File ต้องบันทึกข้อมูลที่เกี่ยวข้องอย่างครบถ้วน เช่น วันที่ เวลา ผู้ใช้งาน IP Address การเข้าถึงข้อมูล การเปลี่ยนแปลงแก้ไข ฯลฯ
2. ความน่าเชื่อถือ : ข้อมูล Log File ต้องมีความน่าเชื่อถือ ไม่สามารถแก้ไขเปลี่ยนแปลงได้โดยง่าย และมีการป้องกันการเข้าถึงโดยไม่ได้รับอนุญาต
3. การเก็บรักษาตามระยะเวลา: ต้องสามารถเก็บรักษา Log File ตามระยะเวลาที่กฎหมายกำหนด (ปัจจุบันคืออย่างน้อย 90 วัน และเก็บรักษาข้อมูลจราจรทางคอมพิวเตอร์ของผู้ให้บริการไว้อย่างน้อย 1 ปี)
4. การตรวจสอบได้ : ต้องมีกลไกที่สามารถตรวจสอบ Log File ได้ง่าย สะดวก และรวดเร็ว
5. การรักษาความลับ : ต้องมีมาตรการรักษาความลับของข้อมูล Log File เพื่อป้องกันการรั่วไหลหรือการนำไปใช้ในทางที่ผิด
--------------------------------
📘1. Wazuh สามารถใช้ในการจัดเก็บ Log File ได้ตามหลักการที่ พ.ร.บ. คอมพิวเตอร์กำหนด และเป็นเครื่องมือที่ได้รับความนิยมอย่างมากในด้าน Security Information and Event Management (SIEM) และ Extended Detection and Response (XDR) แบบ Open Source
.
📘2. Graylog เป็นอีกหนึ่งโปรแกรมที่สามารถใช้ในการจัดเก็บ Log File ได้ตามหลักการที่ พ.ร.บ. คอมพิวเตอร์กำหนด และเป็น Open Source SIEM (Security Information and Event Management) ที่ได้รับความนิยม
.
📘3. ELK Stack เป็นอีกหนึ่งโซลูชันที่ยอดเยี่ยมและได้รับความนิยมอย่างสูงในการจัดเก็บและจัดการ Log File ให้เป็นไปตามหลักการของ พ.ร.บ. คอมพิวเตอร์ และเป็น Open Source ที่มีความยืดหยุ่น และมีประสิทธิภาพมาก
.
📘4. Kiwi Syslog Server เป็นอีกหนึ่งโปรแกรมที่สามารถใช้ในการจัดเก็บ Log File ได้ โดยเฉพาะอย่างยิ่งสำหรับสภาพแวดล้อมของ Windows Server และอุปกรณ์เครือข่ายที่รองรับโปรโตคอล Syslog
.
📘5. Syslog-ng เป็นโปรแกรมจัดการ Log พื้นฐานบน Linux/Unix ที่มีความยืดหยุ่นสูง และใช้งานกันอย่างแพร่หลายในฐานะเครื่องมือหลักในการรวบรวม Log จากระบบและอุปกรณ์ต่างๆ แม้ว่าการวิเคราะห์และแสดงผลอาจต้องใช้เครื่องมืออื่นเสริม
.
💡คำแนะนำเพิ่มเติม :
ปรึกษาผู้เชี่ยวชาญ: หากไม่แน่ใจในการเลือกโปรแกรม ควรปรึกษาผู้เชี่ยวชาญด้าน IT Security หรือผู้ที่มีประสบการณ์ในการติดตั้งและใช้งานระบบ Log Management

ที่มา: KEN CAFE Facebook

การจัดเก็บ Log file ให้ถูกกฎหมายด้วย 5 เครื่องมือ ใช้งานฟรีๆ
ขออนุญาติแชร์บทความของ อาจารย์ Ken  หัวข้อ การจัดเก็บ Log file ให้ถูกกฎหมาย

หมายเหตุ:เนื้อหาในเว็บไซต์นี้มีขึ้นเพื่อวัตถุประสงค์ในการให้ข้อมูล  เผยแพร่ความรู้และให้โอกาสในการค้นคว้าหาข้อมูลเพื่อการศึกษา   บุคคลที่สนใจโดยทั่วไป รวมถึงนักเรียน นิสิต นักศึกษา  ในการเรียนรู้เท่านั้น

* หากมีข้อมูลข้อผิดพลาดประการใด ขออภัยมา ณ ที่นี้ด้วย  รบกวนแจ้ง Admin เพื่อแก้ไขต่อไป
ขอบคุณครับ

#WINDOWSFORENSIC #COMPUTERFORENSICS #DFIR #FORENSICS #DIGITALFORENSICS #COMPUTERFORENSIC #INVESTIGATION #CYBERCRIME #FRAUD

Thursday, October 10, 2024

Digital Forensics:Log file Sample

Digital Forensics:Log file Sample

ตัวอย่าง Aข้อมูลจราจร (Log file) การเข้าถึงเว็บไซต์

2024-07-17 10:15:30 INFO User connected: IP=192.168.1.10, MAC=00:1A:2B:3C:4D:5E [1, 2]
2024-07-17 10:16:45 INFO Website accessed: URL=https://www.example.com, UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 [1, 2]
2024-07-17 10:20:00 WARNING Firewall blocked: Source IP=10.0.0.1, Destination IP=203.0.113.10, Port=80, Protocol=TCP [3]
2024-07-17 10:25:00 INFO Router rebooted [9] 

Digital Forensics:Log file Sample


1. ผู้ใช้เชื่อมต่อภายในเครือข่าย

IP/MAC:
  • IP 192.168.1.10 (IP ภายใน) + MAC 00:1A:2B:3C:4D:5E


2. การเข้าถึงเว็บไซต์

  • User-Agent:

  • เบราว์เซอร์: Chrome เวอร์ชัน 91.0.4472.124 (เวอร์ชันเก่า )
  • OS: Windows 10 (64-bit)

เว็บเป้าหมาย:

  • https://www.example.com (เว็บทั่วไป ไม่มีเนื้อหาเสี่ยง)

ตัวอย่าง B ข้อมูลจราจร (Log file)  เฟอร์วอลล์บล็อกการเชื่อมต่อ

2024-07-17 10:20:00 WARNING Firewall blocked: Source IP=10.0.0.1, Destination IP=203.0.113.10, Port=80, Protocol=TCP [3]  
Digital Forensics:Log file Sample

  • รายละเอียดเหตุการณ์:

    • Source IP = ต้นทาง: IP 10.0.0.1 (IP ภายใน อาจเป็นเราเตอร์หรือเซิร์ฟเวอร์)

    • Destination IP = ปลายทาง: IP 203.0.113.10 (IP สาธารณะ RFC 5737 ใช้สำหรับตัวอย่าง)

    • พอร์ต/โปรโตคอล: พอร์ต 80 (HTTP) + โปรโตคอล TCP


  • การวิเคราะห์:

สาเหตุการบล็อก:
- นโยบายองค์กรไม่อนุญาตให้ส่งข้อมูล HTTP ผ่านพอร์ต 80  
- อาจเป็นการพยายามส่งข้อมูลละเอียดอ่อน (Log, Credential) ไปภายนอก

      • ความเสี่ยงสูง:

      • Source IP = IP ต้นทาง (10.0.0.1) อาจถูกบุกรุกหรือตั้งค่าผิดพลาด
      • Destination IP =ปลายทาง 203.0.113.10 อาจเป็น C2 Server (Command & Control) ของมัลแวร์


    ตัวอย่าง C  ข้อมูลจราจร (Log file) เราเตอร์บูตใหม่

    2024-07-17 10:25:00 INFO Router rebooted 

      • ความสัมพันธ์กับเหตุการณ์อื่น:

      - เกิด 5 นาที หลังจากเฟอร์วอลล์บล็อกการเชื่อมต่อ 
      •   - ไม่มีแท็ก [1,2,3] → อาจเป็นการบูตโดยผู้ดูแลระบบ หรือเกิดจากเหตุอื่น
      สรุปความสัมพันธ์และความเสี่ยง

      Digital Forensics:Log file Sample

      ตัวอย่าง D  ข้อมูลจราจร (Log file)  การเข้าถึงเว็บไซต์

      2025-07-17 14:33:27 NAT 10.0.0.12:58432 → 203.113.23.45:58432 TCP www.example.com 104.18.21.190 443 00:05:32

      รายละเอียดเหตุการณ์:

      Source IP = ต้นทาง: IP 10.0.0.12 (IP ภายในอาจเป็นเราเตอร์หรือเซิร์ฟเวอร์ อุปกรณ์ในเครือข่าย)
      Destination IP = ปลายทาง: IP 203.113.23.45 (IP Public Gateway) → DNS ปลายทางจริงwww.example.com (IP 104.18.21.190)
      พอร์ต/โปรโตคอล: พอร์ต 443 (HTTPS)  

      ตัวอย่าง E  ข้อมูลจราจร (Log file)  การซิงค์เวลาจากเซิร์ฟเวอร์

      2025-07-17 14:35:10 NAT 10.0.0.13:52678 → 203.113.23.46:52678 UDP ntp.org 129.6.15.28 123 00:00:02

      รายละเอียดเหตุการณ์:

      Source IP = ต้นทาง: IP 10.0.0.13 (IP ภายในอาจเป็นเราเตอร์หรือเซิร์ฟเวอร์ อุปกรณ์ในเครือข่าย)
      Destination IP = ปลายทาง: IP 203.113.23.46 (IP Public Gateway) →   ปลายทางภายนอก ntp.org  (IP 129.6.15.28)
      พอร์ต/โปรโตคอล:  UDP/123 (NTP - Network Time Protocol)

      ตัวอย่าง F  ข้อมูลจราจร (Log file)  การเข้าถึงเว็บไซต์ฟิชชิ่ง

      2025-07-17 14:36:01 HTTP_ACCESS customer@isp.co.th GET http://phishing-site.com/index.html 104.21.24.190

      รายละเอียดเหตุการณ์:

               - ผู้ใช้:customer@isp.co.th (บัญชีผู้ใช้ customer)
               - การร้องขอ: GET http://phishing-site.com/index.html
      - Destination IP = ปลายทาง: IP 104.21.24.190

                - พอร์ต/โปรโตคอล: HTTP (ไม่มีการเข้ารหัส!)

      Lab 1 ข้อมูลจราจร (Log file) (สถิติการใช้งานเครือข่าย)

      2025-07-17 10:30:45 NETFLOW: SrcIP=110.170.25.67, DstIP=104.16.24.35, Proto=TCP, SrcPort=54321, DstPort=443, Bytes=15.7MB, Pkts=11230, Duration=00:05:22

      Source IP: = ?

      Destination IP : =?

      port/protocol = พอร์ต/โปรโตคอล: ?


      Lab 2 ข้อมูลจราจร (Log file) (การเชื่อมต่อเครือข่าย)

      2025-07-17 08:12:34 PPPoE-SESSION START: User=customer123@isp.co.th, NAS=bras-01.bangkok.isp, IP=110.170.25.67, MAC=00:1B:44:11:3A:E7, Duration=00:02:15
      2025-07-17 12:45:21 PPPoE-SESSION STOP: User=customer456@isp.co.th, NAS=bras-02.chiangmai.isp, IP=110.170.33.122, RX=1.45GB, TX=350MB, Duration=04:22:10

      Digital Forensics:Log file Sample


      อ่านเพิ่มเติม:


      หมายเหตุ:เนื้อหาในเว็บไซต์นี้มีขึ้นเพื่อวัตถุประสงค์ในการให้ข้อมูล  เผยแพร่ความรู้และให้โอกาสในการค้นคว้าหาข้อมูลเพื่อการศึกษา   บุคคลที่สนใจโดยทั่วไป รวมถึงนักเรียน นิสิต นักศึกษา  ในการเรียนรู้เท่านั้น

      * หากมีข้อมูลข้อผิดพลาดประการใด ขออภัยมา ณ ที่นี้ด้วย  รบกวนแจ้ง Admin เพื่อแก้ไขต่อไป
      ขอบคุณครับ

      #WINDOWSFORENSIC #COMPUTERFORENSICS #DFIR #FORENSICS #DIGITALFORENSICS #COMPUTERFORENSIC #INVESTIGATION #CYBERCRIME #FRAUD

      Volatility Lab

      Volatility Lab  Image Wanna.vmem P.73 windows.info #python3  vol.py   -f '/home/kali/Desktop/Wanna/Wanna-MEM.vmem' windows.info     ...