Welcome back, my Mr Robot aficionados! As you know, Mr. Robot is my favorite TV show because of its realistic depiction of hacking. Nearly all of the hacks in the show are real, although the time frame may be compressed (real hacking is not like a TikTok video). In the first season, Elliot’s “girlfriend”, Shayla, […]
The post Mr Robot Hacks: Building a Deadman’s Switch in Python first appeared on Hackers Arise.
Welcome back, my Mr Robot aficionados!
As you know, Mr. Robot is my favorite TV show because of its realistic depiction of hacking. Nearly all of the hacks in the show are real, although the time frame may be compressed (real hacking is not like a TikTok video).

In the first season, Elliot’s “girlfriend”, Shayla, has been kidnapped and held as hostage by the psychopathic, drug dealer, Vera. Vera has been arrested and is sitting in jail waiting for trial. He insists that Elliot get him out of jail by some sort of elaborate hack in 24 hours! For more of the prison hack, see my tutorial here and my David Bombal YouTube video here.
Elliot goes to the jail to visit Vera and explain the difficulties of hacking him out jail in 24 hours. Vera insists. Elliot explains that he has all the evidence from Vera’s brothers cellphone (he hacked it over the LAN in his apartment probably using the shellshock vulnerability) to put Vera and his brother away forever. When Vera threatens him, he explains that if anything happens to him, a deadman’s switch will be triggered and send all the evidence to law enforcement, thereby guaranteeing his safety,
Deadman’s switch is not a new concept. It has a long and storied history in its many physical forms. A deadman’s switch is simply a safety mechanism that triggers if there is NO user action. This means that if the owner or holder of the switch is dead or otherwise incapacitated, an action is triggered. They have long been used within industrial society to stop machines if the operater is “dead” such as locomotives, amusement rides, and aircraft refueling, among many applications. It has also been used by to preserve the operator’s life. Imagine a person wearing a suicide vest. They often hold a deadman’s switch that triggers the explosive should they be killed. You have probably seen this in many TV shows and movies.
Elliot is using this strategy to preserve his life from Vera’s assassins except that here he creates a digital deadman’s switch. If he is dead, the program triggers and notifies law enforcement with all the digital evidence against Vera and his brother.
Let’s see whether we can create such a digital deadman’s switch in Python, the favorite language of cybersecurity and artificial intelligence.
Step # 1: Getting Started
A deadman’s switch is a safety mechanism that triggers an action if the user fails to perform a periodic task (like pressing a key or sending a signal) within a certain time frame. In our script, we will wait to get receive an ENTER from the user. If you user does not hit ENTER within a specified period of time, we assume they a are dead and execute the action, in this case send an SMS message.
To develop our deadman’s switch, we will need;
- code or a function to send the message when the user is dead
- some code or function to track the time and determined time is exhausted
- a main function to take user input on the desired time out and determine when that time has exhausted and trigger the action function
Let’s get started by importing the modules necessary:
import threading
The threading module in Python allows your program to run multiple operations concurrently within the same process by using threads.
- Wait for input or other blocking operations (like in your deadman’s switch).
- Perform background tasks while the main program continues (e.g., downloading a file while updating a UI).
import requests
The requests module in Python is a simple and powerful library for making HTTP requests — it lets your program talk to websites or APIs over the internet

Step # 2: Create a function named action to send an SMS Message If the User is Dead
Now that we have all the necessary modules, let’s create a function called action. In this function, we will use the requests.post command to send a SMS message through textbelt.com (we have used this service before with the sending a fake SMS message here). This function executes if the action indicating life (hitting ENTER) is not completed within specified amount of time entered by the user in the main function below. So, to simplify, the user defines the amount of time and if no action is detected within that time period, the switch is triggered.
Here we use the requests module to build a payload to be sent to the URL, https://textbelt.com/text

def action():
# Create a payload to send to the SMS provider
payload = { ‘phone’: ‘xxxxxxxxxxx’, # enter phone number of sms destination
‘message’: ‘Hi OTW. I am dead. I am sorry, you are on your own in this case. Send the evidence against Vera to the police’,
# put the message you want to be sent when you are dead
‘key’: ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’ # enter you textbelt api key here
}
response = requests.post(‘https://textbelt.com/text’, data=payload)
print(response.json())

Step 3: Wait For Input
In this function, we named wait_for_input, we use the threading module to create a timer.

def wait_for_input(timeout):
“””
Waits for user input with a timeout.
Returns True if input received, False if timeout occurs.
“””
timer = threading.Timer(timeout, deadman_action)
timer.start()
try:
input(f”Press Enter within {timeout} seconds to reset the deadman’s switch: “)
timer.cancel()
return True
except Exception:
timer.cancel()
return False
Step 4: Create a main function
Here, we create our main function. In this function, we prompt the user for the number of seconds to wait and convert it into integer, then print the timeout for the user to see and another print statement simply telling the user that the switch is activated and they must press enter to keep it alive.

def main():
timeout = int(input(“Enter the length of timeout in seconds: “)) # seconds
print(“Deadman’s switch activated. Press Enter regularly to keep it alive.”)
while True:
if not wait_for_input(timeout):
break # Deadman’s switch triggered, exit loop or take other action
Step # 5
In this section, we use a python convention that ensures that some code only runs when the file is executed directly, not when it’s imported as a module in another script.
As you already know;
- name is a special built-in variable in Python.
- When a file is run directly, name == “__main__” is True.
- When a file is imported, name is set to the module’s name, not “__main__”.

Now, we only need to give ourselves execute permissions;
kali > sudo chmod 755 deadmans_script.py
Now, if Vera’s thugs kill Elliot, the deadman’s switch will be triggered and law enforcement will be notified with all the evidence on Vera’s brother’s phone!
How It Works
- The program waits for the user to press Enter within the timeout.
- If the user presses Enter in time, the timer is canceled, and the loop continues.
- If the user fails to press Enter before the timer expires, the action() function is called.
- You can customize action() to perform any critical task (e.g., email, alerting, shutting down, encrypting files, etc.).
Summary
Mr. Robot is a fascinating TV show that demonstrates many of the realistic hacks we all use but in compressed time frames. In this tutorial, we demonstrated how you can use the hacker’s favorite scripting language, Python, to create a Deadman’s Switch that will only be triggered if the user fails to do the required action in the required time frame.
For more on Python, check out my upcoming book, Python Basics for Hackers!
The post Mr Robot Hacks: Building a Deadman’s Switch in Python first appeared on Hackers Arise.
Source: HackersArise
Source Link: https://hackers-arise.com/mr-robot-hacks-building-a-deadman-s-switch-in-python/