Kahibaro
Discord Login Register

Analyzing suspicious processes

Goals and mindset for process analysis

When you see a suspicious process, your goals are to:

In incident response, you usually observe first, change later:

This chapter assumes you already have:

Here we focus specifically on how to interrogate suspicious processes.

Recognizing suspicious processes

You rarely start from a blank slate. Typical triggers:

When scanning processes, red flags include:

Capturing a process snapshot

Before changing anything, take a quick snapshot of what’s running and what each suspicious process is doing. This is often your only chance if an attacker notices your presence.

Baseline process listing

Use ps with extensive columns to capture a point‑in‑time process list:

ps auxww > /root/ps_snapshot_$(date +%F_%H%M%S).txt

Options explained briefly:

For tree view, which is vital to understand parent–child relationships:

ps axfww -o pid,ppid,uid,gid,cmd > /root/ps_tree_$(date +%F_%H%M%S).txt

Look for:

Using `pstree` for hierarchy

pstree is useful for visual inspection:

# Entire tree, with PIDs and user names
pstree -alp > /root/pstree_$(date +%F_%H%M%S).txt
# Filter by a specific suspicious PID
pstree -alp <PID>

This helps answer:

Take targeted snapshots

For each suspicious process <PID>, immediately save:

  # Process info
  ps -p <PID> -o pid,ppid,user,group,start,time,cmd >> /root/proc_<PID>.txt
  # Environment if readable
  tr '\0' '\n' < /proc/<PID>/environ >> /root/proc_<PID>_env.txt 2>/dev/null
  ls -al /proc/<PID>/cwd >> /root/proc_<PID>_cwd.txt
  ls -l /proc/<PID>/fd >> /root/proc_<PID>_fd.txt
  cat /proc/<PID>/maps > /root/proc_<PID>_maps.txt

These /proc paths are volatile but extremely informative while the process lives.

Inspecting a single suspicious process

Once you have candidate PIDs, dive into each one methodically.

Verify the executable and its location

Use ls and /proc/<PID>/exe:

# What binary is this process actually executing?
ls -l /proc/<PID>/exe
# Where is it on disk?
realpath /proc/<PID>/exe

Questions to ask:

  stat -c 'Owner:%U Group:%G Size:%s mtime:%y' "$(realpath /proc/<PID>/exe)"

If the binary is missing but the process still runs, /proc/<PID>/exe will be dangling ((deleted)); this is common for malware trying to hide:

ls -l /proc/<PID>/exe
# Example output:
# lr-x------ 1 root root 0 ... /proc/1234/exe -> /tmp/.xyz (deleted)

In that case, use cp /proc/<PID>/exe (see below) to preserve the image.

Collect a copy of the executable image

If allowed by policy, copy the binary for offline analysis:

cp /proc/<PID>/exe /root/evidence/exe_<PID>_$(date +%F_%H%M%S)
sha256sum /root/evidence/exe_<PID>_* >> /root/evidence/checksums.txt

If /proc/<PID>/exe is a deleted binary, this is sometimes the only way to recover it.

Examine the command line

The command line shows how the process was started:

tr '\0' ' ' < /proc/<PID>/cmdline; echo

Look for:

Preserve it as evidence:

tr '\0' ' ' < /proc/<PID>/cmdline >> /root/proc_<PID>_cmd.txt

Environment variables

Environment can reveal:

tr '\0' '\n' < /proc/<PID>/environ | sort >> /root/proc_<PID>_env.txt 2>/dev/null

Sensitive info may appear here, so handle carefully and store securely.

Current working directory and associated files

The working directory often points to where the process or its payload resides:

ls -al /proc/<PID>/cwd
realpath /proc/<PID>/cwd
ls -al "$(realpath /proc/<PID>/cwd)" > /root/proc_<PID>_cwd_list.txt

Suspicious if:

Inspecting open files and network activity

Understanding what a process has open is crucial for spotting exfiltration, keylogging, crypto‑mining, or lateral movement.

`lsof` overview

lsof (“list open files”) is one of the most useful tools:

# All open files for a PID
lsof -p <PID> > /root/proc_<PID>_lsof.txt
# Only network‑related
lsof -Pan -p <PID> -i
# All listening sockets system‑wide
lsof -Pan -iTCP -sTCP:LISTEN

Pitfalls:

Network connections via `/proc` or `ss`

Brief, low‑level methods:

