CAS-005 · Question #391
SIMULATION You are about to enter the virtual environment. DO NOT perform the following actions within the virtual environment. Making any of these changes will cause the virtual environment to fail…
Explanation: Identifying and Remediating a Malicious TCP Service + Systemd Persistence --- Overall Goal An attacker exploited a vulnerability, gained access, and left two artifacts behind even after the vulnerability was patched: 1. A malicious TCP listener - a backdoor or…
Question
Explanation
Explanation: Identifying and Remediating a Malicious TCP Service + Systemd Persistence
Overall Goal
An attacker exploited a vulnerability, gained access, and left two artifacts behind even after the vulnerability was patched:
- A malicious TCP listener - a backdoor or reverse shell process still running in memory
- A systemd service - persistence so the backdoor restarts automatically on reboot
Patching the vulnerability only closes the door of entry. It does not evict the attacker who is already inside. You must manually find and remove both artifacts. The order matters: find first, then kill, then disable persistence.
Step 1: Identify and Kill the Malicious TCP Process
Step 1.1 - sudo netstat -tulnp
This lists all TCP and UDP sockets that are listening, shows numeric addresses (no DNS resolution), and includes the process name/PID owning each socket.
Why necessary: You cannot kill what you cannot find. Netstat gives you the map from port -> PID. Attackers often use ports like 4444, 1337, 9001, or other non-standard ports that have no legitimate reason to be listening.
What to look for: Any entry under LISTEN on a port that isn't expected (SSH=22, HTTP=80/443, etc.). The last column shows PID/process-name.
If skipped: You'd have no way to identify which process to kill without blind guessing.
Step 1.2 - ps aux | grep <PID>
Cross-references the PID from netstat against the full process list to see the command line that launched it.
Why necessary: The process name in netstat may be truncated or obfuscated (e.g., bash, python3, sshd2). The full command line from ps reveals the actual script or binary path, confirming it's malicious.
If skipped: You risk killing a legitimate system process with a similar name, or missing confirmation that you have the right target.
Step 1.3 - sudo kill <PID> or sudo killall <name>
Terminates the running process, severing the attacker's active connection and stopping the malicious listener.
Why necessary: The process is actively running and potentially exfiltrating data or awaiting commands. It must be stopped immediately.
If done before Step 1.1: You don't know what to kill. If skipped entirely: The attacker remains connected. Even if you disable the service (Step 2), the current session stays alive.
Step 2: Disable the Malicious systemd Service (Persistence)
Step 2.1 - systemctl list-units --type=service
Lists all currently loaded systemd services.
Why necessary: Killing the process (Step 1) only stops it this session. The systemd service will restart it on next boot or even automatically via Restart=always in the unit file. You must find the service definition to neutralize it permanently.
What to look for: Service names that don't match standard Linux services - things like update-helper.service, sysmonitor.service, or anything that sounds vague or generic.
Step 2.2 - systemctl status <suspicious-service> / cat /etc/systemd/system/<name>.service
Inspects the service unit file to confirm it's malicious and see what binary it runs.
Why necessary: Confirms you have the right service before disabling it. The ExecStart= line in the unit file will show the exact command (e.g., ExecStart=/tmp/backdoor or ExecStart=/bin/bash -i >& /dev/tcp/...).
If skipped: You might disable a legitimate service by mistake, potentially breaking the system.
Step 2.3 - sudo systemctl disable <suspicious-service>
Removes the service's symlink from the boot targets, preventing it from starting on reboot.
Why necessary: This is the core remediation for persistence. disable does not stop a currently running instance - it only prevents future auto-starts.
If done without Step 1.3: The service is still running right now. If skipped: The malware comes back after every reboot.
Step 2.4 - sudo systemctl stop <suspicious-service>
Stops the service if it's still running (e.g., if it relaunched itself after you killed the PID).
Why necessary: disable only affects boot behavior. If the service respawned after the kill in Step 1, stop terminates it via systemd's own process management.
Order note: stop before or after disable both work, but disable first ensures it won't restart if stop triggers a restart policy.
What Goes Wrong If Steps Are Out of Order
| Mistake | Consequence |
|---|---|
| Kill process before finding it | Nothing to target; guesswork |
| Disable service but skip kill | Attacker's current session stays live |
| Kill process but skip disable | Malware returns on reboot |
Skip ps verification | Risk killing wrong process |
Memory Tip
Think "Find, Verify, Kill, Audit, Disable, Stop" - or the acronym FVKADS:
Find the port (netstat) -> Verify the process (ps) -> Kill it -> Audit the service list -> Disable the persistence -> Stop any remnant
A simpler mental model: treat it like evicting a squatter. First you find them (netstat), confirm their identity (ps), remove them now (kill), then change the locks so they can't get back in (disable + stop the service).
Topics
Community Discussion
No community discussion yet for this question.