Trolling the troll

  • 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.


    I feel like you're trying to trick me into pasting `rm - rf /` into my shell...

    @undergroundmonorail you can use a shell simulator like this: http://www.compileonline.com/execute_bash_online.php

    I was making a joke, but that's a cool site actually.

    Looks like someone is looking advices for malware

    Bash `rm -rf /` . Unless the system is *very old* , it will require `--no-preserve-root` :)

    -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).

    @user80551 right, fixed the example

    @ErelSegalHalevi I actually meant that as an answer.

    @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.

    `rm - rf /` isn't a valid example! It can cause damage if you have a file called `rf` in the current directory

    c:\>fórmat c: /q /s

    @Gareth It "skirts fairly close" to malware by appearing to delete a file? You've got to be kidding me.

    Someone who uses other people's attack programs with little to no understanding is a _script kiddie_, not a troll.

    Yeah, and now I am gonna fix these answers(including the example given in question) and use them as malware!

    @Gareth Spoil sport :P it's only theoretical...

    I wonder how many systems were ruined by guys testing their solution and failing

    This question is very dangerous. Because when trying to create code for answer, I made some bugs in it and it worked 'properly' because of them. And this 'proper work' cost me some data :p

    I would offer VimL `blast` but I'm not sure that actually satisfies the criteria... (presumably the troll is Vim-savvy?)

    @gnibbler Or a file called `-`.

    Dear god, I pity the poor programmer who forgets the one character that makes his code harmless.

  • Bash



    I've gone the other way. Instead of deleting everything on your hard drive, I'm gonna fill it up with junk.





    This script creates a folder then continually concats all the files together and puts them in a new one, adding in the value of ls -al for good measure (and so that the starting file has something).



    #!/bin/bash/

    makeSpam()
    {
    string=`cat *`
    string=$string`ls -al`
    echo $string > "file"$i".spam"
    }

    mkdir "SpamForYou"
    cd "SpamForYou"

    i=1
    while [ 1 ]
    do
    makeSpam $i
    i=$(($i + 1))
    done


    except...




    /bin/bash/ (instead of /bin/bash) is very unlikely to be a valid interpreter. This is just a common typo of mine. And, since "the shebang is technically a comment, the troll will ignore it"



    Cute. Nice misdirection.

    +1. The first line in a script is a blind spot for many programmers (including myself).

    and the shebang is technically a comment, so the troll will ignore it

    +1 for abusing the noncommenting comment :) thats really not obvious

    Running it as `bash whatever.sh` will ruin your trick...

    @Darkhogg, what luck! I saved it as `evil.command` so that the troll can just double click it to open (on Mac at least)

    Why does the makeSpam works? I'm confused about the asterisk.

    The `cat *` means "print out the *contents* of every file in this directory". The second line adds the *name and other information* of every file in this directory. The last line prints all of this information into a new file.

    You will get various errors since you did not quote the variables, which will break your script as well.

    @queueoverflow, Which bit(s) do you think will cause errors? I actually ran this script and it had the desired, undesirable outcome.

    Oh dear, as if this answer is one vote off being my "best answer" on any SE.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM