How to Investigate a Linux System Breach?

When a company experiences a hacker intrusion; when the system crashes; when a security incident affects normal business operations, can you respond immediately and provide a solution? The following article will teach you the Linux emergency response process!

How to Investigate a Linux System Breach?

Intrusion Investigation Approach

01

How to Investigate a Linux System Breach?

Apache Log Path

How to Investigate a Linux System Breach?

Access Log:

/var/log/apache2/access.log (Debian/Ubuntu) or /var/log/httpd/access_log (CentOS/RHEL)

How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?

Nginx Log Path

Access Log:

/var/log/nginx/access.log

Apache Root Directory

Debian/Ubuntu (including Kali Linux):

/var/www/html/

CentOS/RHEL:

/var/www/html/

In Nginx the default root directory is usually:

Debian/Ubuntu systems: /var/www/html CentOS/RHEL systems: /usr/share/nginx/html

How to Investigate a Linux System Breach?

02

How to Investigate a Linux System Breach?

Detection & Analysis

How to Investigate a Linux System Breach?

System Status Check

Process Analysis

top -c                     # View processes with abnormal CPU/memory usage ps aux --sort=-%cpu       # Sort processes by CPU usage pstree -p                 # View process tree to find abnormal parent-child relationships

How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?

Network Connection Analysis

netstat -antp | grep ESTABLISHED  # View active connections lsof -i :suspicious_port  # Locate the process listening on the port ss -tulwn                       # Replace netstat, show more detailed network information

How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?

User and Login Check

last -ai                   # View login records (focus on root user) grep "Accepted" /var/log/auth.log  # Check SSH successful login logs cat /etc/passwd | grep -E "/bin/bash|/bin/sh"  # Check loggable users

How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?

Username: Password: User ID: Group ID: User Description: Home Directory: Login Shell

1. Query privileged users (uid is 0)

[root@localhost ~]# awk -F: '$3==0{print $1}' /etc/passwd;

How to Investigate a Linux System Breach?

2. Query accounts that can log in remotely

[root@localhost ~]# awk '/\$1|\$6/{print $1}' /etc/shadow

3. Check if other accounts besides root have sudo privileges. If not needed for management, ordinary accounts should have sudo privileges removed.

[root@localhost ~]# more /etc/sudoers | grep -v "^#\|^$" | grep "ALL=(ALL)"

4. Disable or delete unnecessary and suspicious accounts

  usermod -L user    Disable account, account cannot log in, /etc/shadow second column starts with !  userdel user       Delete user
  userdel -r user    Delete user and also remove the user directory under /home

How to Investigate a Linux System Breach?

File System Check

Sensitive File Scan

find / -name "*.php" -mtime -3   # Find PHP files modified in the last 3 days (WebShell) find / -perm -4000 -ls           # Find SUID privilege escalation files grep -r "eval(base64_decode" /var/www/html  # Scan for encrypted code in web directory

How to Investigate a Linux System Breach?

Hidden File Detection

ls -la /tmp              # View hidden files in /tmp directory lsattr /suspicious_file         # Check file hidden attributes (e.g., undeletable)

How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?

Log Analysis

System Logs

journalctl -u sshd   # View SSH service logs tail -f /var/log/secure      # Real-time monitor authentication logs

How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?

Terminate Malicious Processes

ps -aux                          # View processes kill -9 malicious_process_PID               # Force terminate process systemctl stop malicious_service_name         # Stop malicious service

How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?

Check Scheduled Tasks

1. Create scheduled tasks using crontab

crontab -l List detailed contents of a user's cron service

How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?

Check System Logs

Default log storage location: /var/log/ Check log configuration: more /etc/rsyslog.conf

How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?How to Investigate a Linux System Breach?

Leave a Comment