• Arthur Besse@lemmy.ml
      link
      fedilink
      English
      arrow-up
      31
      ·
      1 day ago

      :(){ :|:& };: is a classic fork bomb for bash (and other shells which allow : as a function name).

      running it will likely cause your system to need to be rebooted.

      • Voroxpete@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        47
        ·
        1 day ago

        For those curious as to how this works…

        Part one is ‘:()’. This creates a new function named ‘:’. That’s because we start with the name, ‘:’, then the open and closed brackets (this is where you put any inputs the function expects), which is the shell syntax for creating a function.

        Part two is ’ ::& '. This creates the content of the function. The curly braces define the beginning and end of the content. Everything inside them is the function itself. The first part of the actual function is ‘:’, so it’s literally running itself. On its own this would just mean it runs forever doing nothing. But then we have a ‘|’ (pipe) character; this takes the output of the previous command and feeds it into the input of the next one. The next command is another ‘:’, so it’s calling itself again. What this means is that every time ‘:’ gets called, it calls itself twice. The last part of the function is an ‘&’ character so that the second call of the function gets run in the background. So now every time this loop runs we create two copies of our program (yes, this is a program, just a very simple one), which each create two copies, and so on.

        Finally, we have the last characters / commands. The first is a ‘;’ (semi-colon) which means “After doing that, do this.” That allows us to continue on to the last command, which is ‘:’ again. So, having defined our endlessly multiplying function, we finally run it for the first time, setting off the entire self-replicating loop. Endless copies of this tiny program will run themselves infinitely, eating up all our RAM and CPU time and crashing the PC.

        In practice, modern Linux systems have an upper limit on the number of processes that can run, so if your system resources are high enough it won’t crash, just struggle.

        • Arthur Besse@lemmy.ml
          link
          fedilink
          English
          arrow-up
          10
          ·
          1 day ago

          Why is the pipe required tho?

          it isn’t really. what is required for it to consume memory very rapidly is for each invocation of the function to call itself more than once. using the pipe is just one way to do this; it would work just as well if the pipe character were replaced with an &

    • TabbsTheBat (they/them)@pawb.social
      link
      fedilink
      English
      arrow-up
      27
      ·
      1 day ago

      If you’re referring to the cat, it’s a fork bomb. IIRC your system should realize what’s going on and terminate the process before your PC commits seppuku, unless your system is really old. Either way I wouldn’t recommend running it

      • atomicbocks@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        11
        ·
        1 day ago

        A similar attack used to be able to be done in Windows by creating a batch file that calls itself at the end.

        We used to do it where it would open the command prompt several times and then call itself, so after a couple seconds you would have dozens or hundreds of command prompt windows opening. On a system that only had 128 megs of RAM it didn’t take long for the system to become unresponsive.

          • atomicbocks@sh.itjust.works
            link
            fedilink
            English
            arrow-up
            2
            ·
            6 hours ago

            Pulling the script out of the vague recesses of my brain, what we did was more like:

            ECHO pwned!
            start /c start.bat
            start /c start.bat
            start /c start.bat
            start.bat
            

            Then make a shortcut, call it Internet Explorer with the blue E, and wait.

            I also wrote a script that would create 1000 folders in your network drive and then change the owner so you couldn’t delete them. We used that one when people left their machine unlocked.

    • u9000@lemmy.blahaj.zone
      link
      fedilink
      English
      arrow-up
      6
      ·
      1 day ago

      Curious if f(){;f|f&};f works in fish. The version in the image is bash specific, but iirc fish isn’t posix compliant so idk if posix version works

      • skrunkek@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        ·
        11 hours ago

        Fish has a more explicit syntax so we would need something like function :;:&;:&;end;: But sadly it notices and stops it

      • Parafaragaramus@infosec.pub
        link
        fedilink
        English
        arrow-up
        4
        ·
        1 day ago

        Nope. Still doesn’t work.

        fish: command substitutions not allowed in command position. Try var=(your-cmd) $var ...
        f(){;f|f&};
         ^^