Skip to content

Rezaid

Home » Blog » How can an attacker execute malware through a script​

How can an attacker execute malware through a script​

    How can an attacker execute malware through a script​

    Malware can be secretly executed using malicious scripts such as PowerShell, JavaScript, or macros by the attackers. These are fileless attacks, which are difficult to identify, and are propagated via phishing emails, drive-by downloads, and the used of administration tools. The first step to countering them is to learn about their operation.

    Unveiling the Sneaky Truth: What Is Script-Based Malware and How Does It Slip In?

    By script-based malware, we are referring to malicious code in a scripting language such as PowerShell, JavaScript, Bash, or VBScript. What is frightening about such scripts is that they can (and frequently do) execute direct in memory, i.e., without any file, and, therefore, the traditional antivirus tools may totally overlook them. 

    In contrast to an executable file that has a dark gray shoebox, scripts can be masqueraded as benign tools of administration or even automation, and can even be allowed by default on your computer. That is their dearest friend to a hacker.

    1. Step-by-Step: How Attackers Trick You Into Running Malicious Scripts

    a) Phishing and Social Engineering- The Classic Trap.

    Attackers have a fondness for slipping scripts in emails or attachments that appear to be urgent or non-official. Macros are possible in Think Important invoices! After being fooled into opening that file (particularly a Word or Excel spreadsheet containing macros), it will run embedded VBScript or PowerShell that silently installs malware in the background.

    b) Java-Script drive-by on Compromised Web Pages.

    Have you ever landed on a site that auto-redirects, downloads a file or hangs your browser? Hackers are able to inject JavaScript onto genuine websites or advertisements. Drive-by download. Once your browser automatically executes that code, it triggers malware without your knowledge- a drive-by download. This is why it’s critical to protect your Linux and other systems with up-to-date browser security configurations and user access controls.

    c) Remote or Local File Inclusion Attacks Web App Exploits.

    One more tricky way: a hacker finds a weak point in a server (which can be a PHP-based site) and can enter and execute their own scripts. This may be Remote File Inclusion (RFI) or Local File Inclusion (LFI)- fundamentally commandeering something the server executes and converting it to a backdoor.

    d) Misusing Admin Tools such as PowerShell or Node.js To Execute Scripts.

    PowerShell Attacks: PowerShell is trusted and an in-built part of Windows; this will be used by attackers to execute fileless malware undetected. They can shut down security mechanisms, leave ransomware, or leave backdoors with just a single script. 

    Node.js Abuse: Attackers in more recent campaigns deceive the user into executing a command that starts Node.js, which subsequently executes JavaScript that directly starts sophisticated attacks such as network scanning, stealing credentials and manipulating registries.

    2. Why Script-Based Attacks Slip Through Defenses Like a Whisper

    The scripts are usually under the radar due to a number of reasons:

    Verified Tools: They use tools such as PowerShell or verified site scripts; therefore, signature detection defenses tend to fail. 

    Fileless & Obfuscated: Scripts are executed in memory, do not use any disk space and can be obfuscated to elude detection algorithms. 

    Broad Accessibility and Scalability: PowerShell, JavaScript, Bash–they can be found everywhere, and thus prove useful in cross-platform attacks.

    3. Real-World Examples That Will Make Your Skin Crawl

    Macro-Ransomware (Cl0p/TA505)

    In a well-known incident, assailants phished with rogue Office macros. These downloaded droppers that installed self-permanent backdoors- and ultimately ransomware in networks. 

     

    JavaScript Drive-by Intruder In Trusted Domains

    A vulnerability was that a Google OAuth logout URL was a URL that contained obfuscated JavaScript code. Since it seemed to be a product of Google, it was accepted by browser security and antivirus programs. It would then quietly connect socket connections with a rogue server so that it could execute code in real time. 



    Node.js: The Script Execution Engine.

    The other strategy that is gaining momentum is attackers exploiting users into executing a PowerShell script that installs Node.js. Then the attacker executes inline JavaScript that scans networks, gathers information and conceals itself in system settings.

    4. Things to Take Action: How You Can Shield Yourself from Script-Based Attacks

    a) Turn off Macros and Scripts on default- Only turn on when you are sure of the source.

    Macros should never be turned on in the office unless you are certain that it is safe. Same with scripts- only run verified sources. 

    b) Trusted Scripts, Block, and Application Control.

    Security mechanisms such as application control may permit only known safe scripts and bar malicious scripts. 

    c) Implement Endpoint Detection and Response (EDR/XDR) to Identify Abnormal Script Activity.

    EDR tools are capable of identifying strange actions, such as PowerShell being run in memory or Node. JS is playing up something invisible to the traditional antivirus. 

    d) Quarantine Suspicious Scripted Files by using Email/Web Filters and Sandboxing.

    Ensure that you configure your systems to sandbox any files with .ps1, .js or macro-like extensions prior to their delivery to the user. 

    e) Make it Trace (such as PowerShell Script Block Logging)

    What scripts execute can be logged by PowerShell as well as other tools, allowing you to identify obfuscated or malicious behavior afterwards. 

    f) Educate Yourself and Your Team on how to detect phishing and ask urgent-feeling emails.

    The weak point is human error. Provide knowledge about red flags: urgent tone, suspicious attachments or content activation.

    A Quick Summary Table: Scripts—Doors to Disaster Without a Second Thought

    Attack Vector How It Works
    Phishing/Macros Victim enables macro → executes VBScript/PowerShell → malware installed
    Drive-by JavaScript Website/ad runs JavaScript → auto-downloads malware silently
    File Inclusion (LFI/RFI) Web app includes attacker’s script → executes on server with backdoor
    PowerShell Abuse Script runs trusted cmd → downloads/drops malware invisibly in memory
    Node.js Inline Execution PowerShell installs Node → runs JS for scanning, exfiltration, and install

    Final Thoughts

    Introducing malware with the help of scripts is risky exactly because the attacks are: Unobtrusive and file-free, no antivirus notice, Nowby means of looked-upon channels – phishing, authoritative domains, code on servers, Armed with very flexible, powerful scripting languages.

    You will have to implement a combination of technology (EDR, app control, logging, filters) with behavioral defenses (user education, cautious habits) to be able to outsmart attackers. It can make a big difference, even in such simple things like switching off macros unless you are certain about it.

    Be careful and be ahead of script-based threats.

    FAQs

    Which of the following attacks makes a victim have their browser execute malicious scripts?

    Cross-site Scripting (XSS) is an attack of client-side code injection. 

    What is a malicious code script?

    A Malicious Script is a kind of code that can be executed to do damaging activity to a computer without the user realizing it (e.g., spy on communications or destroy valuable files).

    What is a web scripting virus?

    A web scripting virus infects the security of the web browsers and allows a hacker to inject web pages with malicious code or client-side scripting.