Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Cybersecurity: Malformed Packet Attacks & Defenses

Cybersecurity: Malformed Packet Attacks & Defenses

Malformed Packets and the Countdown Timer

In this first activity, you will experiment with the countdown timer app from the Send and Receive Packets activity. Its original form is vulnerable to malformed packet attacks you will learn how to harden it against them.  The malformed packet attack will cause the receiver to throw an exception.  At that point, it will become unresponsive until its script is restarted or reloaded with the Flash button.

This activity requires two micro:bit modules running different scripts, a Sender script and a Receiver script.

Parts

  • Two micro:bit modules.
  • Two USB A to micro-B cables.

Scripts

Running 2 micro:bit modules: You can either connect each micro:bit to a separate computer or connect both to separate USB ports on the same computer.

  • Decide which micro:bit you want to be the countdown Sender and which one you want to be the countdown Receiver.
  • Connect the two micro:bit modules to two USB ports with two USB cables.
  • Open two separate browsers and navigate each one to the micro:bit Python Editor at python.microbit.org.
  • If you are part of a class, and have been assigned a channel, make sure to adjust the script’s channel=7 argument to your assigned channel before you save and flash the scripts.
  • Enter, name, save, and flash the countdown_sender_w_malformed_packet_option script into the Sender micro:bit.
  • Enter, name, save, and flash the script countdown_receiver script into receiver micro:bit.  The Receiver Script is below the Sender Script on this page.
  • Before continuing, find the # Sends malformed packet if value is -1 comment and examine how the dictionary can be changed before transmitting.  

Sender Script: countdown_sender_w_malformed_packet_option

# countdown_sender_w_malformed_packet_option
 
from microbit import *
import radio
 
radio.on()
radio.config(channel=7,length=128)
 
sleep(1000)
 
print("Countdown App")
print("micro:bit sender")
 
while True:
    text = input("Enter countdown start: ")
    value = int(text)
    message = input("Enter message after countdown: ")
    dictionary = {  }
    dictionary['start'] = value
    dictionary['after'] = message
    # Sends malformed packet if value is -1
    if value is -1:
        dictionary['start'] = "Not a number!"
 
    packet = str(dictionary)
    print("Send: ", packet)
    radio.send(packet)
    print()

 

Receiver Script: countdown_receiver

# countdown_receiver.py
 
from microbit import *
import radio
 
radio.on()
radio.config(channel=7,length=128)
 
sleep(1000)
 
print("Countdown App")
print("micro:bit receiver\n")
 
while True:
    packet = radio.receive()
    if packet is not None:
        print("Receive: ", packet)
 
        print()
        print("Parse: ")
 
        dictionary = eval(packet)
 
        value = dictionary['start']
        message = dictionary['after']
        print("value = ", value)
        print("message = ", message, "\n")
        while value >= 0:
            print(value)
            sleep(1000)
            value = value - 1
        print(message)
        print()

 


Printer-friendly version
Sender & Receiver Tests
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress