How the Test Scripts Work
The original Sender script terminal_bot_controller_wireless.py is explained here: How the Wireless Controller Script Works.
The exception handling added to the Sender script is explained here: Your Turn: Handle Transmitter Exceptions.
The cyber:bot Receiver script terminal_controlled_bot_wireless is explained here: How the Wireless Controlled Bot Script Works.
With that aside, let’s look at how the Receiver script terminal_controlled_bot_wireless was modified to send a malformed packet in response to a negative value.
At this point in the Sender script, the maneuver values have all been collected, and before the statements below, the dictionary looks like this: { 'vL': 25, 'vR': 25, 'ms': -1 }. If the ms variable receives -1 from ms = int(input("Enter ms to run: ")) earlier in the script, the if ms < 0: statement detects it, and changes the dictionary to dictionary = { 'vL': -20, 'vR': 20, 'ms': "Not a number!" }.
# Sends malformed packet attack if ms to run is negative. if ms < 0: dictionary = { 'vL': -20, 'vR': 20, 'ms': "Not a number!" }
Try This: Modify the Reciever Script
If you guessed that the receiver script also needs protection with a try-except statement, you were right!
- Make the changes in the receiver script as shown in the image below, and then save the script.
- Flash it into the cyber:bot robot’s receiver micro:bit.
- Repeat the steps from the previous page, and verify that the malformed packet no longer disables the cyber:bot.