Cyber security · GCSE · OCR J277 1.4.1, Edexcel 1CP2 4.2.1 · about 20 min
Brute force, denial of service, data interception and SQL injection, and detecting a flood.
[1 mark]What is a brute force attack?
[1 mark]What does a denial of service attack do?
[1 mark]How is intercepted data made useless to an attacker?
[1 mark]What is a botnet?
[1 mark]How is SQL injection prevented?
[1 mark]How many possible codes does a 4-digit PIN have?
Count how many requests come from each address in requests. Print <address>: <n> for each, sorted from the most requests to the fewest. Any address with 5 or more requests is an attack: print BLOCK on its line, and at the end print blocked: <addresses>, the blocked addresses joined by , .
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
requests = [
"10.0.0.5", "10.0.0.9", "10.0.0.5", "10.0.0.5", "10.0.0.2",
"10.0.0.5", "10.0.0.5", "10.0.0.9", "10.0.0.5", "10.0.0.5",
]The hint students can ask for: Count the requests per address into a dictionary, then sort those counts from the largest down. Mark and collect any address that reaches the threshold, and list the collected ones at the end.
from bugbot import *
connect()
requests = [
"10.0.0.5", "10.0.0.9", "10.0.0.5", "10.0.0.5", "10.0.0.2",
"10.0.0.5", "10.0.0.5", "10.0.0.9", "10.0.0.5", "10.0.0.5",
]
counts = {}
for address in requests:
counts[address] = counts.get(address, 0) + 1
blocked = []
for address, n in sorted(counts.items(), key=lambda kv: kv[1], reverse=True):
if n >= 5:
print(f"{address}: {n} BLOCK")
blocked.append(address)
else:
print(f"{address}: {n}")
print("blocked:", ", ".join(blocked))
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.