Skip to main content

Malicious code definition

Malicious code is harmful computer programming scripts designed to create or exploit system vulnerabilities. This code is designed by a threat actor to cause unwanted changes, damage, or ongoing access to computer systems. Malicious code may result in back doors, security breaches, information and data theft, and other potential damages to files and computing systems.

What is malicious code?

Malicious code is the language hostile parties “speak” to manipulate computer systems into dangerous behaviors. It is created by writing changes or add-ons to the existing programming of computer programs, files, and infrastructure.

This threat is the foundational tool used to carry out the vast majority of cybersecurity attacks. Hackers probe and find weaknesses that are based on the languages used to program computers. They then create “phrases” known as scripts or lists of commands to abuse these vulnerabilities in these languages. These scripts can be re-used and automated via macroinstructions, or macros for short.

Hackers and other threat actors would move very slowly if they were restricted to manual methods of exploiting computer systems. Unfortunately, malicious code allows them to automate their attacks. Some codes can even replicate, spread, and cause damage on their own. Other types of code may need human users to download or interact with it.

The consequences of malicious code may often lead to any of the following:

To help you protect yourself, let’s explore how these threats work.

How does a malicious code work?

Any programmed component of a computer system can be manipulated by malicious code. Large-scale components such as computer networking infrastructure and smaller components like mobile or desktop apps are all common targets. Web services, such as websites and online servers, can also be targets. Malicious code can infect any device using a computer to operate, such as:

  • Traditional computer devices — desktops, laptops, mobile phones, tablets.
  • IoT devices — smart home devices, in-vehicle infotainment systems (IVI).
  • Computer network devices — modems, routers, servers.

Attackers use malicious scripts and programs to breach trusted parts of computer systems. From this point, they aim to do one or more of the following:

  1. Expose users to malicious code, to infect them and spread it further.
  2. Access private information on the breached systems.
  3. Monitor the use of a breached system.
  4. Breach deeper into a system.

Malicious code is created and used in a few distinct phases. The malicious scripted code may need human interaction or other computer actions to trigger the next event at each stage. Notably, some code can even operate entirely autonomously. Most malicious code follows this structure:

  1. Probe and investigate for vulnerabilities.
  2. Program by writing code to exploit vulnerabilities.
  3. Expose computer systems to malicious code.
  4. Execute the code through a related program or on its own.

Probing and programming are the setup phase of an attack. Before an attacker can breach a system, they must first have the tools to break in. They'll need to make the code if it doesn't already exist but may also use or modify existing malicious code to prepare their attack.

The result of malicious scripting is either an auto-executable application that can activate itself and take various forms. Some may include macros and scripts in JavaScript, ActiveX controls, Powershell misuse, pushed content, plug-ins, scripting languages, or other programming languages that are designed to enhance Web pages and email.

Exposing computer systems may occur through direct interface ports like USB or online network connections like mobile and Wi-Fi. Successful exposure only requires a way for the malicious code to travel to your machine.

Exposure in widespread attacks relies on high-contact channels such as popular websites and email spam, while more targeted efforts use social engineering methods like spear phishing. Some insider efforts can even plant malicious code into a private network like a corporate intranet by direct USB drive connection on a local end-user computer.

Execution occurs when an exposed system is compatible with the malicious code. Once a targeted device or system is exposed to malicious code, the resulting attack may include unauthorized attempts of any of the following:

  • Modify data — unpermitted encryption, weaken security, etc.
  • Delete or corrupt data — website servers, etc.
  • Obtain data — account credentials, personal information, etc.
  • Access to restricted systems — private networks, email accounts, etc.
  • Executing actions — replicating itself, spreading malicious code, remote device control, etc.

How does malicious code spread?

Malicious code may be used to breach systems on its own, enable secondary malicious activity, or to replicate and spread itself. In any case, the original code must move from one device to another.

These threats can spread over nearly any communications channel that transmits data. Often, the vectors of spread include:

  • Online networks — intranets, P2P file-sharing, public internet websites, etc.
  • Social communications — email, SMS, push content, mobile messaging apps, etc.
  • Wireless connectivity — Bluetooth, etc.
  • Direct device interfaces — USB, etc.

Visiting infected websites or clicking on a bad email link or attachment are standard gateways for malicious code to sneak its way into your system. However, this threat can enter from legitimate sources as well as explicitly malicious ones. Anything from public USB charging stations to exploited software update tools has been misused for these purposes.

The “packaging” of malicious code isn’t always obvious, but public data connections and any messaging service are the most important paths to watch. Downloads and URL links are often used by attackers to embed dangerous code.

Kaspersky Premium - block cyber threats

Types of malicious code

Many malicious code types can harm your computer by finding entry points that lead to your precious data. Among the ever-growing list, here are some common culprits.

Viruses

Viruses are self-replicating malicious code that attaches to macro-enabled programs to execute. These files travel via documents and other file downloads, allowing the virus to infiltrate your device. Once the virus executes, it can self-propagate and spread through the system and connected networks.

Worms

Worms are also self-replicating and self-spreading code like viruses but do not require any further action to do so. Once a computer worm has arrived on your device, these malicious threats can execute entirely on their own — without any assistance from a user-run program.

Trojans

Trojans are decoy files that carry malicious code payloads, requiring a user to use the file or program to execute. These threats cannot self-replicate or spread autonomously. However, their malicious payload could contain viruses, worms, or any other code.

Cross-site scripting (XSS)

Cross-site scripting interferes with the user’s web browsing by injecting malicious commands into the web applications they may use. This often changes web content, intercepts confidential information, or serves an infection to the user’s device itself.

Backdoor attacks

Application backdoor access can be coded to give a cybercriminal remote access to the compromised system. Aside from exposing sensitive data, such as private company information, a backdoor can allow an attacker to become an advanced persistent threat (APT).

Cybercriminals can then move laterally through their newly obtained access level, wipe out a computer's data, or even install spyware. These threats can reach a high level: The U.S. Government Accountability Office has even warned about the threat of malicious code against national security.

Examples of malicious code attacks

Malicious code can come in many forms and has been very active in the past. Among the instances of these attacks, here are a few of the most well-known:

Emotet trojan

First appearing in 2014, the Emotet trojan evolved from its malware roots to become email spam laden with malicious code. The attackers use phishing tactics like urgent email subject lines (ex: "Payment Needed") to fool users into downloads.

Once on a device, Emotet has been known to run scripts that deliver viruses, install command and control (C&C) malware for botnet recruitment, and more. This threat took a short break in 2018 before returning to become an SMS malware threat in the process.

Stuxnet worm

Since 2010, the Stuxnet computer worm and its successors have been targeting national infrastructure. Its first documented attack involved Iranian nuclear facilities via USB flash drive, destroying critical equipment. Stuxnet has since ceased, but its source code has been used to create similar highly targeted attacks through 2018.

How to protect against malicious code attacks

For most malicious threats, antivirus software with automatic updates, malware removal capabilities, web-browsing security is the best defense. However, preventing malicious code may not be possible with antivirus software on its own.

Antivirus typically prevents and removes viruses and other forms of malware — or malicious software — is a subcategory of malicious code. The broader category of malicious code includes website scripts that can exploit vulnerabilities to upload malware. By definition, not all antivirus protection can treat certain infections or actions caused by malicious code.

While antivirus is still essential for proactive infection removal and defense, here are some valuable ways to protect yourself:

  • Install anti-scripting software to prevent JavaScript and related code from running unauthorized.
  • Exercise caution against links and attachments. Any message containing URL links or attachments — whether by email or text message — can be a vector for malicious code.
  • Activate your browser’s popup blocker to prevent scripts from serving malicious content in unwanted browser windows.
  • Avoid using admin-level accounts for daily use. High-level permissions are usually required to run scripts and programs automatically.
  • Utilize data backups to protect irreplaceable files and documents.
  • Be wary of using any public data connection. USB connections are generally overlooked but can easily harbor malicious code. Public Wi-Fi is also a common threat that attackers can use to deliver malicious code.
  • Use a properly configured firewall to block unauthorized connections. If malicious code infiltrates your machine and connects outward to request malware payloads, a firewall can help stop this. Be sure that your firewall is configured to block by default and whitelist any expected and trusted connections.

Related Links:

What is Malicious code?

Malicious code is computer code that causes security breaches to damage a computing system. Learn how to protect yourself from Malicious code today.
Kaspersky Logo