00->1
Learning pathStep 32 of 62Web and technical attacks ← All writeups

Drive-By Attack, Explained

If you are reading this, you have probably heard that you can get infected "just by visiting a website," and you want to know whether that is true and how it works.

By the end you will be able to define drive-by download and drive-by compromise, describe the steps from page visit to infection, explain how it relates to malicious ads and watering hole attacks, and apply the defences that work.


1. What it is

Wikipedia gives two senses of drive-by download (Wikipedia: Drive-by download):

  1. A download "authorized by a user without understanding what is being downloaded, such as in the case of a Trojan horse."
  2. "A download which occurs without a user's knowledge."

The second is what people usually mean: you visit a web page and something is installed or run without you choosing to download anything.

MITRE ATT&CK calls the technique Drive-by Compromise (T1189): adversaries gain access when a user visits a website, exploiting software vulnerabilities on the endpoint (T1189).

The important point: the attack depends on a weakness in your software, usually the browser or its plugins, not on you doing something unusual. That makes it different from phishing, where the victim is tricked into acting.


2. How it works

According to MITRE, a typical drive-by compromise goes like this:

  1. A user visits a website that is compromised or malicious.
  2. Scripts run automatically and "typically search versions of the browser and plugins for a potentially vulnerable version."
  3. If a vulnerable version is found, exploit code runs and delivers malware to the system.
  4. The attacker gets code execution and then proceeds (see privilege escalation).

Wikipedia adds that the skill needed has been lowered by "exploit packs that contain the vulnerabilities needed to carry out unauthorized drive-by download attacks." Attackers do not need to write exploits themselves.

How victims reach the malicious content

MITRE lists several delivery methods:

Method What happens
Compromised legitimate websites Code is injected into a genuine site
Malicious advertisements Ads served through legitimate ad providers carry malicious code. This is often called malvertising
Modified scripts on public cloud storage A script that many sites load is altered
Cross-site scripting Injected script runs in visitors' browsers
Browser push notifications Abuse of notification features to run JavaScript

Wikipedia also notes content may be hosted on "a legitimate website unknowingly distributing the attacker's content through a third party service (e.g., an advertisement)."

Drive-by and watering hole

A watering hole attack is a targeted drive-by compromise: instead of infecting any visitor of any site, the attacker compromises a site that a specific group visits. MITRE says so directly: targeted campaigns focus on websites visited by specific communities.

Drive-by (general) Watering hole
Targeting Any visitor A chosen group
Site Any compromised site, or malicious ad A site the group already trusts and visits
Method of infection Same techniques Same techniques

3. What happens after

If the exploit works, the attacker can run code with the privileges of the user and the browser. They might install malware that steals credentials, provides remote access, or downloads further tools. Often a second stage then tries to gain higher privileges.

Whether the exploit works depends mostly on:

  • How up to date the software is. Known vulnerabilities in outdated browsers and plugins are the usual targets.
  • Whether protections are in place: sandboxing, exploit mitigations, and ad or script blocking.
  • What rights the user has. Running as an administrator makes it worse.

4. Defence

MITRE's recommended mitigations for T1189 are the backbone, and the other measures reinforce them.

Core defences

Defence Why it works
Keep browsers, plugins and the operating system updated Removes the known vulnerabilities the exploit looks for
Remove plugins and extensions you do not need Fewer places to find a flaw
Browser sandboxing and application isolation MITRE: browser sandboxes can mitigate some of the impact of exploitation
Exploit protection Tools such as Windows Defender Exploit Guard detect exploitation behaviours
Content blocking MITRE: ad blockers can help prevent malicious code served through ads from executing
Script blocking Wikipedia mentions tools that disable scripts on a page and let the user re-enable individual ones selectively
Standard user accounts, not administrator Limits what the code can do
User awareness MITRE lists training as a mitigation for related social engineering

Organizational layers

Control Purpose
Patch management for endpoints Fast updates for browsers and plugins
Protective DNS and web filtering Block known malicious sites. Recommended in the CISA/NSA/FBI/MS-ISAC guidance
Endpoint detection and response Spots exploitation and what follows
Network monitoring MITRE suggests watching for requests to uncommon domains, unexpected child processes spawned by browsers, unusual file writes, and deviations from baseline outbound connections
Remote browser isolation Runs web content away from the endpoint
Application allowlisting Only approved programs run
Segmentation and least privilege Contain any infected machine

Habits

  • Install updates promptly, including for the browser.
  • Do not allow a site to install software or extensions you did not look for.
  • Be careful of "update your browser/plugin" pop-ups. Update through the browser or system settings instead.
  • Close the page if a site shows unexpected prompts or downloads.
  • Keep security software active.

If you think you were affected

  1. Disconnect the device from the network and tell your IT or security team.
  2. Run a full security scan and get the device checked or rebuilt if needed.
  3. Change passwords from a clean device, especially if accounts were open in the browser.
  4. Review account activity for unfamiliar sign-ins.

5. Common mistakes

Myth The facts
"I'm safe if I don't download anything" A drive-by can run without any download from you
"Only dodgy sites are dangerous" Legitimate sites can be compromised or serve malicious ads
"I would see a warning" Often there is none
"A padlock means the site is safe" It only means the connection is encrypted
"Antivirus is enough" It helps, but patching and sandboxing matter more
"Drive-by and phishing are the same" Drive-by exploits software weaknesses. Phishing tricks the user
"Ad blockers are only for convenience" They reduce exposure to malicious ads

Closing

A drive-by attack turns a web visit into an infection by exploiting weaknesses in the browser or its plugins. It succeeds mainly where software is out of date. A watering hole is the targeted version.

Keep these points:

  • No click or download by you is needed if the software is vulnerable.
  • Delivery comes from compromised sites, malicious ads and altered scripts.
  • Update first, then sandbox, block content and limit privileges.
  • Monitor for odd behaviour from browsers.
  • Watering holes are drive-bys aimed at a specific group.