How to Detect and Recover From Linux Server Intrusions: Practical Steps
This guide outlines ten practical methods for Linux administrators to identify compromised machines on CentOS, including log inspection, checking /etc/passwd and /etc/shadow, analyzing login records, monitoring network traffic, and using lsof to recover deleted log files, with step‑by‑step commands and examples.
Background
With the growing popularity of open‑source products, Linux operations engineers must be able to quickly determine whether a machine has been compromised. The following procedures were tested on CentOS 6.9 and are applicable to other Linux distributions.
Common Compromise Indicators
Log files may be deleted or cleared. Verify the presence and integrity of logs such as /var/log/lastlog, /var/log/secure, and others.
Attackers may create or modify /etc/passwd and /etc/shadow. Examine these files for unexpected entries.
Check recent successful and failed login events using /var/log/lastlog.
Inspect currently logged‑in users via /var/run/utmp.
Review historical login records from /var/log/wtmp, including total connection time per user.
Monitor abnormal network traffic with tcpdump or iperf.
Search /var/log/secure for suspicious activity.
Process Inspection
Identify abnormal processes and their associated scripts:
Use top to find the PID of suspicious processes.
Locate the executable file in the virtual filesystem, e.g., /proc/<em>PID</em>/fd.
Recovering Deleted Files with lsof
If a critical log such as /var/log/secure has been removed, it can be recovered as long as a process still holds an open file descriptor.
Confirm the file is missing.
Run lsof | grep /var/log/secure to see which process (e.g., PID 1264 rsyslogd) still has the file open.
Inspect the descriptor path, e.g., /proc/1264/fd/4, which points to the deleted file’s data.
Redirect the descriptor’s contents to a new file: cat /proc/1264/fd/4 > /var/log/secure.
Verify that /var/log/secure is restored and contains the expected logs.
These steps are valuable for recovering deleted log files or databases that remain open by running processes.
Illustrative Commands (Images)
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
