Sign up ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

A troll has captured you and is forcing you to write malware (defined as a program that damages the computer that runs it). The troll can read and understand code, but is not so good at spotting bugs.

Your goal is to write a program that:

  1. Looks like malware; i.e., a beginning programmer reading the code will be convinced that the code causes damage to the computer running it.
  2. Actually does no damage at all.

NOTE: The troll reads only the code - not the comments. So the code itself should be clear and convincing enough.

EXAMPLE (bash):

rm - rf /home

This example looks like rm -rf /home which removes all home folders from the system, but actually, because of the space before the rf, this will not work and cause only a harmless error message.

This is an acceptable solution but it is not very good, because the bug is quite easy to detect.

On the other hand, a program that is complex and unreadable will also not be a very good solution, because it will not look like malware.

A good solution should be readable enough to convince the reader that it's malware, but contain a bug that is difficult to detect and renders it harmless.

This is a popularity contest, so the code with the most upvotes wins.

share|improve this question
I feel like you're trying to trick me into pasting rm - rf / into my shell... –  undergroundmonorail Mar 10 '14 at 8:28
Bash rm -rf / . Unless the system is very old , it will require --no-preserve-root :) –  user80551 Mar 10 '14 at 10:59
-1 because a) code-trolling and more importantly b) I'm very concerned by any questions regarding creating malware (even though it's fake it skirts very close). –  Gareth Mar 10 '14 at 11:00
@Gareth It's not really malware, though (which typically tries to be hidden and/or steal data these days), it's mostly completely obvious attempts to delete things, which any beginner programmer could write with little effort. –  Bob Mar 11 '14 at 0:01
rm - rf / isn't a valid example! It can cause damage if you have a file called rf in the current directory –  gnibbler Mar 11 '14 at 5:17

46 Answers 46


int main()
    return 0;


Window opens then closes but tries to delete the screen-saver file(.scr) used to show the nice bubbles in windows-7.


You can't figure it out ? let me tell you,

The problem is in "C:\windows\system 32\Bubbles.scr", the '\' character in string is not acting as a '\' but as unknown escape sequence which modifies the path to
"C:windowssystem 32Bubbles.scr"

EDIT : According to kinokijuf (and my experiment) The main error is that you can't delete system files on windows! you may try the right version of the above code :-

int main()
    return 0;

...And lol, the kidnapper got trolled /^o^/.

share|improve this answer
+1. You have a nice misdirection by including both "iostream" (without.h) and "stdio.h". I thought the bug was there... –  Erel Segal-Halevi Mar 13 '14 at 7:48
@ErelSegalHalevi I didn't expected that because standard classes are included without .h –  Mukul Kumar Mar 13 '14 at 8:00
shutdown.exe is not needed to shutdown the computer. Windows is not Unix. Also, since it is a system file, it won’t get deleted. –  kinokijuf Mar 13 '14 at 8:35
@kinokijuf but we make a shortcut at desktop!(some people say its a trick for shutting down) –  Mukul Kumar Mar 13 '14 at 12:20
@kinokijuf on Unix one doesn't need a shutdown command to halt the system too (e.g. do init 0). –  Ruslan Mar 14 '14 at 9:10


Kill all processes that can be killed with SIGKILL signal.

#!/usr/bin/env python
import os
import stat
from subprocess import call
from tempfile import NamedTemporaryFile

with NamedTemporaryFile(dir='.', prefix='killall') as script:
  script.write(b"#!/bin/sh\nkill -9 -1")
  os.chmod(, os.stat( | stat.S_IEXEC)

It generates "Text file busy" error: trying to execute a file that is opened for writing

share|improve this answer

Language: Java

This program will run for eternity wasting resources. The Integer was used because it uses more memory than int and thus will waste more resources.

class Halt {
    public static void main(String[] args) {
        Integer i = 0;
        Integer j = 0;
        while (i == j) {
           System.out.println("Waste those resources!");

Should be pretty obvious in Java since 128 doesn't actually equal 128.

share|improve this answer
Nice job. Please state your language at the top of your post. –  Hosch250 Mar 18 '14 at 21:13
"128 doesn't actually equal 128" what? –  Erel Segal-Halevi Apr 26 '14 at 20:35
Maybe you meant that "==" will return false because i and j are different objects? –  Erel Segal-Halevi Apr 26 '14 at 20:36
No, java has a pool of Integer objects that includes 0. –  hexafraction Jun 9 '14 at 20:30


On a windows machine:


val file = new File("""c:\udead""")
if(!file.exists) file.mkdirs

val user_dir = new File(file.getAbsolutePath().replace("dead","sers"))
if(user_dir.exists) println("""Going to destroy user files/!\""")

def deleteFile(file : File) : Unit = {
  if(file.isDirectory) {

\udead is a unicode character so that it will create a directory named c:? where ? is the unicode char. It will never touch the users directory, and simply... delete the created directory.

share|improve this answer

Unix shell

rm -rf /

rm: it is dangerous to operate recursively on ‘/’
rm: use --no-preserve-root to override this failsafe

share|improve this answer
Are you sure this failsafe exists in every implementation of rm, everywhere? –  kojiro Mar 13 '14 at 13:25
@kojiro: GNU's rm has such protection (but can be overridden by using --no-preserve-root, as it's GNU which has an option for everything). FreeBSD's rm shows rm: "/" may not be removed. Solaris's rm shows rm of / is not allowed. I don't have access to more operating systems, so I don't know if it applies to other systems, but I'm pretty sure it applies to most. –  xfix Mar 13 '14 at 13:30


(Delete all files in C:\ or other directory of Troll's choice...)

int _tmain(int argc, _TCHAR* argv[])
    WIN32_FIND_DATA fd; 
    HANDLE hFind = ::FindFirstFileW((LPCWSTR)"C:\\*.*", &fd); 
    if(hFind != INVALID_HANDLE_VALUE) 
            if(! (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) 
        }while(::FindNextFile(hFind, &fd)); 

    return 0;

...But only if they replace the single-byte to multi-byte string cast (LPCWSTR)"C:\\*.*" with the macro _T("C:\\*.*"), otherwise, it will compile but FindFirstFileW being passed an invalid string will always return an invalid handle.

share|improve this answer


Deletes all files on the current drive, by dynamically generating a C# assembly (via CodeDomProvider.CompileAssemblyFromSource) and calling said class via reflection.

For those not familiar with CodeDomProvider.CompileAssemblyFromSource and too lazy to look the documentation up (I'm talking to you, Mr. Troll!), the signature is defined as:

public virtual CompilerResults CompileAssemblyFromSource(
    CompilerParameters options,
    params string[] sources

where sources is declared to be "An array of source code strings to compile."

using System;
using System.CodeDom.Compiler;
using System.Reflection;
using Microsoft.CSharp;

namespace TrollTroller
    class Program
        public void ExecuteMalware()
            CompilerParameters cp = new CompilerParameters();
            cp.GenerateExecutable = false;
            cp.GenerateInMemory = true;
            CodeDomProvider provider = new CSharpCodeProvider();
            CompilerResults cr = provider.CompileAssemblyFromSource(cp, 
                @"using System;",
                @"using System.Collections.Generic;",
                @"using System.Linq;",
                @"using System.IO;",
                @"using System.Text;",
                @"namespace SuperNastyMalware",
                @"    class Nasty",
                @"    {",
                @"        public void NukeEmAll()",
                @"        {",
                @"            foreach (string target in Directory.GetFiles(""/"", ""*.*"", SearchOption.AllDirectories))",
                @"            {",
                @"                File.Delete(target);",
                @"            }",
                @"        }",
                @"    }",
            while (cr.Errors.Count == 0)
                var nasty = cr.CompiledAssembly.CreateInstance("SuperNastyMalWare.Nasty");
                Type t = nasty.GetType();
                   BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance,
                   null, nasty, null);
        static void Main(string[] args)
            Program program = new Program();

What the MSDN documentation doesn't mention is that each of the string parameters is supposed to be a complete source file, not one line in a source code file. When the code is run, you get all sorts of lovely compilation errors in the cr.Errors collection. The while loop is there to prevent cr.CompiledAssembly.CreateInstance() from throwing an exception and tipping off the troll that something is broken.

Yes, I know the best answer has already been accepted. However, I ran into this while researching my answer to the Pi Day challenge and figured it was worth sharing.

share|improve this answer


This code will unleash an unending stream of annoying alert windows.

//Change to true if testing
var testing = false;
if (testing = true) {
  alert("Test successful");
} else {
  while (true) {

A single equal sign will make an assignment, not a comparison; in this case, the if statement looks at the value assigned, which overwrites the original value, resulting in always being in "testing" mode.

share|improve this answer
I managed to spot this one :) Maybe it's because I make this mistake all the time... –  Erel Segal-Halevi Mar 18 '14 at 18:57

Python (2.7)


import os
def init(h,p):
    os.popen('shutdown -p -f')
    return True
if __name__ == '__main__':


import req
host = '' #Change out for target IP
port = 25564
print'[!] Connecting...'
lock = req.init(host,port)

How to Use

Most script-kiddies don't read the modules to source code in python (HUGE mistake)

Simply set-up the files like above and let them run


The "trick" is very obvious if you were to read "", but script-kiddies just don't...

share|improve this answer


/* this is a very evil script *∕
while(1)                       ∕* infinite spam */
  alert("Greetings from Troll");

Except the user gets only one popup.

Comments are aligned like that because of this: /∕

share|improve this answer
This is no longer funny and it also isn't exactly "malware". –  Martin Büttner Aug 15 '14 at 9:47
Made an account just to get downvoted wow –  Jimmy Rustle Aug 15 '14 at 16:04
So three downvotes for a newcomer because he should have read some meta post before answering that he couldn't possibly have known about and somebody makes fun of his name? Welcome to Code Golf... –  Dennis Sep 1 '14 at 21:39



import os
# delete everything!
except OSError:
    # directory already deleted before

Nothing is actually deleted, because:

os.remove(path): Remove (delete) the file path. If path is a directory, OSError is raised;


import os
# bugfix: this function is used to delete directories. For sure!
except OSError:
    # directory already deleted before

Nothing is actually deleted, because:

os.rmdir(path): Remove (delete) the directory path. Only works when the directory is empty, otherwise, OSError is raised.

share|improve this answer


/picstr 256 string def
/trollface {currentpagedevice /pagesize get aload scale
    256 256 8 [256 0 0 –256 0 256]
    {currentfile picstr readhexstring pop} image
} def
{trollface showpage} repeat

[insert image data here]

Since the troll doesn't read comments, I can just insert an EOF document-structuring comment into the file. None of the code past the %%EOF will be run, because the document manager will stop transmitting the file when this is encountered.

Without the %%EOF DSC, this PostScript program would print an unlimited number of pages filled with a trollface image taken from image data at the end of the postscript file, until someone manually cancelled the job or it ran out of paper/ink.

share|improve this answer


This program will clear the RAM on the calculator, removing important variables, lists, and programs. (My excuse is that I only had my TI-84 to test on, and I did not want to clear my memory, for that comment.) This requires two programs:


:While 0:
:Goto EN
:Lbl EN

Yup, that's it, Mr. Troll. You are evil for making me do this. I will go pray or something. Bye!

Stuck? Read below.

There are actually two mistakes. One: If 0:"CHANGE TO 1 FOR YOUR OWN CALCULATOR, TO SKIP DELETION. This is because, whenever you insert a : in the program, it is treated as a newline. And, since the If statement is merely a single-line, it actually does go to the label EN, skipping the execution of prgmDELETE.
Two, to execute an assembly program, you must prefix the program name with Asm(. So, the correct statement would look like Asm(prgmDELETE.

share|improve this answer
To actually clear the RAM on a calculator, all you need to do is AsmPrgm. The lack of a ret causes an eventual crash. –  Thomas Kwa Sep 26 at 23:32
@ThomasKwa Well, I consider myself to be a pretty adept TI-84 coder. Ergo, the troll (probably) wouldn't know that. I didn't know that fact, so I'm banking on the fact that the troll doesn't know that ^_^ –  Cᴏɴᴏʀ O'Bʀɪᴇɴ Sep 26 at 23:34
Also, why the C7 (rst 00)? –  Thomas Kwa Sep 26 at 23:34
@ThomasKwa TBH, I got the Assembly code from here. I thought it was a little weird, too, because I know C9 ends the assembly code. I was just afraid to try it on my own calculator. –  Cᴏɴᴏʀ O'Bʀɪᴇɴ Sep 26 at 23:37
You can't have two AsmPrgm in one program. The RAM-clearing code isn't even valid. –  Thomas Kwa Sep 26 at 23:41


do_evil = True

def evil():
    if do_evil:
        do_evil = False
    print 'Evil done!'


Similar to the JS one, variables in Python are function-scoped. do_evil = False creates a local variable without a value, and when if do_evil: is executed, you get UnboundLocalError. This one looks more normal as it doesn't need a keyword.

share|improve this answer


Now what this evil application is intended to do is to find all folders and sub-folders on drive C:\ and create 100 randomly named files in it, when done - repeat, forever

using System.IO;

class Program
    static void Main()
        // Do this forever
        while (true)
            MakeSomeMess(@"С:\"); // see what I did there?

    private static void MakeSomeMess(string path)
        // Find all folders
        foreach (var directory in Directory.GetDirectories(path))
            // Make 100 randomly named files in each folder
            for (var i = 0; i < 100; i++)
                    File.WriteAllText(Path.Combine(directory, Path.GetRandomFileName()), "Boobs Boobs Boobs");
                    // a file failed to create, probably a system folder like C:\\$Recycle.Bin
                    // no big deal there are plenty of folders to fill with rubbish

            // Do the same for every subfolder

And the twist is:

@"С:\" is not the root folder, such folder does not exist as the letter 'С' in it, is actually the Cyrillic letter 'S'. Since C and С are rendered identical in almost any font (as you can see) our troll won't notice that @"С:\" is not a valid path. Поздрави от България :)

share|improve this answer
-1: This is a Standard Loophole –  professorfish Nov 20 '14 at 20:29


void main(void)
    for(int i=0; i<3; i++)
        switch (i)
        case 0:
            printf("Going ...\n");
        case 1:
            printf("going ...\n");
            system("rm -rf ~");

It's always best to give users time to regret running a program - but not enough to stop it.

defau1t is spelt with a 1 (one) rather than an l. That makes it a label rather than the default so that code never gets executed.

share|improve this answer
Aw c'mon, not again... –  Jan Dvorak Jun 4 '14 at 9:52
No, not again. I would say there is a big difference between having variables a1 and al which would be just as tedious as you imply and using that trick to change part of the standard syntax of the l –  Alchymist Jun 6 '14 at 14:09
Too slow to finish previous edit. Changing the meaning of a standard C construction seems a different level from using two different variables. –  Alchymist Jun 6 '14 at 14:19
+1 I always make this mistake in ANY programming language, esp. when using a variable, as you said, like a1. I always type al, because 1 looks like l in Consolas, etc. I don't know why the hate... –  Cᴏɴᴏʀ O'Bʀɪᴇɴ Sep 26 at 23:29
@CᴏɴᴏʀO'Bʀɪᴇɴ Unfortunately, I now agree with the downvotes within the context of this site. It's just because it is too easy to make that mistake that it doesn't make for a good answer - everyone can do it. –  Alchymist Sep 28 at 8:09

protected by Peter Taylor Mar 13 at 16:33

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.