How to track deleted log files in a compromised Linux system

0 votes

After a suspected security incident, I discovered that certain log files were deleted. I want to determine if there’s a way to recover or track what was deleted. My concerns are:

  • How to check for signs of log file deletion using system metadata (e.g., lsof, auditd logs)?
  • How to recover deleted log files from disk (e.g., extundelete, foremost)?
  • What are the best practices for securing logs against tampering, such as forwarding logs to a remote server?

Any insights into forensic techniques for detecting log tampering would be appreciated.

Feb 25 in Cyber Security & Ethical Hacking by Anupam
• 12,620 points
43 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Dealing with deleted log files on a compromised Linux system requires a methodical approach to detect, recover, and prevent future tampering. Here's how you can address each of your concerns:

1. Detecting Signs of Log File Deletion Using System Metadata

  • Using lsof (List Open Files): This command helps identify processes that have files open, including deleted ones.

lsof | grep '(deleted)'

This will list files that are still open by processes but have been deleted from the filesystem.

  • Checking auditd Logs: The Linux Auditing System (auditd) can track file deletions if it was configured prior to the incident.

    • View Audit Logs:

      ausearch -k delete

      This searches for events tagged with the key "delete".

    • Set Up Monitoring for Future Events:

      auditctl -w /var/log/ -p wa -k log_monitor

      This command sets a watch on the /var/log/ directory for write and attribute changes, tagging them with "log_monitor".

2. Recovering Deleted Log Files from Disk

  • Using extundelete: If your system uses the ext3 or ext4 filesystem, extundelete can help recover deleted files.

    • Unmount the Filesystem:

      umount /dev/sdX#

      Replace /dev/sdX# with the appropriate device identifier.

    • Recover Files:

      extundelete /dev/sdX# --restore-directory /var/log/

      This attempts to restore deleted files in the /var/log/ directory.

  • Using foremost: A file carving tool that can recover files based on their headers, footers, and internal data structures.

    • Run foremost:

      foremost -i /dev/sdX# -o /recovery_output/ 

      This scans the device and outputs recovered files to /recovery_output/.

3. Best Practices for Securing Logs Against Tampering

  • Remote Log Forwarding: Send logs to a dedicated remote server to ensure they remain intact even if the local system is compromised.

    • Using rsyslog:

      • Configure the Remote Server: On the remote server, enable reception of logs.

        # In /etc/rsyslog.conf or /etc/rsyslog.d/remote.conf
        module(load="imtcp")
        input(type="imtcp" port="514") 
      • Configure the Local Machine: On the local machine, forward logs to the remote server.

        # In /etc/rsyslog.conf or /etc/rsyslog.d/remote.conf
        *.* @@remote-server-ip:514
  • Implementing Immutable Log Files: Set log files to be immutable, preventing even the root user from modifying or deleting them.

    • Make Logs Immutable:

      chattr +i /var/log/syslog

      Replace /var/log/syslog with the specific log file you want to protect.

    • Remove Immutability (if necessary):

      chattr -i /var/log/syslog

4. Forensic Techniques for Detecting Log Tampering

  • Check for Gaps in Log Timestamps: Inconsistent or missing timestamps can indicate tampering.

  • Verify Log Integrity with Checksums: Generate and compare checksums of log files to detect unauthorized changes.

    • Generate a Checksum:

      sha256sum /var/log/syslog
    • Regularly Verify Checksums: Compare the current checksum with a known good value to detect alterations.

  • Use Specialized Forensic Tools: Tools like chkrootkit and rkhunter can help detect rootkits and signs of log tampering.

    • Run chkrootkit:

      chkrootkit
    • Run rkhunter:

      rkhunter --check

By implementing these steps, you can enhance the security of your log files and improve your ability to detect and respond to unauthorized deletions or modifications.

answered Feb 25 by CaLLmeDaDDY
• 22,940 points

edited Mar 6

Related Questions In Cyber Security & Ethical Hacking

0 votes
1 answer

How do you detect log tampering in a compromised system?

Ensuring the integrity of system logs is ...READ MORE

answered Feb 21 in Cyber Security & Ethical Hacking by CaLLmeDaDDY
• 22,940 points
116 views
0 votes
0 answers

How to check file integrity in a read-write file system on Linux?

Ensuring file integrity is crucial for security ...READ MORE

Mar 6 in Cyber Security & Ethical Hacking by Anupam
• 12,620 points
36 views
0 votes
1 answer

How to close a port in Linux?

Closing ports in Linux is essential for ...READ MORE

answered Nov 13, 2024 in Cyber Security & Ethical Hacking by CaLLmeDaDDY
• 22,940 points
121 views
0 votes
1 answer

How to script a privilege escalation attack simulation in Linux?

Simulating a privilege escalation attack in Linux ...READ MORE

answered Feb 19 in Cyber Security & Ethical Hacking by CaLLmeDaDDY
• 22,940 points
90 views
0 votes
0 answers

How to check integrity of a file in Linux?

I want to verify whether a file ...READ MORE

Feb 26 in Cyber Security & Ethical Hacking by Anupam
• 12,620 points
47 views
0 votes
1 answer
+1 vote
1 answer

How do you decrypt a ROT13 encryption on the terminal itself?

Yes, it's possible to decrypt a ROT13 ...READ MORE

answered Oct 17, 2024 in Cyber Security & Ethical Hacking by CaLLmeDaDDY
• 22,940 points
452 views
+1 vote
1 answer

How does the LIMIT clause in SQL queries lead to injection attacks?

The LIMIT clause in SQL can indeed ...READ MORE

answered Oct 17, 2024 in Cyber Security & Ethical Hacking by CaLLmeDaDDY
• 22,940 points
422 views
+1 vote
1 answer

Is it safe to use string concatenation for dynamic SQL queries in Python with psycopg2?

The use of string concatenation while building ...READ MORE

answered Oct 17, 2024 in Cyber Security & Ethical Hacking by CaLLmeDaDDY
• 22,940 points
276 views
+1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP