Logical Bombs

According to Wikipedia:

A logic bomb is a piece of code intentionally inserted into a software system that will set off a malicious function when specified conditions are met.

These things are a bit complicateder compared to Fork Bombs. A logic bomb has 2 main components:

  1. An event-checker/event-listener that keeps checking if the requirements are met for the bomb to go off.

  2. The bomb's payload. This stuff is the "malicious function" that'll be executed when the logic bomb goes off.

So, if you want a simple example of a logic bomb, here's one:

import time

START = time.time()

def payload_function():
    # Stuff to execute when the conditions are met
    # For this example, we can just print "BOOOM" to the console:
    print("BOOOM")

while True:
    if time.time() - START == 5:
        payload_function()
        break

Let's go through how this works:

def payload_function():
    print("BOOOM")

First comes the payload function, i.e. the stuff the logic bomb should execute when it goes off. For this example, we'll just make it print the string: BOOOM on the console; pretty simple, right?

while True:
    if time.time() - START == 5: # Condition check
        ...

Since we wanna keep this as simple as possible, we're using an infinite loop that will keep checking for a condition every iteration. In this case, we're checking if the time passed since the beginning of the program's execution is 5 seconds. If 5 seconds have passed, the payload will be executed and the program will break out of the loop.

The condition defined can be anything you want, maybe it's the user pressing a certain key, maybe it's so that this bomb goes off when a user logs into the system at a certain time of the day, or if they access a particular website. Basically, the sky's the limit 😄

Now comes the part when we execute this program. It'd be pretty stupid to run it in a console and expect the user to not close said console and keep it running in the background. The following command can be used to work around that:

$ python logic_bomb.py &

If you don't already know, (on Linux) the & at the end means that the program will run in the background. In its own process thread. If you want to achieve the same on a windows system, you can use the following powershell command:

Start-Process -NoNewWindow py3 logic_bomb.py

The example we considered was a simple one. If you wish to see a more overengineered and verbose implementation of a logical bomb, you can check the puffgo package:

PS: Be sure to check the puffgo wiki, I promise it'll be helpful :)

Last updated