# Human-friendly socket info
ss -pant | grep <PID>
# Or use 'netstat' on older systems
netstat -plant | grep <PID>

Suspicious signs:

For encrypted connections, you may not see payloads, but you still get:

Open files and pipes

From lsof -p <PID> or /proc/<PID>/fd, note:

Example to dump an open deleted file:

# Identify fd number from lsof output, e.g., 5u REG /tmp/.x (deleted)
cp /proc/<PID>/fd/5 /root/evidence/deleted_<PID>_fd5

CPU, memory, and behavior patterns

Resource use patterns can indicate certain malware families or activities.

CPU and memory usage

Use top/htop interactively, or ps for snapshots:

ps -p <PID> -o pid,user,%cpu,%mem,etime,cmd

Clues:

Thread and child process activity

Many advanced threats spawn numerous threads or children:

# Count threads
ls -1 /proc/<PID>/task | wc -l
# View tasks
ls -1 /proc/<PID>/task

Extremely high thread counts can be a sign of:

Use ps to see children:

ps --ppid <PID> -o pid,user,%cpu,%mem,cmd

Correlating processes with users and logins

Identify which user context and login session a suspicious process is tied to.

Basic user mapping

From ps:

ps -p <PID> -o pid,user,group,cmd

Look up the user in /etc/passwd or with id:

id <username>

Questions:

TTY and login sessions

If the process is interactive (shell, editor), see if it is attached to a terminal:

ps -p <PID> -o tty,pid,user,cmd

For interactive logins, correlate with:

who
w
last -n 20

This helps you answer:

Identifying persistence linked to processes

A suspicious process might be part of a persistence mechanism. Use your process as a starting point to hunt:

From the process command line or tree, jot down:

You will analyze these in depth as part of persistence and configuration review, not necessarily at process‑time.

Handling kernel‑level or stealth processes (rootkits)

Some advanced threats hide processes from userland tools.

Indicators of possible rootkit influence:

Basic cross‑checks:

  # Count numeric dirs in /proc (rough process count)
  ls /proc | grep '^[0-9]\+$' | wc -l
  # Compare with: 
  ps ax | wc -l

In deeper cases, you may:

Those topics are typically covered in specialized forensic tooling chapters; here, recognize that when process listings are inconsistent, your trust in local tools must decrease.

Deciding what to do with a suspicious process

Once you understand a process reasonably well, choose how to act:

Preserve, then contain

Trigger checklist before termination (if time permits and risk is acceptable):

  1. Captured:
    • ps outputs and process tree.
    • /proc/<PID>/cmdline, environ, cwd, fd, maps.
    • Network connections from ss/lsof.
    • Executable copy from /proc/<PID>/exe (if allowed).
  2. Correlated:
    • Parent PID and its process info.
    • User account, login session, and basic logs around start time.
  3. Checked:
    • Any obvious persistence (systemd units, cron jobs, startup scripts).

Terminating or isolating

If the process is actively harmful (e.g., encryption, data exfiltration):

    kill <PID>        # SIGTERM
    kill -9 <PID>     # SIGKILL (irreversible, bypasses cleanup)

Document:

Practical triage workflow example

A minimal, repeatable workflow you can apply under pressure:

  1. Identify candidates
    • ps auxww and ps axfww to locate odd processes.
  2. Pick one suspicious PID
    • Criteria: unknown name, odd location, high CPU, strange parent.
  3. Snapshot everything quickly
    • ps -p <PID> -o pid,ppid,user,%cpu,%mem,etime,cmd
    • /proc/<PID>/{cmdline,environ,cwd,fd,maps} to files in /root/evidence.
    • lsof -p <PID> and ss -pant | grep <PID>.
    • Copy /proc/<PID>/exe if permitted.
  4. Analyze context
    • Confirm binary path and owner.
    • Examine environment and working directory.
    • Check open network connections and files.
    • Map to user and login session (who, last).
  5. Check for relatives
    • pstree -alp <PID> and ps --ppid <PID>.
    • Investigate parent PID similarly if suspicious.
  6. Decide action
    • If benign ⇒ document and move on.
    • If malicious/suspicious ⇒ coordinate containment, then terminate after evidence captured.
  7. Log everything
    • Commands run.
    • Files collected (with hashes).
    • Observations and timestamps.

This systematic approach helps you remain consistent and defensible in incident response, even under time pressure.

Views: 33

Comments

Please login to add a comment.

Don't have an account? Register now!