How Remote Access Trojans (RATs) Work — and How to Defend Against Them

A defender's walkthrough of what a RAT actually is, the client/server/C2 architecture, why almost all of them "call home" through NAT, the role of port forwarding, the real-world consequences, and how to detect and stop them.

· 8 min read · intermediate

A Remote Access Trojan is malware that gives an attacker interactive remote control over a machine, while pretending to be something harmless. The "trojan" part is the deception; the "remote access" part is the capability. Technically a RAT is very close to legitimate remote-administration software such as TeamViewer, AnyDesk or an RMM agent — the difference is consent and intent, not the underlying mechanism. That overlap is exactly why RATs are hard to spot: the traffic can look like ordinary remote support.

The three moving parts

Almost every RAT, whether it is a cheap commodity tool or a nation-state implant, breaks down into the same three components.

ComponentWhere it runsWhat it does
Implant (agent / stub)The victim machineThe code that actually executes commands: keystrokes, files, screen, webcam, shell.
Controller (operator console)The attacker's machineThe UI the attacker uses to issue commands and view results.
C2 server (command-and-control)A server the attacker controlsThe meeting point the implant connects to and the controller talks through.

The crucial insight for a defender: the implant and controller almost never talk directly. They talk through the C2 server. Understanding why tells you most of what you need to know about detecting RATs on the wire.

Why RATs "call home": the NAT problem

Imagine the naive design — the attacker connects to the victim. This is called a bind connection: the implant opens a listening port and waits.

text
Attacker  ──────────────▶  Victim:4444  (implant is LISTENING)

This almost never works on the modern internet, for one simple reason: NAT. A victim on a home or corporate network does not have a public IP. They sit behind a router doing Network Address Translation, and that router drops unsolicited inbound connections. There is no path from the attacker's machine to victim:4444 unless someone deliberately opened one.

So real RATs invert the direction. The implant makes an outbound connection to the C2 server. This is a reverse connection:

text
Victim  ──────────────▶  C2 server:443   (implant CONNECTS OUT)
Attacker ─────────────▶  C2 server        (operator connects to the same server)

Outbound connections sail straight through NAT and most firewalls, because firewalls are usually permissive outbound — your browser, your updates and your chat apps all need to reach out. The implant rides the same lane. Once the outbound tunnel is established, the attacker sends commands down the connection the victim itself opened.

Where port forwarding comes in

If reverse connections avoid NAT, where does port forwarding fit? On the attacker's side, not the victim's.

The C2 server has to be reachable from the internet so the implant can connect to it. If the attacker runs their listener on a laptop behind their own home router, that router also does NAT and also blocks inbound. So the attacker configures a port-forwarding rule on their router: "any traffic arriving on public port 443, send it to my laptop's internal address on port 443." Now the implant's outbound connection can actually land.

text
                    ┌─────────── attacker's router (public IP) ───────────┐
Victim ──▶ :443 ──▶ │  port-forward 443 ──▶ 192.168.1.50:443 (listener)   │
                    └──────────────────────────────────────────────────────┘

In practice, sophisticated operators skip home port forwarding entirely and rent a VPS with a public IP (no NAT to fight), or hide behind a redirector — a cheap front-end server that just relays traffic to the real C2, so the victim never sees the operator's true infrastructure. Some even tunnel through legitimate services so the destination looks like *.cloudfront.net or a trusted SaaS domain ("domain fronting" and its successors). The topology gets more layered, but the core direction never changes: victim dials out.

Putting the topology together

text
  [ Victim PC ]                         [ Redirector / VPS ]            [ Operator ]
  implant ──────── TLS :443 ───────────▶  relays traffic  ◀──────────── controller
      ▲                                        │
      └──── outbound through NAT/firewall ─────┘

Every hop that matters is initiated left-to-right by the victim. The operator may be on another continent, behind their own NAT, asleep — the session persists because the tunnel is held open from the inside.

What the implant can actually do

Once the channel is up, the operator has a menu. Typical capabilities, roughly in order of how commonly they appear:

  • Command execution — run arbitrary commands / a remote shell. This is the foundation; everything else can be built on it.
  • File operations — browse, download (exfiltrate) and upload (drop more tools) files.
  • Keylogging and clipboard capture — harvest credentials and 2FA codes as they are typed.
  • Screen capture / live screen — watch or record the desktop.
  • Webcam and microphone — surveillance; also used for extortion.
  • Credential and token theft — dump browser-saved passwords, session cookies, cloud tokens.
  • Persistence — survive reboots via scheduled tasks, services, registry run keys or startup entries.
  • Privilege escalation hooks — attempt to gain admin/SYSTEM so the rest becomes easier.
  • Pivoting / proxying — use the victim as a jump box to reach machines the attacker otherwise couldn't, turning one foothold into a network-wide problem.

Not every RAT has every feature, but "remote shell + file transfer + persistence" is the near-universal core.

The consequences — why this matters

It is tempting to think of a RAT as "someone can see my screen." The real impact is broader and compounding:

  1. Total confidentiality loss. Anything the user can read, the attacker can read: documents, email, password managers, source code, chat history.
  2. Credential cascade. Stolen passwords and session tokens unlock other systems — VPNs, cloud consoles, banking — often without needing the RAT any more.
  3. Lateral movement. Using pivoting, one infected laptop becomes the launch point for the whole network. Most ransomware incidents begin with exactly this kind of foothold.
  4. Persistence and dwell time. Well-run intrusions sit quietly for weeks or months, learning the environment before acting. The average dwell time for undetected intrusions is routinely measured in weeks.
  5. Integrity and availability. The attacker can alter data, plant further malware, or detonate ransomware — turning a quiet spy into an outage.
  6. Legal and regulatory fallout. For organisations, a confirmed RAT often triggers breach-notification duties, regulatory scrutiny and contractual penalties.

A RAT is rarely the end goal. It is the beachhead.

How infections usually start

Defenders waste effort if they only watch the network. The implant has to get executed first, and that almost always happens through the human layer:

  • Phishing attachments — a "invoice.pdf.exe", a macro-enabled document, an ISO/LNK lure.
  • Trojanised downloads — cracked software, fake installers, poisoned search-ad results.
  • Malvertising and fake updates — "your browser is out of date" pages.
  • Supply-chain compromise — a legitimate tool shipped with a backdoor.
  • Exploits — far rarer for commodity RATs, more common for targeted ones.

The common thread: initial execution is a people-and-process problem as much as a technical one.

Detection — where RATs give themselves away

Because the implant must communicate, it leaves signals. The most reliable ones:

On the network

  • Beaconing. Implants "check in" on a schedule. Humans browse irregularly; an implant that phones home every 60 seconds (even with jitter) produces a tell-tale periodic pattern. Beacon-detection analytics look for exactly this regularity.
  • Odd destinations. Connections to freshly registered domains, raw IPs, cloud VPS ranges, or countries your business never deals with.
  • Protocol mismatch. "HTTPS" on 443 that never completes a normal TLS handshake, or DNS queries far larger and more frequent than normal (DNS tunnelling).
  • Long-lived outbound sessions to a single host, especially from a server that should not be browsing the web.

On the host

  • Unexpected persistence — new scheduled tasks, services, run keys, or autostart entries.
  • Suspicious parent/child process chains — e.g. a document viewer spawning a shell, or a shell spawning a network tool.
  • Living-off-the-land abuse — legitimate system binaries used in illegitimate ways.
  • Unsigned or oddly located executables running from temp or user-profile directories.

Endpoint Detection & Response (EDR) tooling exists precisely to spot these host behaviours; network detection (IDS/NDR) and DNS logging catch the communication side. You want both.

Defence — a layered checklist

Reduce the chance of execution

  • Harden email: attachment filtering, link rewriting, DMARC/SPF/DKIM.
  • Application allow-listing so unknown binaries simply cannot run.
  • Block or disable macros, and treat ISO/LNK attachments as hostile by default.
  • Keep users as non-admins; separate privileged accounts from daily-driver accounts.

Limit what an implant can reach (this is the big one)

  • Egress filtering. Default-deny outbound; allow only the destinations and ports a host genuinely needs. This directly attacks the "call home" model.
  • DNS filtering and logging. Block newly-registered and known-bad domains; log every query so tunnelling stands out.
  • Network segmentation. Stop a single foothold from reaching everything — kill the pivoting path.

Catch it when it runs anyway

  • Deploy EDR and actually tune and watch it.
  • Centralise logs (host, DNS, proxy, firewall) into a SIEM and alert on beaconing and anomalous egress.
  • Hunt proactively for persistence mechanisms.

Be ready to respond

  • Have an incident-response plan: isolate the host (pull it off the network, don't just power it off and lose memory evidence), rotate exposed credentials, and assume anything the account could touch is compromised until proven otherwise.

The legitimate cousins

It is worth repeating that the mechanism is not inherently evil. Reverse connections through NAT power plenty of legitimate tools: remote-support software, your CI runner reaching a build server, an IoT device phoning a cloud backend, even ssh -R reverse tunnels used by sysadmins every day. The line is authorisation. A reverse shell you set up on your own lab VM to learn is a networking exercise; the identical technique on someone else's machine without consent is a felony.

Key takeaways

  • A RAT = implant on the victim + controller for the operator + C2 in between.
  • Victims sit behind NAT, so implants use reverse (outbound) connections — they dial out, the attacker rides back.
  • Port forwarding matters on the attacker's infrastructure, to make the C2 reachable; serious operators use VPS/redirectors instead.
  • The damage is rarely the spying itself — it is credential theft, lateral movement and persistence that turn one machine into a whole-network incident.
  • Your strongest single control is egress filtering + DNS logging, because it attacks the call-home model every RAT depends on — backed by EDR on the host and a rehearsed response plan.

Related

Security intermediate

The Web Vulnerabilities Worth Knowing

The handful of classic web bugs behind most real breaches — injection, XSS, broken access control — explained with the one-line principle that prevents each.

· 2 min read
Security intermediate

Crypto You Actually Need as a Developer

Hashing vs encryption, how to store passwords without regret, what TLS gives you, and the one rule that keeps you out of trouble — don't roll your own.

· 2 min read
Security beginner

Setting Up a Safe Home Security Lab

Build an isolated playground of virtual machines where you can break things, run malware safely and practise attacks — with zero risk to the real world.

· 2 min read